Examples of EdmSimpleTypeException


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

      final Class<T> returnType) throws EdmSimpleTypeException {
    Integer valueInteger;
    try {
      valueInteger = Integer.parseInt(value);
    } catch (final NumberFormatException e) {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
    }

    if (returnType.isAssignableFrom(Integer.class)) {
      return returnType.cast(valueInteger);
    } else if (returnType.isAssignableFrom(Byte.class)) {
      if (valueInteger >= Byte.MIN_VALUE && valueInteger <= Byte.MAX_VALUE) {
        return returnType.cast(valueInteger.byteValue());
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value,
            returnType));
      }
    } else if (returnType.isAssignableFrom(Short.class)) {
      if (valueInteger >= Short.MIN_VALUE && valueInteger <= Short.MAX_VALUE) {
        return returnType.cast(valueInteger.shortValue());
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value,
            returnType));
      }
    } else if (returnType.isAssignableFrom(Long.class)) {
      return returnType.cast(valueInteger.longValue());
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
    }
  }
View Full Code Here

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

      return value.toString();
    } else if (value instanceof Long) {
      if ((Long) value >= Integer.MIN_VALUE && (Long) value <= Integer.MAX_VALUE) {
        return value.toString();
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
      }
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
    }
  }
View Full Code Here

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

    try {
      if (literalKind == EdmLiteralKind.URI) {
        if (value.endsWith("L") || value.endsWith("l")) {
          valueLong = Long.parseLong(value.substring(0, value.length() - 1));
        } else {
          throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
        }
      } else {
        valueLong = Long.parseLong(value);
      }
    } catch (final NumberFormatException e) {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e);
    }

    if (returnType.isAssignableFrom(Long.class)) {
      return returnType.cast(valueLong);
    } else if (returnType.isAssignableFrom(Byte.class)) {
      if (valueLong >= Byte.MIN_VALUE && valueLong <= Byte.MAX_VALUE) {
        return returnType.cast(valueLong.byteValue());
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value,
            returnType));
      }
    } else if (returnType.isAssignableFrom(Short.class)) {
      if (valueLong >= Short.MIN_VALUE && valueLong <= Short.MAX_VALUE) {
        return returnType.cast(valueLong.shortValue());
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value,
            returnType));
      }
    } else if (returnType.isAssignableFrom(Integer.class)) {
      if (valueLong >= Integer.MIN_VALUE && valueLong <= Integer.MAX_VALUE) {
        return returnType.cast(valueLong.intValue());
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value,
            returnType));
      }
    } else if (returnType.isAssignableFrom(BigInteger.class)) {
      return returnType.cast(BigInteger.valueOf(valueLong));
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
    }
  }
View Full Code Here

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

      return value.toString();
    } else if (value instanceof BigInteger) {
      if (((BigInteger) value).bitLength() < Long.SIZE) {
        return value.toString();
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_ILLEGAL_CONTENT.addContent(value));
      }
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
    }
  }
View Full Code Here

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

    Calendar valueCalendar;
    if (literalKind == EdmLiteralKind.URI) {
      if (value.length() > 6 && value.startsWith("time'") && value.endsWith("'")) {
        valueCalendar = parseLiteral(value.substring(5, value.length() - 1), facets);
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
      }
    } else {
      valueCalendar = parseLiteral(value, facets);
    }

    if (returnType.isAssignableFrom(Calendar.class)) {
      return returnType.cast(valueCalendar);
    } else if (returnType.isAssignableFrom(Long.class)) {
      return returnType.cast(valueCalendar.getTimeInMillis());
    } else if (returnType.isAssignableFrom(Date.class)) {
      return returnType.cast(valueCalendar.getTime());
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
    }
  }
View Full Code Here

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

  private Calendar parseLiteral(final String literal, final EdmFacets facets) throws EdmSimpleTypeException {
    final Matcher matcher = PATTERN.matcher(literal);
    if (!matcher.matches()
        || (matcher.group(1) == null && matcher.group(2) == null && matcher.group(3) == null)) {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal));
    }

    Calendar dateTimeValue = Calendar.getInstance();
    dateTimeValue.clear();

    dateTimeValue.set(Calendar.HOUR_OF_DAY,
        matcher.group(1) == null ? 0 : Integer.parseInt(matcher.group(1)));
    dateTimeValue.set(Calendar.MINUTE,
        matcher.group(2) == null ? 0 : Integer.parseInt(matcher.group(2)));
    dateTimeValue.set(Calendar.SECOND,
        matcher.group(3) == null ? 0 : Integer.parseInt(matcher.group(3)));

    if (matcher.group(4) != null) {
      if (facets == null || facets.getPrecision() == null || facets.getPrecision() >= matcher.group(4).length()) {
        if (matcher.group(4).length() <= 3) {
          dateTimeValue.set(Calendar.MILLISECOND,
              Short.parseShort(matcher.group(4) + "000".substring(0, 3 - matcher.group(4).length())));
        } else {
          throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal));
        }
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(literal, facets));
      }
    }

    if (dateTimeValue.get(Calendar.DAY_OF_YEAR) == 1) {
      return dateTimeValue;
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal));
    }
  }
View Full Code Here

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

    } else if (value instanceof Long) {
      dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
      dateTimeValue.clear();
      dateTimeValue.setTimeInMillis((Long) value);
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
    }

    StringBuilder result = new StringBuilder(15); // 15 characters are enough for millisecond precision.
    result.append('P');
    result.append('T');
    result.append(dateTimeValue.get(Calendar.HOUR_OF_DAY));
    result.append('H');
    result.append(dateTimeValue.get(Calendar.MINUTE));
    result.append('M');
    result.append(dateTimeValue.get(Calendar.SECOND));

    try {
      EdmDateTime.appendMilliseconds(result, dateTimeValue.get(Calendar.MILLISECOND), facets);
    } catch (final IllegalArgumentException e) {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e);
    }

    result.append('S');

    return result.toString();
View Full Code Here

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

      final Class<T> returnType) throws EdmSimpleTypeException {
    if (validateLiteral(value)) {
      if (returnType.isAssignableFrom(Boolean.class)) {
        return returnType.cast(Boolean.valueOf("true".equals(value) || "1".equals(value)));
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
      }
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
    }
  }
View Full Code Here

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

  protected <T> String internalValueToString(final T value, final EdmLiteralKind literalKind, final EdmFacets facets)
      throws EdmSimpleTypeException {
    if (value instanceof Boolean) {
      return Boolean.toString((Boolean) value);
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
    }
  }
View Full Code Here

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

    String result;
    if (literalKind == EdmLiteralKind.URI) {
      if (value.length() >= 2 && value.startsWith("'") && value.endsWith("'")) {
        result = (value.substring(1, value.length() - 1)).replace("''", "'");
      } else {
        throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value));
      }
    } else {
      result = value;
    }

    if (facets != null
        && (facets.isUnicode() != null && !facets.isUnicode() && !PATTERN_ASCII.matcher(result).matches()
        || facets.getMaxLength() != null && facets.getMaxLength() < result.length())) {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets));
    }

    if (returnType.isAssignableFrom(String.class)) {
      return returnType.cast(result);
    } else {
      throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType));
    }
  }
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.