本文整理汇总了Java中org.apache.olingo.server.api.uri.queryoption.expression.Expression.accept方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.accept方法的具体用法?Java Expression.accept怎么用?Java Expression.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.olingo.server.api.uri.queryoption.expression.Expression
的用法示例。
在下文中一共展示了Expression.accept方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterClause
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入方法依赖的package包/类
private SparqlExpressionVisitor filterClause(FilterOption filter, RdfEntityType entityType, String nextTargetKey)
throws ODataApplicationException, ExpressionVisitException {
SparqlExpressionVisitor sparqlExpressionVisitor = new SparqlExpressionVisitor(rdfModel, rdfModelToMetadata,
entityType, nextTargetKey);
if (filter != null) {
Expression filterExpression = filter.getExpression();
final Object visitorResult;
final String result;
visitorResult = filterExpression.accept(sparqlExpressionVisitor);
result = new String((String) visitorResult);
sparqlExpressionVisitor.setConditionString(result);
}
return sparqlExpressionVisitor;
}
开发者ID:peterjohnlawrence,项目名称:com.inova8.odata2sparql.v4,代码行数:15,代码来源:SparqlFilterClausesBuilder.java
示例2: handleLambdaAny
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入方法依赖的package包/类
private ExpressionResult handleLambdaAny(Expression lambdaExpression)
throws ODataApplicationException, ExpressionVisitException {
setPath(lambdaExpression);
// if any lambda uses primitive property
// Books?$filter=property/any(p:p eq 'value')
// than parent path already contains path and property name
// that's why we need to retrieve only nested path
String nestedPath = isPreLastResourcePrimitive()
? StringUtils.substringBeforeLast(pathToMember, NESTED_PATH_SEPARATOR)
: pathToMember;
ExpressionResult expressionResult = (ExpressionResult) lambdaExpression.accept(visitor);
return isPreLastResourcePrimitive() ? expressionResult
: new NestedMember(nestedPath, expressionResult.getQueryBuilder()).any();
}
示例3: appendExpressionJson
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入方法依赖的package包/类
private void appendExpressionJson(final JsonGenerator gen, final Expression expression) throws IOException {
if (expression == null) {
gen.writeNull();
} else {
try {
final JsonNode tree = expression.accept(new ExpressionJsonVisitor());
gen.writeTree(tree);
} catch (final ODataException e) {
gen.writeString("Exception in Debug Expression visitor occurred: " + e.getMessage());
}
}
}
示例4: applyFilterQueryOption
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入方法依赖的package包/类
private List<Entity> applyFilterQueryOption(List<Entity> entityList, FilterOption filterOption)
throws ODataApplicationException {
if (filterOption != null) {
try {
Iterator<Entity> entityIterator = entityList.iterator();
// Evaluate the expression for each entity
// If the expression is evaluated to "true", keep the entity otherwise remove it from the entityList
while (entityIterator.hasNext()) {
// To evaluate the the expression, create an instance of the Filter Expression Visitor and pass
// the current entity to the constructor
Entity currentEntity = entityIterator.next();
Expression filterExpression = filterOption.getExpression();
FilterExpressionVisitor expressionVisitor = new FilterExpressionVisitor(currentEntity);
// Start evaluating the expression
Object visitorResult = filterExpression.accept(expressionVisitor);
// The result of the filter expression must be of type Edm.Boolean
if (visitorResult instanceof Boolean) {
if (!Boolean.TRUE.equals(visitorResult)) {
// The expression evaluated to false (or null), so we have to remove the currentEntity from entityList
entityIterator.remove();
}
} else {
throw new ODataApplicationException("A filter expression must evaulate to type Edm.Boolean",
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
}
}
} catch (ExpressionVisitException e) {
throw new ODataApplicationException("Exception in filter evaluation",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ENGLISH);
}
}
return entityList;
}
示例5: appendFilter
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入方法依赖的package包/类
private void appendFilter(String alias,Expression filterExpression) throws ExpressionVisitException, ODataApplicationException {
FilterExpressionVisitor expressionVisitor = new FilterExpressionVisitor(alias);
SQLExpression filter = filterExpression.accept(expressionVisitor);
if(getSelect().getWhere() == null ){
getSelect().setWhere(filter);
}else {
BinaryExpression where = new AndExpression().setLeftExpression(new Parenthesis().setExpression(getSelect().getWhere())).
setRightExpression( new Parenthesis().setExpression(filter));
getSelect().setWhere(where);
}
}
示例6: Serialize
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入方法依赖的package包/类
public static String Serialize(final FilterOption filter)
throws ExpressionVisitException, ODataApplicationException {
Expression expression = filter.getExpression();
return expression.accept(new FilterTreeToText());
}
示例7: visitLambdaExpression
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入方法依赖的package包/类
@Override
public String visitLambdaExpression(final String functionText, final String string, final Expression expression)
throws ExpressionVisitException, ODataApplicationException {
return "<" + functionText + ";" + ((expression == null) ? "" : expression.accept(this)) + ">";
}
示例8: readEntityCollection
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入方法依赖的package包/类
public void readEntityCollection(ODataRequest request, ODataResponse response, UriInfo uriInfo,
ContentType responseFormat) throws ODataApplicationException, SerializerException {
// 1st: retrieve the requested EntitySet from the uriInfo (representation of the parsed URI)
List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
// in our example, the first segment is the EntitySet
UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) resourcePaths.get(0);
EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
// 2nd: fetch the data from backend for this requested EntitySetName and deliver as EntitySet
EntityCollection entityCollection = storage.readEntitySetData(edmEntitySet);
// 3rd: Check if filter system query option is provided and apply the expression if necessary
FilterOption filterOption = uriInfo.getFilterOption();
if(filterOption != null) {
// Apply $filter system query option
try {
List<Entity> entityList = entityCollection.getEntities();
Iterator<Entity> entityIterator = entityList.iterator();
// Evaluate the expression for each entity
// If the expression is evaluated to "true", keep the entity otherwise remove it from the entityList
while (entityIterator.hasNext()) {
// To evaluate the the expression, create an instance of the Filter Expression Visitor and pass
// the current entity to the constructor
Entity currentEntity = entityIterator.next();
Expression filterExpression = filterOption.getExpression();
FilterExpressionVisitor expressionVisitor = new FilterExpressionVisitor(currentEntity);
// Start evaluating the expression
Object visitorResult = filterExpression.accept(expressionVisitor);
// The result of the filter expression must be of type Edm.Boolean
if(visitorResult instanceof Boolean) {
if(!Boolean.TRUE.equals(visitorResult)) {
// The expression evaluated to false (or null), so we have to remove the currentEntity from entityList
entityIterator.remove();
}
} else {
throw new ODataApplicationException("A filter expression must evaulate to type Edm.Boolean",
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
}
}
} catch (ExpressionVisitException e) {
throw new ODataApplicationException("Exception in filter evaluation",
HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ENGLISH);
}
}
// 4th: create a serializer based on the requested format (json)
ODataSerializer serializer = odata.createSerializer(responseFormat);
// and serialize the content: transform from the EntitySet object to InputStream
EdmEntityType edmEntityType = edmEntitySet.getEntityType();
ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with()
.contextURL(contextUrl).id(id).build();
SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, entityCollection,
opts);
InputStream serializedContent = serializerResult.getContent();
// 5th: configure the response object: set the body, headers and status code
response.setContent(serializedContent);
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, responseFormat.toContentTypeString());
}