Java Code Examples for org.apache.olingo.odata2.api.uri.expression.BinaryOperator#PROPERTY_ACCESS

The following examples show how to use org.apache.olingo.odata2.api.uri.expression.BinaryOperator#PROPERTY_ACCESS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilterParserImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected CommonExpression readElements(final CommonExpression leftExpression, final int priority)
    throws ExpressionParserException, ExpressionParserInternalError {
  CommonExpression leftNode = leftExpression;
  CommonExpression rightNode;
  BinaryExpression binaryNode;

  ActualBinaryOperator operator = readBinaryOperator();
  ActualBinaryOperator nextOperator;

  while ((operator != null) && (operator.getOP().getPriority() >= priority)) {
    tokenList.next(); // eat the operator
    rightNode = readElement(leftNode, operator); // throws FilterParserException, FilterParserInternalError
    if (rightNode == null) {
      // Tested with TestParserExceptions.testAdditionalStuff CASE 10
      throw FilterParserExceptionImpl.createEXPRESSION_EXPECTED_AFTER_POS(operator.getToken().getPosition()
          + operator.getToken().getUriLiteral().length(), curExpression);
    }
    nextOperator = readBinaryOperator();

    // It must be "while" because for example in "Filter=a or c eq d and e eq f"
    // after reading the "eq" operator the "and" operator must be consumed too. This is due to the fact that "and" has
    // a higher priority than "or"
    while ((nextOperator != null) && (nextOperator.getOP().getPriority() > operator.getOP().getPriority())) {
      // recurse until the a binary operator with a lower priority is detected
      rightNode = readElements(rightNode, nextOperator.getOP().getPriority());
      nextOperator = readBinaryOperator();
    }

    // Although the member operator is also a binary operator, there is some special handling in the filterTree
    if (operator.getOP().getOperator() == BinaryOperator.PROPERTY_ACCESS) {
      binaryNode = new MemberExpressionImpl(leftNode, rightNode);
    } else {
      binaryNode = new BinaryExpressionImpl(operator.getOP(), leftNode, rightNode, operator.getToken());
    }

    try {
      validateBinaryOperatorTypes(binaryNode);
    } catch (ExpressionParserException expressionException) {
      // Extend the error information
      // Tested for original throw point
      expressionException.setFilterTree(binaryNode);
      throw expressionException;
    }

    leftNode = binaryNode;
    operator = readBinaryOperator();
  }

  // Add special handling for expressions like $filter=notsupportedfunction('a')
  // If this special handling is not in place the error text would be
  // -->Invalid token "(" detected after parsing at position 21 in "notsupportedfunction('a')".
  // with this special handling we ensure that the error text would be

  Token token = tokenList.lookToken();
  if (token != null) {
    if ((leftNode.getKind() == ExpressionKind.PROPERTY) && (tokenList.lookToken().getKind() == TokenKind.OPENPAREN)) {
      // Tested with TestParserExceptions.testAdditionalStuff CASE 2
      throw FilterParserExceptionImpl.createINVALID_METHOD_CALL(leftNode, tokenList.lookPrevToken(), curExpression);
    }
  }

  return leftNode;
}
 
Example 2
Source File: FilterParserImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected void validateEdmProperty(final CommonExpression leftExpression, final PropertyExpressionImpl property,
    final Token propertyToken, final ActualBinaryOperator actBinOp) throws ExpressionParserException,
    ExpressionParserInternalError {

  // Exit if no edm provided
  if (resourceEntityType == null) {
    return;
  }

  if (leftExpression == null) {
    // e.g. "$filter=city eq 'Hong Kong'" --> "city" is checked against the resource entity type of the last URL
    // segment
    validateEdmPropertyOfStructuredType(resourceEntityType, property, propertyToken);
    return;
  }
  // e.g. "$filter='Hong Kong' eq address/city" --> city is "checked" against the type of the property "address".
  // "address" itself must be a (navigation)property of the resource entity type of the last URL segment AND
  // "address" must have a structural edm type
  EdmType parentType = leftExpression.getEdmType(); // parentType point now to the type of property "address"

  if ((actBinOp != null) && (actBinOp.operator.getOperator() != BinaryOperator.PROPERTY_ACCESS)) {
    validateEdmPropertyOfStructuredType(resourceEntityType, property, propertyToken);
    return;
  } else {
    if ((leftExpression.getKind() != ExpressionKind.PROPERTY) &&
        (leftExpression.getKind() != ExpressionKind.MEMBER)) {
      if (actBinOp != null) {
        // Tested with TestParserExceptions.TestPMvalidateEdmProperty CASE 6
        throw FilterParserExceptionImpl.createLEFT_SIDE_NOT_A_PROPERTY(actBinOp.token, curExpression);
      } else {
        // not Tested, should not occur
        throw ExpressionParserInternalError.createCOMMON();
      }

    }
  }

  if (parentType instanceof EdmEntityType) {
    // e.g. "$filter='Hong Kong' eq navigationProp/city" --> "navigationProp" is a navigation property with a entity
    // type
    validateEdmPropertyOfStructuredType((EdmStructuralType) parentType, property, propertyToken);
  } else if (parentType instanceof EdmComplexType) {
    // e.g. "$filter='Hong Kong' eq address/city" --> "address" is a property with a complex type
    validateEdmPropertyOfStructuredType((EdmStructuralType) parentType, property, propertyToken);
  } else {
    // e.g. "$filter='Hong Kong' eq name/city" --> "name is of type String"
    // Tested with TestParserExceptions.TestPMvalidateEdmProperty CASE 5
    throw FilterParserExceptionImpl.createLEFT_SIDE_NOT_STRUCTURAL_TYPE(parentType, property, propertyToken,
        curExpression);
  }

  return;
}
 
Example 3
Source File: MemberExpressionImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public BinaryOperator getOperator() {
  return BinaryOperator.PROPERTY_ACCESS;
}