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

The following examples show how to use org.apache.olingo.odata2.api.uri.expression.LiteralExpression. 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: FunctionalVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Object visitLiteral(LiteralExpression literal, EdmLiteral edm_literal)
{
   try
   {
      // A literal is a Provider<?> (Functional Java)
      // Returns a Node<?> (Expression Tree)
      Object o = edm_literal.getType().valueOfString(
            edm_literal.getLiteral(),
            EdmLiteralKind.DEFAULT,
            null,
            edm_literal.getType().getDefaultType());
      return ExecutableExpressionTree.Node.createLeave(ConstantFactory.constantFactory(o));
   }
   catch (EdmException ex)
   {
      throw new RuntimeException(ex);
   }
}
 
Example #2
Source File: JsonVisitor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitLiteral(final LiteralExpression literal, final EdmLiteral edmLiteral) {
  try {
    StringWriter writer = new StringWriter();
    JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
    jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", literal.getKind().toString()).separator()
        .namedStringValueRaw("type", getType(literal)).separator().namedStringValue("value", edmLiteral.getLiteral())
        .endObject();
    writer.flush();
    return writer.toString();
  } catch (final IOException e) {
    return null;
  }
}
 
Example #3
Source File: ODataParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitLiteral(LiteralExpression literal, EdmLiteral edmLiteral) {
    try {
        final EdmSimpleType type = edmLiteral.getType();

        final Object value = type.valueOfString(edmLiteral.getLiteral(),
            EdmLiteralKind.DEFAULT, null, type.getDefaultType());

        return new TypedValue(type.getDefaultType(), edmLiteral.getLiteral(), value);
    } catch (EdmSimpleTypeException ex) {
        throw new SearchParseException("Failed to convert literal to a typed form: " + literal, ex);
    }
}
 
Example #4
Source File: SQLVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Object visitLiteral(LiteralExpression literal, EdmLiteral edm_literal)
{
   Object result;
   Class type = edm_literal.getType().getDefaultType();

   if (type.equals(Boolean.class))
   {
      result = Boolean.valueOf(edm_literal.getLiteral());
   }
   else if (type.equals(Byte.class)    || type.equals(Short.class) ||
            type.equals(Integer.class) || type.equals(Long.class))
   {
      result = Long.valueOf(edm_literal.getLiteral());
   }
   else if (type.equals(Double.class) || type.equals(BigDecimal.class))
   {
      result = Double.valueOf(edm_literal.getLiteral());
   }
   else if (type.equals(String.class))
   {
      result = edm_literal.getLiteral();
   }
   else if (type.equals(Calendar.class))
   {
      SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
      SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
      try
      {
         result = sdf1.parse(edm_literal.getLiteral());
      }
      catch (ParseException e)
      {
         try
         {
            result = sdf2.parse(edm_literal.getLiteral());
         }
         catch (ParseException e1)
         {
            throw new IllegalArgumentException("Invalid date format");
         }
      }
   }
   else
   {
      throw new IllegalArgumentException("Type " + edm_literal.getType() +
            " is not supported by the service");
   }

   return result;
}
 
Example #5
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 #6
Source File: JPAQueryBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private UriInfo mockURIInfoForEntitySet(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());
  
  EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class);
  EasyMock.expect(edmProperty1.getMapping()).andStubReturn((EdmMapping)mockEdmMappingForProperty1());
  
  EdmNavigationProperty navEdmProperty = EasyMock.createMock(EdmNavigationProperty.class);
  EasyMock.expect(navEdmProperty.getMapping()).andStubReturn((EdmMapping)mockNavEdmMappingForProperty());
  
  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);
  MethodExpression commonExpression = EasyMock.createMock(MethodExpression.class);
  EasyMock.expect(commonExpression.getKind()).andStubReturn(ExpressionKind.METHOD);
  PropertyExpression propExp = EasyMock.createMock(PropertyExpression.class);
  LiteralExpression literalExp = EasyMock.createMock(LiteralExpression.class);
  MemberExpression memberExp = EasyMock.createMock(MemberExpression.class);
  List<CommonExpression> parameterList = new ArrayList<CommonExpression>();
  
  PropertyExpression navPropExp = EasyMock.createMock(PropertyExpression.class);
  if ("substringof".equals(methodName)) {
    EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.SUBSTRINGOF);
    EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2);
    EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'");
    EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
    parameterList.add(literalExp);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
  } else if ("startsWith".equals(methodName)) {
    EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.STARTSWITH);
    EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'");
    EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
    parameterList.add(literalExp);
  } else if ("endsWith".equals(methodName)) {
    EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.ENDSWITH);
    EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    parameterList.add(propExp);
    EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'");
    EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
    parameterList.add(literalExp);
  } else if ("substringof_1".equals(methodName)) {
    EasyMock.expect(commonExpression.getMethod()).andStubReturn(MethodOperator.SUBSTRINGOF);
    EasyMock.expect(commonExpression.getParameterCount()).andStubReturn(2);
    EasyMock.expect(literalExp.getUriLiteral()).andStubReturn("'a.b.c'");
    EasyMock.expect(literalExp.getKind()).andStubReturn(ExpressionKind.LITERAL);
    EasyMock.expect(literalExp.getEdmType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
    parameterList.add(literalExp);
    EasyMock.expect(memberExp.getKind()).andStubReturn(ExpressionKind.MEMBER);
    EasyMock.expect(memberExp.getProperty()).andStubReturn(propExp);
    
    EasyMock.expect(memberExp.getPath()).andStubReturn(navPropExp);
    EasyMock.expect(navPropExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    EasyMock.expect(navPropExp.getEdmProperty()).andStubReturn(navEdmProperty);
    EasyMock.expect(propExp.getKind()).andStubReturn(ExpressionKind.PROPERTY);
    EasyMock.expect(propExp.getEdmProperty()).andStubReturn(edmProperty1);
    
    parameterList.add(propExp);
  }
  
  EasyMock.expect(commonExpression.getParameters()).andStubReturn(parameterList);
  
  EasyMock.expect(filterExpression.getExpression()).andStubReturn(commonExpression);
  EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
  EasyMock.expect(filterExpression.getExpressionString()).andStubReturn("substringof('a.b.c',Id)");
  EasyMock.expect(uriInfo.getFilter()).andStubReturn(filterExpression);
  EasyMock.replay(edmEntityType, edmEntitySet, orderbyExpression, filterExpression, 
      commonExpression, literalExp, propExp, uriInfo, edmProperty, memberExp,
      edmProperty1, navEdmProperty);
  return uriInfo;

}
 
Example #7
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 #8
Source File: FilterParserImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
/**
 * Reads: Unary operators, Methods, Properties, ...
 * but not binary operators which are handelt in {@link #readElements(CommonExpression, int)}
 * @param leftExpression
 * Used while parsing properties. In this case ( e.g. parsing "a/b") the property "a" ( as leftExpression of "/") is
 * relevant
 * to verify whether the property "b" exists inside the edm
 * @return a CommonExpression
 * @throws ExpressionParserException
 * @throws ExpressionParserInternalError
 * @throws TokenizerMessage
 */
protected CommonExpression
    readElement(final CommonExpression leftExpression, final ActualBinaryOperator leftOperator)
        throws ExpressionParserException, ExpressionParserInternalError {
  CommonExpression node = null;
  Token token;
  Token lookToken;
  lookToken = tokenList.lookToken();
  if (lookToken == null) {
    return null;
  }

  switch (lookToken.getKind()) {
  case OPENPAREN:
    node = readParenthesis();
    return node;
  case CLOSEPAREN: // ')' finishes a parenthesis (it is no extra token)" +
  case COMMA: // . " ','  is a separator for function parameters (it is no extra token)" +
    return null;
  default:
    // continue
  }

  // -->Check if the token is a unary operator
  InfoUnaryOperator unaryOperator = isUnaryOperator(lookToken);
  if (unaryOperator != null) {
    return readUnaryoperator(lookToken, unaryOperator);
  }

  // ---expect the look ahead token
  token = tokenList.expectToken(lookToken.getUriLiteral(), true);
  lookToken = tokenList.lookToken();

  // -->Check if the token is a method
  // To avoid name clashes between method names and property names we accept here only method names if a "(" follows.
  // Hence the parser accepts a property named "concat"
  InfoMethod methodOperator = isMethod(token, lookToken);
  if (methodOperator != null) {
    return readMethod(token, methodOperator);
  }

  // -->Check if token is a terminal
  // is a terminal e.g. a Value like an EDM.String 'hugo' or 125L or 1.25D"
  if (token.getKind() == TokenKind.SIMPLE_TYPE) {
    LiteralExpression literal = new LiteralExpressionImpl(token.getUriLiteral(), token.getJavaLiteral());
    return literal;
  }

  // -->Check if token is a property, e.g. "name" or "address"
  if (token.getKind() == TokenKind.LITERAL) {
    PropertyExpressionImpl property = new PropertyExpressionImpl(token.getUriLiteral(), token.getJavaLiteral());
    validateEdmProperty(leftExpression, property, token, leftOperator);
    return property;
  }

  // not Tested, should not occur
  throw ExpressionParserInternalError.createCOMMON();
}
 
Example #9
Source File: VisitorTool.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitLiteral(final LiteralExpression literal, final EdmLiteral edmLiteral) {
  return "" + literal.getUriLiteral() + "";
}