Java Code Examples for org.apache.olingo.odata2.api.edm.EdmLiteral#getType()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmLiteral#getType() . 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: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> mapFunctionParameters(final Map<String, EdmLiteral> functionImportParameters)
    throws EdmSimpleTypeException {
  if (functionImportParameters == null) {
    return Collections.emptyMap();
  } else {
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    for (final Entry<String, EdmLiteral> parameter : functionImportParameters.entrySet()) {
      final EdmLiteral literal = parameter.getValue();
      final EdmSimpleType type = literal.getType();
      parameterMap.put(parameter.getKey(), type.valueOfString(literal.getLiteral(), EdmLiteralKind.DEFAULT, null, type
          .getDefaultType()));
    }
    return parameterMap;
  }
}
 
Example 2
Source File: JPAFunctionContext.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private Object convertArgument(final EdmLiteral edmLiteral, final EdmFacets facets, final Class<?> targetType)
    throws EdmSimpleTypeException {
  Object value = null;
  if (edmLiteral != null) {
    EdmSimpleType edmType = edmLiteral.getType();
    value = edmType.valueOfString(edmLiteral.getLiteral(), EdmLiteralKind.DEFAULT, facets, targetType);
  }
  return value;
}
 
Example 3
Source File: PropertyExpressionImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public PropertyExpressionImpl(final String uriLiteral, final EdmLiteral edmLiteral) {
  this.uriLiteral = uriLiteral;

  this.edmLiteral = edmLiteral;
  if (edmLiteral != null) {
    edmType = edmLiteral.getType();
  }
}
 
Example 4
Source File: ListsProcessor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> mapFunctionParameters(final Map<String, EdmLiteral> functionImportParameters)
    throws EdmSimpleTypeException {
  if (functionImportParameters == null) {
    return Collections.emptyMap();
  } else {
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    for (final String parameterName : functionImportParameters.keySet()) {
      final EdmLiteral literal = functionImportParameters.get(parameterName);
      final EdmSimpleType type = literal.getType();
      parameterMap.put(parameterName, type.valueOfString(literal.getLiteral(), EdmLiteralKind.DEFAULT, null, type
          .getDefaultType()));
    }
    return parameterMap;
  }
}
 
Example 5
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 6
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;
}