Examples of EdmLiteralException


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

        && 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);
      }
    }

    throw new EdmLiteralException(EdmLiteralException.UNKNOWNLITERAL.addContent(uriLiteral));
  }
View Full Code Here

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

      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
TOP
Copyright © 2018 www.massapi.com. 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.