protected Class<?> getDefaultType(final EdmPrimitiveType type) { return defaultTypeMapping.get(type) != null ? defaultTypeMapping.get(type) : type.getDefaultType(); }
@Override public Class<?> getDefaultType() { return getUnderlyingType().getDefaultType(); }
@Override public Class<?> getDefaultType() { return getUnderlyingType().getDefaultType(); }
@Override public Class<?> getDefaultType() { return getUnderlyingType().getDefaultType(); }
@Override public Class<?> getDefaultType() { return getUnderlyingType().getDefaultType(); }
@Override public Object get() throws ODataApplicationException { final EdmPrimitiveType edmType = ((EdmPrimitiveType) literal.getType()); try { final Class<?> defaultType = edmType.getDefaultType(); final Constructor<?> c = defaultType.getConstructor(String.class); return c.newInstance(edmType.fromUriLiteral(literalText)); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | EdmPrimitiveTypeException | InstantiationException | NoSuchMethodException | SecurityException e) { throw new ODataJPAFilterException(e, HttpStatusCode.INTERNAL_SERVER_ERROR); } }
/** * This method returns java class to read primitive values. * * @param edmProperty EdmProperty * @param edmPrimitiveType EdmPrimitiveType * @return javaClass * @see EdmPrimitiveType#valueOfString(String, Boolean, Integer, Integer, Integer, Boolean, Class) */ private Class<?> getJavaClassForPrimitiveType(EdmProperty edmProperty, EdmPrimitiveType edmPrimitiveType) { Class<?> javaClass; if (edmProperty.getMapping() != null && edmProperty.getMapping().getMappedJavaClass() != null) { javaClass = edmProperty.getMapping().getMappedJavaClass(); } else { javaClass = edmPrimitiveType.getDefaultType(); } edmPrimitiveType.getDefaultType(); return javaClass; }
private Object fromPrimitive(final JsonNode node, final EdmTypeInfo typeInfo) throws EdmPrimitiveTypeException { return node.isNull() ? null : typeInfo == null ? node.asText() : typeInfo.getPrimitiveTypeKind().isGeospatial() ? getGeoDeserializer().deserialize(node, typeInfo) : ((EdmPrimitiveType) typeInfo.getType()) .valueOfString(node.asText(), true, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true, ((EdmPrimitiveType) typeInfo.getType()).getDefaultType()); }
private Object fromPrimitive(final JsonNode node, final EdmTypeInfo typeInfo) throws EdmPrimitiveTypeException { return node.isNull() ? null : typeInfo == null ? node.asText() : typeInfo.getPrimitiveTypeKind().isGeospatial() ? getGeoDeserializer().deserialize(node, typeInfo) : ((EdmPrimitiveType) typeInfo.getType()) .valueOfString(node.asText(), true, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true, ((EdmPrimitiveType) typeInfo.getType()).getDefaultType()); }
private Object convertKeyValue(final OData odata, final String keyElementValue, final JPAPath path) throws ODataJPAModelException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, EdmPrimitiveTypeException { EdmPrimitiveType edmType = odata.createPrimitiveTypeInstance(path.getLeaf().getEdmType()); final Class<?> defaultType = edmType.getDefaultType(); final Constructor<?> c = defaultType.getConstructor(String.class); final Object value = c.newInstance(edmType.fromUriLiteral(keyElementValue)); return helper.processAttributeConverter(value, path.getLeaf()); }
} else { final EdmPrimitiveType primitiveType = (EdmPrimitiveType) typeInfo.getType(); final Class<?> returnType = primitiveType.getDefaultType().isAssignableFrom(Calendar.class) ? Timestamp.class : primitiveType.getDefaultType(); value = ((EdmPrimitiveType) typeInfo.getType()).valueOfString(stringValue, true, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true,
@Override public Object primitiveValue(final InputStream content, final EdmProperty property) throws DeserializerException { if (property == null || !property.isPrimitive()) { throw new DeserializerException("Wrong property.", DeserializerException.MessageKeys.NOT_IMPLEMENTED); } try { StringWriter writer = new StringWriter(); InputStreamReader reader = new InputStreamReader(content, "UTF-8"); int c = -1; while ((c = reader.read()) != -1) { writer.append((char) c); } final EdmPrimitiveType type = (EdmPrimitiveType) property.getType(); return type.valueOfString(writer.toString(), property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(), property.isUnicode(), type.getDefaultType()); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException("The value is not valid.", e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, property.getName()); } catch (final IOException e) { throw new DeserializerException("An I/O exception occurred.", e, DeserializerException.MessageKeys.IO_EXCEPTION); } }
@Override public Object primitiveValue(final InputStream content, final EdmProperty property) throws DeserializerException { if (property == null || !property.isPrimitive()) { throw new DeserializerException("Wrong property.", DeserializerException.MessageKeys.NOT_IMPLEMENTED); } try { StringWriter writer = new StringWriter(); InputStreamReader reader = new InputStreamReader(content, "UTF-8"); int c = -1; while ((c = reader.read()) != -1) { writer.append((char) c); } final EdmPrimitiveType type = (EdmPrimitiveType) property.getType(); return type.valueOfString(writer.toString(), property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(), property.isUnicode(), type.getDefaultType()); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException("The value is not valid.", e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, property.getName()); } catch (final IOException e) { throw new DeserializerException("An I/O exception occurred.", e, DeserializerException.MessageKeys.IO_EXCEPTION); } }
/** * Returns the primitive type's default class or the manually mapped class if present. * @param mapping * @param edmPrimitiveType * @return the java class to be used during deserialization */ private Class<?> getJavaClassForPrimitiveType(final EdmMapping mapping, final EdmPrimitiveType type) { final EdmPrimitiveType edmPrimitiveType = type.getKind() == EdmTypeKind.ENUM ? ((EdmEnumType) type).getUnderlyingType() : type .getKind() == EdmTypeKind.DEFINITION ? ((EdmTypeDefinition) type).getUnderlyingType() : type; return mapping == null || mapping.getMappedJavaClass() == null ? edmPrimitiveType.getDefaultType() : mapping .getMappedJavaClass(); }
private static EdmTypeInfo guessPrimitiveType(final EdmEnabledODataClient client, final Class<?> clazz) { EdmPrimitiveTypeKind bckCandidate = null; for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) { final Class<?> target = EdmPrimitiveTypeFactory.getInstance(kind).getDefaultType(); if (clazz.equals(target)) { return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(kind.toString()).build(); } else if (target.isAssignableFrom(clazz)) { bckCandidate = kind; } else if (target == Timestamp.class && kind == EdmPrimitiveTypeKind.DateTimeOffset) { bckCandidate = kind; } } if (bckCandidate == null) { throw new IllegalArgumentException(clazz.getSimpleName() + " is not a simple type"); } else { return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(bckCandidate.toString()).build(); } }
/** * Returns the primitive type's default class or the manually mapped class if present. * @param mapping * @param edmPrimitiveType * @return the java class to be used during deserialization */ private Class<?> getJavaClassForPrimitiveType(final EdmMapping mapping, final EdmPrimitiveType type) { final EdmPrimitiveType edmPrimitiveType = type.getKind() == EdmTypeKind.ENUM ? ((EdmEnumType) type).getUnderlyingType() : type .getKind() == EdmTypeKind.DEFINITION ? ((EdmTypeDefinition) type).getUnderlyingType() : type; return mapping == null || mapping.getMappedJavaClass() == null ? edmPrimitiveType.getDefaultType() : mapping .getMappedJavaClass(); }
private static EdmTypeInfo guessPrimitiveType(final EdmEnabledODataClient client, final Class<?> clazz) { EdmPrimitiveTypeKind bckCandidate = null; for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) { final Class<?> target = EdmPrimitiveTypeFactory.getInstance(kind).getDefaultType(); if (clazz.equals(target)) { return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(kind.toString()).build(); } else if (target.isAssignableFrom(clazz)) { bckCandidate = kind; } else if (target == Timestamp.class && kind == EdmPrimitiveTypeKind.DateTimeOffset) { bckCandidate = kind; } } if (bckCandidate == null) { throw new IllegalArgumentException(clazz.getSimpleName() + " is not a simple type"); } else { return new EdmTypeInfo.Builder().setEdm(client.getCachedEdm()).setTypeExpression(bckCandidate.toString()).build(); } }
/** * Returns the primitive type's default class or the manually mapped class * if present. * * @param mapping * @param edmPrimitiveType * @return the java class to be used during deserialization */ private Class<?> getJavaClassForPrimitiveType(final EdmMapping mapping, final EdmPrimitiveType type) { final EdmPrimitiveType edmPrimitiveType = type.getKind() == EdmTypeKind.ENUM ? ((EdmEnumType) type).getUnderlyingType() : type.getKind() == EdmTypeKind.DEFINITION ? ((EdmTypeDefinition) type).getUnderlyingType() : type; return mapping == null || mapping.getMappedJavaClass() == null ? edmPrimitiveType.getDefaultType() : mapping.getMappedJavaClass(); }
@Override public Parameter parameter(final String content, final EdmParameter parameter) throws DeserializerException { final EdmType type = parameter.getType(); final EdmTypeKind kind = type.getKind(); if ((kind == EdmTypeKind.PRIMITIVE || kind == EdmTypeKind.DEFINITION || kind == EdmTypeKind.ENUM) && !parameter.isCollection()) { // The content is a primitive URI literal. Parameter result = new Parameter(); result.setName(parameter.getName()); result.setType(type.getFullQualifiedName().getFullQualifiedNameAsString()); final EdmPrimitiveType primitiveType = (EdmPrimitiveType) type; try { result.setValue(type.getKind() == EdmTypeKind.ENUM ? ValueType.ENUM : ValueType.PRIMITIVE, primitiveType.valueOfString(primitiveType.fromUriLiteral(content), parameter.isNullable(), parameter.getMaxLength(), parameter.getPrecision(), parameter.getScale(), true, parameter.getMapping() == null ? primitiveType.getDefaultType() : parameter.getMapping().getMappedJavaClass())); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException( "Invalid value '" + content + "' for parameter " + parameter.getName(), e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, parameter.getName()); } return result; } else { // The content is a JSON array or object. return new ODataJsonDeserializer(ContentType.JSON).parameter(content, parameter); } }
@Override public Parameter parameter(final String content, final EdmParameter parameter) throws DeserializerException { final EdmType type = parameter.getType(); final EdmTypeKind kind = type.getKind(); if ((kind == EdmTypeKind.PRIMITIVE || kind == EdmTypeKind.DEFINITION || kind == EdmTypeKind.ENUM) && !parameter.isCollection()) { // The content is a primitive URI literal. Parameter result = new Parameter(); result.setName(parameter.getName()); result.setType(type.getFullQualifiedName().getFullQualifiedNameAsString()); final EdmPrimitiveType primitiveType = (EdmPrimitiveType) type; try { result.setValue(type.getKind() == EdmTypeKind.ENUM ? ValueType.ENUM : ValueType.PRIMITIVE, primitiveType.valueOfString(primitiveType.fromUriLiteral(content), parameter.isNullable(), parameter.getMaxLength(), parameter.getPrecision(), parameter.getScale(), true, parameter.getMapping() == null ? primitiveType.getDefaultType() : parameter.getMapping().getMappedJavaClass())); } catch (final EdmPrimitiveTypeException e) { throw new DeserializerException( "Invalid value '" + content + "' for parameter " + parameter.getName(), e, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, parameter.getName()); } return result; } else { // The content is a JSON array or object. return new ODataJsonDeserializer(ContentType.JSON).parameter(content, parameter); } }