当前位置: 首页>>代码示例>>Java>>正文


Java Expression.accept方法代码示例

本文整理汇总了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();
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:16,代码来源:MemberHandler.java

示例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());
    }
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:13,代码来源:DebugTabUri.java

示例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;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:40,代码来源:DemoEntityCollectionProcessor.java

示例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);
		}

	}
 
开发者ID:jbaliuka,项目名称:sql-analytic,代码行数:15,代码来源:ReadCommand.java

示例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());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:7,代码来源:FilterTreeToText.java

示例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)) + ">";
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:7,代码来源:FilterTreeToText.java

示例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());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:71,代码来源:DemoEntityCollectionProcessor.java


注:本文中的org.apache.olingo.server.api.uri.queryoption.expression.Expression.accept方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。