org.apache.olingo.odata2.api.uri.expression.BinaryOperator Java Examples

The following examples show how to use org.apache.olingo.odata2.api.uri.expression.BinaryOperator. 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: JsonVisitor.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public Object visitBinary(final BinaryExpression binaryExpression, final BinaryOperator operator,
    final Object leftSide, final Object rightSide) {
  try {
    StringWriter writer = new StringWriter();
    JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
    jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", binaryExpression.getKind().toString()).separator()
        .namedStringValue("operator", operator.toUriLiteral()).separator().namedStringValueRaw("type",
            getType(binaryExpression)).separator().name("left").unquotedValue(leftSide.toString()).separator().name(
            "right").unquotedValue(rightSide.toString()).endObject();
    writer.flush();
    return writer.toString();
  } catch (final IOException e) {
    return null;
  }
}
 
Example #2
Source File: SQLVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Object visitBinary(BinaryExpression binary_expression,
      BinaryOperator operator, Object left_side, Object right_side)
{
   Criterion criterion;
   switch (operator)
   {
      case EQ:
      case NE:
      case GT:
      case GE:
      case LT:
      case LE:
      {
         criterion = getCriterionComparative(operator, left_side, right_side);
         break;
      }
      case AND:
      case OR:
      {
         Criterion left = (Criterion) left_side;
         Criterion right = (Criterion) right_side;
         criterion = getCriterionLogical(operator, left, right);
         break;
      }
      default:
         // Other operators are not supported for SQL Statements
         throw new UnsupportedOperationException("Unsupported operator: " +
               operator.toUriLiteral());
   }
   // return the binary statement
   return criterion;
}
 
Example #3
Source File: SQLVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
private Criterion getCriterionLogical(BinaryOperator operator,
      Criterion left, Criterion right)
{
   Criterion criterion;
   if (left == null && right == null)
   {
      criterion = null;
   }
   else if (left != null && right != null)
   {
      switch (operator)
      {
         case AND:
         {
            criterion = Restrictions.and(left, right);
            break;
         }
         case OR:
         {
            criterion = Restrictions.or(left, right);
            break;
         }
         default:
         {
            throw new UnsupportedOperationException(
                  "Unsupported operator: " + operator.toUriLiteral());
         }
      }
   }
   else if (left == null)
   {
      criterion = right;
   }
   else
   {
      criterion = left;
   }
   return criterion;
}
 
Example #4
Source File: FunctionalVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Object visitBinary(BinaryExpression be, BinaryOperator op, Object left, Object right)
{
   // `left` and `right` are instances of Node<?> (Expression Tree)
   // Returns a BiTransformer (functional Java) as a Node<?> (Expression Tree)
   Transformer res;
   switch(op)
   {
      case  EQ: res = Transformers.<Object>eq(); break;
      case  NE: res = Transformers.<Object>ne(); break;

      case AND: res = Transformers.and(); break;
      case  OR: res = Transformers.or();  break;

      case GE: res = Transformers.ge(); break;
      case GT: res = Transformers.gt(); break;
      case LE: res = Transformers.le(); break;
      case LT: res = Transformers.lt(); break;

      case    ADD: res = Transformers.add(); break;
      case    SUB: res = Transformers.sub(); break;
      case    MUL: res = Transformers.mul(); break;
      case    DIV: res = Transformers.div(); break;
      case MODULO: res = Transformers.mod(); break;

      default:
         throw new UnsupportedOperationException("Unsupported operator: " + op.toUriLiteral());
   }

   ExecutableExpressionTree.Node nleft  = ExecutableExpressionTree.Node.class.cast(left);
   ExecutableExpressionTree.Node nright = ExecutableExpressionTree.Node.class.cast(right);
   return ExecutableExpressionTree.Node.createNode(res, nleft, nright);
}
 
Example #5
Source File: InfoBinaryOperator.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public InfoBinaryOperator(final BinaryOperator operator, final String category, final int priority,
    final ParameterSetCombination combination) {
  this.operator = operator;
  this.category = category;
  syntax = operator.toUriLiteral();
  this.priority = priority;
  this.combination = combination;
}
 
Example #6
Source File: SQLVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
private Criterion internalCriterionComparative(
      BinaryOperator operator, String property, Object value)
{
   Criterion criterion;
   switch (operator)
   {
      case EQ:
      {
         criterion = Restrictions.eq(property, value);
         break;
      }
      case NE:
      {
         criterion = Restrictions.ne(property, value);
         break;
      }
      case GT:
      {
         criterion = Restrictions.gt(property, value);
         break;
      }
      case GE:
      {
         criterion = Restrictions.ge(property, value);
         break;
      }
      case LT:
      {
         criterion = Restrictions.lt(property, value);
         break;
      }
      case LE:
      {
         criterion = Restrictions.le(property, value);
         break;
      }
      default:
         throw new UnsupportedOperationException(
               "Unsupported operation: " + operator.toUriLiteral());
   }
   return criterion;
}
 
Example #7
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private UriInfo mockURIInfoWithKeyNavSegAndFilter(EdmMapping mapping) throws EdmException {
  UriInfo uriInfo = EasyMock.createMock(UriInfo.class);
  
  EdmEntityType startEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(startEntityType.getMapping()).andStubReturn(mapping);
  
  EdmEntitySet startEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EasyMock.expect(startEntitySet.getEntityType()).andStubReturn(startEntityType);
  EasyMock.expect(uriInfo.getStartEntitySet()).andStubReturn(startEntitySet);
  
  EdmEntityType targetEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(targetEntityType.getMapping()).andStubReturn((EdmMapping) mockNavEdmMappingForProperty());
  
  EdmEntitySet targetEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EasyMock.expect(targetEntitySet.getEntityType()).andStubReturn(targetEntityType);
  EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(targetEntitySet);
  
  List<KeyPredicate> keyPreds = new ArrayList<KeyPredicate>();
  EdmProperty edmProperty = mockEdmProperty((EdmMapping) mockMappingWithType("uuid"), "uuid");
  keyPreds.add(mockKeyPredicate(edmProperty, "56fe79b1-1c88-465b-b309-33bf8b8f6800"));
  EasyMock.expect(uriInfo.getKeyPredicates()).andStubReturn(keyPreds); 
  
  List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
  EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments);
  NavigationSegment navSegment = EasyMock.createMock(NavigationSegment.class);
  EasyMock.expect(navSegment.getEntitySet()).andStubReturn(targetEntitySet);
  List<KeyPredicate> navKeyPreds = new ArrayList<KeyPredicate>();
  EasyMock.expect(navSegment.getKeyPredicates()).andStubReturn(navKeyPreds);
  EdmNavigationProperty navEdmProperty = EasyMock.createMock(EdmNavigationProperty.class);
  EasyMock.expect(navSegment.getNavigationProperty()).andStubReturn(navEdmProperty);
  EasyMock.expect(navEdmProperty.getMapping()).andStubReturn((EdmMapping)mockNavEdmMappingForProperty());
  EasyMock.expect(navEdmProperty.getFromRole()).andStubReturn("Customers");
  EasyMock.expect(navEdmProperty.getToRole()).andStubReturn("SalesOrderHeader");
  EdmAssociation association = EasyMock.createMock(EdmAssociation.class);
  EasyMock.expect(navEdmProperty.getRelationship()).andStubReturn(association);
  EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
  EasyMock.expect(associationEnd.getEntityType()).andStubReturn(startEntityType);
  EasyMock.expect(association.getEnd("Customers")).andStubReturn(associationEnd);
  navSegments.add(navSegment);
  
  FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
  PropertyExpression propExp = EasyMock.createMock(PropertyExpression.class);
  LiteralExpression literalExp = EasyMock.createMock(LiteralExpression.class);
  EasyMock.expect(uriInfo.getFilter()).andStubReturn(filterExpression);
  BinaryExpression commonExpression = EasyMock.createMock(BinaryExpression.class);
  EasyMock.expect(commonExpression.getOperator()).andStubReturn(BinaryOperator.EQ);
  EasyMock.expect(commonExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
  EasyMock.expect(filterExpression.getExpression()).andStubReturn(commonExpression);
  EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER); 
  EasyMock.expect(filterExpression.getExpressionString()).andStubReturn(
      "Customer eq '56fe79b1-1c88-465b-b309-32bf8b8f7800'"); 
  
  EasyMock.expect(commonExpression.getLeftOperand()).andStubReturn(propExp);
  EasyMock.expect(propExp.getEdmProperty()).andStubReturn(mockEdmProperty(
      (EdmMapping) mockMappingWithType("uuid"), "uuid"));
  EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
  EasyMock.expect(propExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance());
  
  EasyMock.expect(commonExpression.getRightOperand()).andStubReturn(literalExp);
  EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("guid'56fe79b1-1c88-465b-b309-32bf8b8f7800'");
  EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
  EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance());
  
  EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(null);
  EasyMock.expect(uriInfo.getTop()).andStubReturn(null);
  EasyMock.expect(uriInfo.getSkip()).andStubReturn(null);
  
  EasyMock.replay(startEntityType, targetEntityType, startEntitySet, targetEntitySet, uriInfo,
      filterExpression, propExp, literalExp, navSegment, navEdmProperty, 
      commonExpression, association, associationEnd);
  return uriInfo;

}
 
Example #8
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private UriInfo mockURIInfoForEntitySetWithBinaryFilterExpression
(EdmMapping mapping, String methodName) throws EdmException {
  
  UriInfo uriInfo = EasyMock.createMock(UriInfo.class);
  List<NavigationSegment> navSegments = new ArrayList<NavigationSegment>();
  EasyMock.expect(uriInfo.getNavigationSegments()).andStubReturn(navSegments);
  EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
  EasyMock.expect(edmEntityType.getMapping()).andStubReturn(mapping);
  EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
  EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
  EasyMock.expect(uriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
  EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
  EasyMock.expect(edmProperty.getMapping()).andStubReturn((EdmMapping)mockEdmMappingForProperty());
  OrderByExpression orderbyExpression = EasyMock.createMock(OrderByExpression.class);
  List<OrderExpression> orders = new ArrayList<OrderExpression>();
  EasyMock.expect(orderbyExpression.getOrders()).andStubReturn(orders);
  EasyMock.expect(uriInfo.getOrderBy()).andStubReturn(orderbyExpression);
  FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
  BinaryExpression commonExpression = EasyMock.createMock(BinaryExpression.class);
  EasyMock.expect(commonExpression.getOperator()).andStubReturn(BinaryOperator.EQ);
  EasyMock.expect(commonExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
  MethodExpression methodExp = EasyMock.createMock(MethodExpression.class);
  EasyMock.expect(commonExpression.getLeftOperand()).andStubReturn(methodExp);
  EdmSimpleType type = EasyMock.createMock(EdmSimpleType.class);;
  EasyMock.expect(methodExp.getEdmType()).andStubReturn(type );
  
  LiteralExpression literalValueExp = EasyMock.createMock(LiteralExpression.class);
  EasyMock.expect(commonExpression.getRightOperand()).andStubReturn(literalValueExp);
  EasyMock.expect(literalValueExp.getUriLiteral()).andStubReturn("'a%.b*.c'");
  EasyMock.expect(literalValueExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
  EasyMock.expect(literalValueExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
  
  PropertyExpression propExp = EasyMock.createMock(PropertyExpression.class);
  LiteralExpression literalExp1 = EasyMock.createMock(LiteralExpression.class);
  LiteralExpression literalExp2 = EasyMock.createMock(LiteralExpression.class);
  List<CommonExpression> parameterList = new ArrayList<CommonExpression>();
  if ("substring".equals(methodName)) {
    EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.SUBSTRING);
    EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD);
    EasyMock.expect(methodExp.getParameterCount()).andStubReturn(3);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(literalExp1.getUriLiteral()).andStubReturn("1");
    EasyMock.expect(literalExp1.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp1.getEdmType()).andStubReturn(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance());
    parameterList.add(literalExp1);
    EasyMock.expect(literalExp2.getUriLiteral()).andStubReturn("2");
    EasyMock.expect(literalExp2.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp2.getEdmType()).andStubReturn(EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance());
    parameterList.add(literalExp2);
    EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList);
  } else if ("toLower".equals(methodName)) {
    EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.TOLOWER);
    EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD);
    EasyMock.expect(methodExp.getParameterCount()).andStubReturn(1);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList);
  } else if ("toUpper".equals(methodName)) {
    EasyMock.expect(methodExp.getMethod()).andStubReturn(MethodOperator.TOUPPER);
    EasyMock.expect(methodExp.getKind()).andStubReturn(ExpressionKind.METHOD);
    EasyMock.expect(methodExp.getParameterCount()).andStubReturn(1);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(methodExp.getParameters()).andStubReturn(parameterList);
  }
  EasyMock.expect(filterExpression.getExpression()).andStubReturn(commonExpression);
  EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
  EasyMock.expect(filterExpression.getExpressionString()).andStubReturn("substring(CompanyName,1,2) eq 'a.b.c'");
  EasyMock.expect(uriInfo.getFilter()).andStubReturn(filterExpression);
  EasyMock.replay(edmEntityType, edmEntitySet, orderbyExpression, filterExpression, 
      commonExpression, literalExp1, literalExp2, propExp, uriInfo, edmProperty, 
      methodExp, literalValueExp);
  return uriInfo;

}
 
Example #9
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 #10
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 #11
Source File: InfoBinaryOperator.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public BinaryOperator getOperator() {
  return operator;
}
 
Example #12
Source File: BinaryExpressionImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public BinaryOperator getOperator() {
  return operatorInfo.getOperator();
}
 
Example #13
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;
}
 
Example #14
Source File: MemberExpressionImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public String getUriLiteral() {
  return BinaryOperator.PROPERTY_ACCESS.toUriLiteral();
}
 
Example #15
Source File: VisitorTool.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitBinary(final BinaryExpression binaryExpression, final BinaryOperator operator,
    final Object leftSide, final Object rightSide) {
  return "{" + leftSide.toString() + " " + operator.toUriLiteral() + " " + rightSide.toString() + "}";
}
 
Example #16
Source File: ODataParser.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Object visitBinary(BinaryExpression binaryExpression, BinaryOperator operator,
        Object leftSide, Object rightSide) {

    // AND / OR operate on search conditions
    if (operator == BinaryOperator.AND || operator == BinaryOperator.OR) {
        if (leftSide instanceof SearchCondition && rightSide instanceof SearchCondition) {
            final List< SearchCondition< T > > conditions = new ArrayList<>(2);
            conditions.add((SearchCondition< T >)leftSide);
            conditions.add((SearchCondition< T >)rightSide);

            if (operator == BinaryOperator.AND) {
                return new AndSearchCondition< T >(conditions);
            } else if (operator == BinaryOperator.OR) {
                return new OrSearchCondition< T >(conditions);
            }
        } else {
            throw new SearchParseException(
                "Unsupported binary operation arguments (SearchCondition expected): "
                    + leftSide + ", " + rightSide);
        }
    }

    // Property could be either on left side (Name eq 'Tom') or
    // right side ('Tom' eq Name)
    TypedValue value = null;
    TypedProperty property = null;

    if (leftSide instanceof TypedProperty && rightSide instanceof TypedValue) {
        property = (TypedProperty)leftSide;
        value = (TypedValue)rightSide;
    } else if (rightSide instanceof TypedProperty && leftSide instanceof TypedValue) {
        property = (TypedProperty)rightSide;
        value = (TypedValue)leftSide;
    } else {
        throw new SearchParseException(
            "Unsupported binary operation arguments (TypedValue or TypedProperty expected): "
                + leftSide + ", " + rightSide);
    }

    ConditionType conditionType = null;
    switch (operator) {
    case EQ:
        conditionType = ConditionType.EQUALS;
        break;
    case NE:
        conditionType = ConditionType.NOT_EQUALS;
        break;
    case LT:
        conditionType = ConditionType.LESS_THAN;
        break;
    case LE:
        conditionType = ConditionType.LESS_OR_EQUALS;
        break;
    case GT:
        conditionType = ConditionType.GREATER_THAN;
        break;
    case GE:
        conditionType = ConditionType.GREATER_OR_EQUALS;
        break;
    default:
        throw new SearchParseException("Unsupported binary operation: " + operator);
    }

    Object typedValue = null;
    // If property type and value type are compatible, just use them
    if (property.typeInfo.getWrappedTypeClass().isAssignableFrom(value.typeClass)) {
        typedValue = value.value;
    } else { // Property type and value type are not compatible and convert / cast are required
        String valueStr = value.literal;
        if (isDecodeQueryValues()) {
            valueStr = UrlUtils.urlDecode(valueStr);
        }
        typedValue = parseType(property.propertyName, null, null, property.propertyName,
            property.typeInfo, valueStr);
    }

    final CollectionCheckInfo checkInfo = property.typeInfo.getCollectionCheckInfo();
    if (checkInfo != null) {
        return new CollectionCheckCondition< T >(property.propertyName, typedValue,
            property.typeInfo.getGenericType(), conditionType, condition, checkInfo);
    }

    return new PrimitiveSearchCondition< T >(property.propertyName, typedValue,
        property.typeInfo.getGenericType(), conditionType, condition);
}