2013-06-28 7 views
0

누구나 서비스 클래스에 대해 where 절의 샘플 OSLC 코드를 제공 할 수 있습니까? 방금 ​​OSLC를 사용하기 시작했습니다."where"절이있는 샘플 OSLC 코드

@GET 
@Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON}) 
public Project[] getChangeRequests(@QueryParam("oslc.where") final String where, 
        @QueryParam("oslc.prefix") final String prefix) 
{  
    final List< Project> results = new ArrayList<Project>();   
    Map<String, String> prefixMap; 
    try 
    {  
     QueryUtils.parseSearchTerms(where); 
     prefixMap = QueryUtils.parsePrefixes(prefix); 
     WhereClause whereClause = QueryUtils.parseWhere(where, prefixMap); 

    } 
    catch (ParseException e) 
    { 
     e.printStackTrace(); 
    } 

    final Project[] changeRequests = Persistence.getChangeRequestsForProject(); 
    for (final Project changeRequest : changeRequests) 
    { 
     changeRequest.setServiceProvider(ServiceProviderSingleton.getServiceProviderURI()); 
     results.add(changeRequest); 
    } 
    return results.toArray(new Project[results.size()]); 
} 
+0

누군가가 downvoting 동안 질문에 대한 개선에 의견을주십시오 수 있습니까? – eeerahul

답변

2

난 그냥 코드의 작업 조각을 게시 할 예정입니다 생각 : 여기


내가 시도 코드 (does't 일)입니다. 여기에 그것입니다 :

prefixMap = QueryUtils.parsePrefixes(prefix); 
WhereClause whereClause = QueryUtils.parseWhere(where, prefixMap); 

PName property = null; 
String value =""; 
for (SimpleTerm term : whereClause.children()) 
{ 
    ComparisonTerm comparison = (ComparisonTerm)term; 
    String operator; 

    switch (comparison.operator()) 
    { 
     case EQUALS: 
      operator = "equals"; 
      break; 
     case NOT_EQUALS: 
      operator = "notequals"; 
      break; 
     case LESS_THAN: 
      operator = "lessthan"; 
      break; 
     case LESS_EQUALS: 
      operator = "lessthaneq"; 
      break; 
     case GREATER_THAN: 
      operator = "greaterthan"; 
      break; 
     default: 
     case GREATER_EQUALS: 
      operator = "greaterhaneq"; 
      break; 
    }   
    property = comparison.property();  
    Value operand = comparison.operand(); 
    value = operand.toString(); 
    switch (operand.type()) 
    { 
     case STRING: 
     case URI_REF: 
      value = value.substring(1, value.length() - 1); 
      break; 
     case BOOLEAN: 
     case DECIMAL: 
      break; 
     default: 
     throw new WebApplicationException 
     (new UnsupportedOperationException("Unsupported oslc.where comparison operand: " + value),Status.BAD_REQUEST);     
    } 
} 
String compareString=property.toString().substring(property.toString().indexOf(":")+1); 
String val="get" + compareString.substring(0,1).toUpperCase() +compareString.substring(1); 
final Project[] changeRequests = Persistence.getChangeRequestsForProject(); 
for (final Project changeRequest : changeRequests) 
{ 
    changeRequest.setServiceProvider(ServiceProviderSingleton.getServiceProviderURI()); 
    Method m=changeRequest.getClass().getMethod(val, null); 
    if((m.invoke(changeRequest).toString().equalsIgnoreCase(value))) 
    { 
     results.add(changeRequest); 
    } 
}