Package org.apache.olingo.odata2.api.edm

Examples of org.apache.olingo.odata2.api.edm.EdmLiteral


    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;
    }
  }
View Full Code Here


    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;
    }
  }
View Full Code Here

public class EdmSimpleTypeFacadeImpl implements EdmSimpleTypeFacade {

  @Override
  public EdmLiteral parseUriLiteral(final String uriLiteral) throws EdmLiteralException {
    if (uriLiteral == null || "null".equals(uriLiteral)) {
      return new EdmLiteral(getEdmSimpleType(EdmSimpleTypeKind.Null), uriLiteral);
    }

    if ("true".equals(uriLiteral) || "false".equals(uriLiteral)) {
      return new EdmLiteral(getEdmSimpleType(EdmSimpleTypeKind.Boolean), uriLiteral);
    }

    if (uriLiteral.length() >= 2
        && uriLiteral.startsWith("'") && uriLiteral.endsWith("'")) {
      try {
        final EdmSimpleType type = getEdmSimpleType(EdmSimpleTypeKind.String);
        return new EdmLiteral(type, type.valueOfString(uriLiteral, EdmLiteralKind.URI, null, String.class));
      } catch (EdmSimpleTypeException e) {
        throw new EdmLiteralException(EdmLiteralException.LITERALFORMAT.addContent(uriLiteral), e);
      }
    }

    if (uriLiteral.matches("-?\\p{Digit}+")) {
      try {
        final int i =
            getEdmSimpleType(EdmSimpleTypeKind.Int32)
                .valueOfString(uriLiteral, EdmLiteralKind.URI, null, Integer.class);
        if (i == 0 || i == 1) {
          return new EdmLiteral(getInternalEdmSimpleTypeByString("Bit"), uriLiteral);
        }
        if (i >= 0 && i <= Byte.MAX_VALUE) {
          return new EdmLiteral(getInternalEdmSimpleTypeByString("Uint7"), uriLiteral);
        }
        if (i >= Byte.MIN_VALUE && i < 0) {
          return new EdmLiteral(getEdmSimpleType(EdmSimpleTypeKind.SByte), uriLiteral);
        } else if (i > Byte.MAX_VALUE && i <= 255) {
          return new EdmLiteral(getEdmSimpleType(EdmSimpleTypeKind.Byte), uriLiteral);
        } else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) {
          return new EdmLiteral(getEdmSimpleType(EdmSimpleTypeKind.Int16), uriLiteral);
        } else {
          return new EdmLiteral(getEdmSimpleType(EdmSimpleTypeKind.Int32), uriLiteral);
        }
      } catch (EdmSimpleTypeException e) {
        throw new EdmLiteralException(EdmLiteralException.LITERALFORMAT.addContent(uriLiteral), e);
      }
    }

    if (uriLiteral.endsWith("L") || uriLiteral.endsWith("l")) {
      return createEdmLiteral(EdmSimpleTypeKind.Int64, uriLiteral, 0, 1);
    }
    if (uriLiteral.endsWith("M") || uriLiteral.endsWith("m")) {
      return createEdmLiteral(EdmSimpleTypeKind.Decimal, uriLiteral, 0, 1);
    }
    if (uriLiteral.endsWith("D") || uriLiteral.endsWith("d")) {
      return createEdmLiteral(EdmSimpleTypeKind.Double, uriLiteral, 0, 1);
    }
    if (uriLiteral.equals("-INF") || uriLiteral.equals("INF") || uriLiteral.equals("NaN")) {
      return new EdmLiteral(getEdmSimpleType(EdmSimpleTypeKind.Single), uriLiteral);
    }
    if (uriLiteral.endsWith("F") || uriLiteral.endsWith("f")) {
      return createEdmLiteral(EdmSimpleTypeKind.Single, uriLiteral, 0, 1);
    }

    if (uriLiteral.startsWith("datetime'")) {
      return createEdmLiteral(EdmSimpleTypeKind.DateTime, uriLiteral, 9, 1);
    }
    if (uriLiteral.startsWith("datetimeoffset'")) {
      return createEdmLiteral(EdmSimpleTypeKind.DateTimeOffset, uriLiteral, 15, 1);
    }
    if (uriLiteral.startsWith("guid'")) {
      return createEdmLiteral(EdmSimpleTypeKind.Guid, uriLiteral, 5, 1);
    }
    if (uriLiteral.startsWith("time'")) {
      return createEdmLiteral(EdmSimpleTypeKind.Time, uriLiteral, 5, 1);
    }

    if (uriLiteral.startsWith("X'") || uriLiteral.startsWith("binary'")) {
      try {
        final EdmSimpleType type = getEdmSimpleType(EdmSimpleTypeKind.Binary);
        final byte[] value = type.valueOfString(uriLiteral, EdmLiteralKind.URI, null, byte[].class);
        return new EdmLiteral(type, type.valueToString(value, EdmLiteralKind.DEFAULT, null));
      } catch (EdmSimpleTypeException e) {
        throw new EdmLiteralException(EdmLiteralException.LITERALFORMAT.addContent(uriLiteral), e);
      }
    }
View Full Code Here

  private static EdmLiteral createEdmLiteral(final EdmSimpleTypeKind typeKind, final String literal,
      final int prefixLength, final int suffixLength) throws EdmLiteralException {
    final EdmSimpleType type = getEdmSimpleType(typeKind);
    if (type.validate(literal, EdmLiteralKind.URI, null)) {
      return new EdmLiteral(type, literal.substring(prefixLength, literal.length() - suffixLength));
    } else {
      throw new EdmLiteralException(EdmLiteralException.LITERALFORMAT.addContent(literal));
    }
  }
View Full Code Here

    parseWrongLiteralContent("time'3'", EdmLiteralException.LITERALFORMAT);
  }

  private void parseIncompatibleLiteralContent(final String literal, final EdmSimpleTypeKind typeKind)
      throws EdmLiteralException {
    final EdmLiteral uriLiteral = EdmSimpleTypeKind.parseUriLiteral(literal);
    assertFalse(typeKind.getEdmSimpleTypeInstance().isCompatible(uriLiteral.getType()));
  }
View Full Code Here

    final Matcher matcher = OTHER_LIT.matcher(rem_expr);
    boolean isLiteral = false;
    if (matcher.lookingAt()) {
      String token = matcher.group();
      try {
        EdmLiteral edmLiteral = typeDectector.parseUriLiteral(token);
        curPosition = curPosition + token.length();
        // It is a simple type.
        tokens.appendEdmTypedToken(oldPosition, TokenKind.SIMPLE_TYPE, token, edmLiteral);
        isLiteral = true;
      } catch (EdmLiteralException e) {
View Full Code Here

  private boolean checkForBoolean(final int oldPosition, final String rem_expr) {
    boolean isBoolean = false;
    if (rem_expr.equals("true") || rem_expr.equals("false")) {
      curPosition = curPosition + rem_expr.length();
      tokens.appendEdmTypedToken(oldPosition, TokenKind.SIMPLE_TYPE, rem_expr, new EdmLiteral(EdmSimpleTypeFacadeImpl
          .getEdmSimpleType(EdmSimpleTypeKind.Boolean), rem_expr));
      isBoolean = true;
    }
    return isBoolean;
  }
View Full Code Here

      // Exception tested within TestPMparseFilterString
      throw FilterParserExceptionImpl.createTOKEN_UNDETERMINATED_STRING(oldPosition, expression);
    }

    try {
      EdmLiteral edmLiteral = typeDectector.parseUriLiteral(token);
      tokens.appendEdmTypedToken(oldPosition + offsetPos, TokenKind.SIMPLE_TYPE, token, edmLiteral);
    } catch (EdmLiteralException ex) {
      throw TokenizerException.createTYPEDECTECTION_FAILED_ON_STRING(ex, oldPosition, token);
    }
  }
View Full Code Here

        return null;
      } else {
        Object[] args = new Object[edmArguements.size()];
        int i = 0;
        for (String paramName : functionImport.getParameterNames()) {
          EdmLiteral literal = edmArguements.get(paramName);
          EdmParameter parameter = functionImport.getParameter(paramName);
          JPAEdmMapping mapping = (JPAEdmMapping) parameter.getMapping();
          args[i] = convertArguement(literal, parameter.getFacets(), mapping.getJPAType());
          i++;
        }
View Full Code Here

      if (parsedKeyProperties.contains(keyProperty)) {
        throw new UriSyntaxException(UriSyntaxException.DUPLICATEKEYNAMES.addContent(keyPredicate));
      }
      parsedKeyProperties.add(keyProperty);

      final EdmLiteral uriLiteral = parseLiteral(value, (EdmSimpleType) keyProperty.getType());
      keyPredicates.add(new KeyPredicateImpl(uriLiteral.getLiteral(), keyProperty));
    }

    if (parsedKeyProperties.size() != keyProperties.size()) {
      throw new UriSyntaxException(UriSyntaxException.INVALIDKEYPREDICATE.addContent(keyPredicate));
    }
View Full Code Here

TOP

Related Classes of org.apache.olingo.odata2.api.edm.EdmLiteral

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.