protected void writePrimitiveValue(final EdmPrimitiveType type, final Object primitiveValue, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final String xml10InvalidCharReplacement, final XMLStreamWriter writer) throws EdmPrimitiveTypeException, XMLStreamException { final String value = type.valueToString(primitiveValue, isNullable, maxLength, precision, scale, isUnicode); if (value == null) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true"); } else { // XML 1.0 does not handle certain unicode characters, they need to be replaced writer.writeCharacters(replaceInvalidCharacters(type, value, isUnicode, xml10InvalidCharReplacement)); } }
protected void writePrimitiveValue(final EdmPrimitiveType type, final Object primitiveValue, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final String xml10InvalidCharReplacement, final XMLStreamWriter writer) throws EdmPrimitiveTypeException, XMLStreamException { final String value = type.valueToString(primitiveValue, isNullable, maxLength, precision, scale, isUnicode); if (value == null) { writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true"); } else { // XML 1.0 does not handle certain unicode characters, they need to be replaced writer.writeCharacters(replaceInvalidCharacters(type, value, isUnicode, xml10InvalidCharReplacement)); } }
@Override public String toString() { if (value == null) { return ""; } else if (typeKind.isGeospatial()) { return value.toString(); } else { try { // TODO: set facets return type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException(e); } } }
@Override public String toString() { if (value == null) { return ""; } else if (typeKind.isGeospatial()) { return value.toString(); } else { try { // TODO: set facets return type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException(e); } } }
@Override public <T> T toCastValue(final Class<T> reference) throws EdmPrimitiveTypeException { if (value == null) { return null; } else if (typeKind.isGeospatial()) { return reference.cast(value); } else { // TODO: set facets return type.valueOfString(type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference); } }
@Override public <T> T toCastValue(final Class<T> reference) throws EdmPrimitiveTypeException { if (value == null) { return null; } else if (typeKind.isGeospatial()) { return reference.cast(value); } else { // TODO: set facets return type.valueOfString(type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, reference); } }
protected void primitiveValue(final JsonGenerator jgen, final EdmTypeInfo typeInfo, final Object value) throws IOException, EdmPrimitiveTypeException { final EdmPrimitiveTypeKind kind = typeInfo == null ? EdmTypeInfo.determineTypeKind(value) : typeInfo.getPrimitiveTypeKind(); if (value == null) { jgen.writeNull(); } else if (kind == EdmPrimitiveTypeKind.Boolean) { jgen.writeBoolean((Boolean) value); } else if (kind == null) { if (serverMode) { throw new EdmPrimitiveTypeException("The primitive type could not be determined."); } else { jgen.writeString(value.toString()); // This might not be valid OData. } } else { // TODO: add facets final String serialized = EdmPrimitiveTypeFactory.getInstance(kind) .valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null); if (isIEEE754Compatible && (kind == EdmPrimitiveTypeKind.Int64 || kind == EdmPrimitiveTypeKind.Decimal) || !NUMBER_TYPES.contains(kind)) { jgen.writeString(serialized); } else { jgen.writeNumber(serialized); } } }
protected void primitiveValue(final JsonGenerator jgen, final EdmTypeInfo typeInfo, final Object value) throws IOException, EdmPrimitiveTypeException { final EdmPrimitiveTypeKind kind = typeInfo == null ? EdmTypeInfo.determineTypeKind(value) : typeInfo.getPrimitiveTypeKind(); if (value == null) { jgen.writeNull(); } else if (kind == EdmPrimitiveTypeKind.Boolean) { jgen.writeBoolean((Boolean) value); } else if (kind == null) { if (serverMode) { throw new EdmPrimitiveTypeException("The primitive type could not be determined."); } else { jgen.writeString(value.toString()); // This might not be valid OData. } } else { // TODO: add facets final String serialized = EdmPrimitiveTypeFactory.getInstance(kind) .valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null); if (isIEEE754Compatible && (kind == EdmPrimitiveTypeKind.Int64 || kind == EdmPrimitiveTypeKind.Decimal) || !NUMBER_TYPES.contains(kind)) { jgen.writeString(serialized); } else { jgen.writeNumber(serialized); } } }
private String getLiteral(final Object value) throws EdmPrimitiveTypeException { final EdmProperty edmProperty = getEdmProperty(); String uriLiteral; if (edmProperty != null) { uriLiteral = ((EdmPrimitiveType) type) .valueToString(value, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()); } else { uriLiteral = ((EdmPrimitiveType) type).valueToString(value, null, null, null, null, null); } return ((EdmPrimitiveType) type).toUriLiteral(uriLiteral); } }
@Override public InputStream primitiveValue(final EdmPrimitiveType type, final Object value, final PrimitiveValueSerializerOptions options) throws SerializerException { try { final String result = type.valueToString(value, options.isNullable(), options.getMaxLength(), options.getPrecision(), options.getScale(), options.isUnicode()); return new ByteArrayInputStream(result.getBytes("UTF-8")); } catch (final EdmPrimitiveTypeException e) { throw new SerializerException("Error in primitive-value formatting.", e, SerializerException.MessageKeys.WRONG_PRIMITIVE_VALUE, type.getFullQualifiedName().getFullQualifiedNameAsString(), value.toString()); } catch (final UnsupportedEncodingException e) { throw new SerializerException("Encoding exception.", e, SerializerException.MessageKeys.IO_EXCEPTION); } }
@Override public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { return getUnderlyingType().valueToString(value, isNullable, maxLength == null ? getMaxLength() : maxLength, precision == null ? getPrecision() : precision, scale == null ? getScale() : scale, isUnicode == null ? isUnicode() : isUnicode); }
@Override public InputStream primitiveValue(final EdmPrimitiveType type, final Object value, final PrimitiveValueSerializerOptions options) throws SerializerException { try { final String result = type.valueToString(value, options.isNullable(), options.getMaxLength(), options.getPrecision(), options.getScale(), options.isUnicode()); return new ByteArrayInputStream(result.getBytes("UTF-8")); } catch (final EdmPrimitiveTypeException e) { throw new SerializerException("Error in primitive-value formatting.", e, SerializerException.MessageKeys.WRONG_PRIMITIVE_VALUE, type.getFullQualifiedName().getFullQualifiedNameAsString(), value.toString()); } catch (final UnsupportedEncodingException e) { throw new SerializerException("Encoding exception.", e, SerializerException.MessageKeys.IO_EXCEPTION); } }
@Override public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { return getUnderlyingType().valueToString(value, isNullable, maxLength == null ? getMaxLength() : maxLength, precision == null ? getPrecision() : precision, scale == null ? getScale() : scale, isUnicode == null ? isUnicode() : isUnicode); }
String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString( propertyValue, property.isNullable(), property.getMaxLength(), property.getPrecision(), property.getScale(), property.isUnicode());
public static String convertToODataURIValue(Object val, String odataType) throws EdmPrimitiveTypeException { if (val == null) { return "null"; // is this correct? //$NON-NLS-1$ } if(odataType.startsWith("Edm.")) { //$NON-NLS-1$ odataType = odataType.substring(4); } if (val instanceof AbstractGeospatialType) { Geometry g; try { g = GeometryUtils.getGeometry((AbstractGeospatialType)val); } catch (FunctionExecutionException e1) { throw new EdmPrimitiveTypeException(e1.getMessage(), e1); } return geometryToODataValueString(g, val instanceof GeometryType); } EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(odataType); String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString( val, true, null, null, Integer.MAX_VALUE, true); if (kind == EdmPrimitiveTypeKind.String) { return EdmString.getInstance().toUriLiteral(value); } return value; }
public static String convertToODataURIValue(Object val, String odataType) throws EdmPrimitiveTypeException { if (val == null) { return "null"; // is this correct? //$NON-NLS-1$ } if(odataType.startsWith("Edm.")) { //$NON-NLS-1$ odataType = odataType.substring(4); } if (val instanceof AbstractGeospatialType) { Geometry g; try { g = GeometryUtils.getGeometry((AbstractGeospatialType)val); } catch (FunctionExecutionException e1) { throw new EdmPrimitiveTypeException(e1.getMessage(), e1); } return geometryToODataValueString(g, val instanceof GeometryType); } EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(odataType); String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString( val, true, null, null, Integer.MAX_VALUE, true); if (kind == EdmPrimitiveTypeKind.String) { return EdmString.getInstance().toUriLiteral(value); } return value; }
try { final String value = type.toUriLiteral( type.valueToString(propertyValue, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()));
try { final String value = type.toUriLiteral( type.valueToString(propertyValue, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()));
protected void writePrimitiveValue(final String name, final EdmPrimitiveType type, final Object primitiveValue, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode, final JsonGenerator json) throws EdmPrimitiveTypeException, IOException { final String value = type.valueToString(primitiveValue, isNullable, maxLength, precision, scale, isUnicode); if (value == null) {
/** * This method returns the object which is the value of the property. * * @param edmProperty EdmProperty * @param value String value * @return Object * @throws ODataApplicationException */ private String readPrimitiveValueInString(EdmProperty edmProperty, Object value) throws ODataApplicationException { if (value == null) { return null; } try { EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmProperty.getType(); return edmPrimitiveType.valueToString(value, edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode()); } catch (EdmPrimitiveTypeException e) { throw new ODataApplicationException("Invalid value: " + value + " for property: " + edmProperty.getName(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault()); } }