/** * Returns the value as an instance of the specified class. * * This method converts the value according to its type and then casts it * to the specified class. * * @param as The instance class. * @param <T> The type. * @return The value cast to the specified type. */ public <T> T get(Class<T> as) { return ValueConverter.convertToJava(type, value, as); } }
@SuppressWarnings("unchecked") static public <T> T convertToJava(String type, String value, Class<T> as) { return (T) convertToJava(type, value); } static private DatatypeFactory getFactory() {
@SuppressWarnings("unchecked") static public <T> T convertToJava(String type, String value, Class<T> as) { return (T) convertToJava(type, value); }
/** * Returns the value as an instance of the specified class. * * This method converts the value according to its type and then casts it * to the specified class. * * @param as The instance class. * @param <T> The type. * @return The value cast to the specified type. */ public <T> T get(Class<T> as) { return ValueConverter.convertToJava(type, value, as); } }
/** * Returns the value cast to the specified type. * * This method converts the value according to the supplied type and then casts it * to the specified class. * * <p>The following types are supported: * <code>xs:anySimpleType</code>, * <code>xs:base64Binary</code>, <code>xs:boolean</code>, * <code>xs:byte</code>, <code>xs:date</code>, * <code>xs:dateTime</code>, <code>xs:dayTimeDuration</code>, * <code>xs:decimal</code>, <code>xs:double</code>, * <code>xs:duration</code>, <code>xs:float</code>, * <code>xs:int</code>, <code>xs:integer</code>, * <code>xs:long</code>, <code>xs:short</code>, * <code>xs:string</code>, <code>xs:time</code>, * <code>xs:unsignedInt</code>, <code>xs:unsignedLong</code>, * <code>xs:unsignedShort</code>, and * <code>xs:yearMonthDuration</code>.</p> * * @see com.marklogic.client.impl.ValueConverter#convertToJava(String,String) label * @param type The name of the XSD type to use for conversion. * @param as The class parameter * @param <T> The class to cast to * @return The value, cast to the specified type or */ public <T> T get(String type, Class<T> as) { return ValueConverter.convertToJava(type, value, as); } }
/** * Returns the value cast to the specified type. * * This method converts the value according to the supplied type and then casts it * to the specified class. * * <p>The following types are supported: * <code>xs:anySimpleType</code>, * <code>xs:base64Binary</code>, <code>xs:boolean</code>, * <code>xs:byte</code>, <code>xs:date</code>, * <code>xs:dateTime</code>, <code>xs:dayTimeDuration</code>, * <code>xs:decimal</code>, <code>xs:double</code>, * <code>xs:duration</code>, <code>xs:float</code>, * <code>xs:int</code>, <code>xs:integer</code>, * <code>xs:long</code>, <code>xs:short</code>, * <code>xs:string</code>, <code>xs:time</code>, * <code>xs:unsignedInt</code>, <code>xs:unsignedLong</code>, * <code>xs:unsignedShort</code>, and * <code>xs:yearMonthDuration</code>.</p> * * @see com.marklogic.client.impl.ValueConverter#convertToJava(String,String) label * @param type The name of the XSD type to use for conversion. * @param as The class parameter * @param <T> The class to cast to * @return The value, cast to the specified type or */ public <T> T get(String type, Class<T> as) { return ValueConverter.convertToJava(type, value, as); } }
/** * Returns the value cast to the specified type. * * This method converts the value according to the supplied type and then casts it * to the specified class. * * <p>The following types are supported: * <code>xs:anySimpleType</code>, * <code>xs:base64Binary</code>, <code>xs:boolean</code>, * <code>xs:byte</code>, <code>xs:date</code>, * <code>xs:dateTime</code>, <code>xs:dayTimeDuration</code>, * <code>xs:decimal</code>, <code>xs:double</code>, * <code>xs:duration</code>, <code>xs:float</code>, * <code>xs:int</code>, <code>xs:integer</code>, * <code>xs:long</code>, <code>xs:short</code>, * <code>xs:string</code>, <code>xs:time</code>, * <code>xs:unsignedInt</code>, <code>xs:unsignedLong</code>, * <code>xs:unsignedShort</code>, and * <code>xs:yearMonthDuration</code>.</p> * * @see ValueConverter#convertToJava(String,String) label * @param type The name of the XSD type to use for conversion. * @param as The class parameter * @param <T> The class to cast to * @return The value, cast to the specified type or */ public <T> T get(String type, Class<T> as) { return ValueConverter.convertToJava(type, value, as); } }
/** * Returns the value cast to the specified type. * * This method converts the value according to the supplied type and then casts it * to the specified class. * * <p>The following types are supported: * <code>xs:anySimpleType</code>, * <code>xs:base64Binary</code>, <code>xs:boolean</code>, * <code>xs:byte</code>, <code>xs:date</code>, * <code>xs:dateTime</code>, <code>xs:dayTimeDuration</code>, * <code>xs:decimal</code>, <code>xs:double</code>, * <code>xs:duration</code>, <code>xs:float</code>, * <code>xs:int</code>, <code>xs:integer</code>, * <code>xs:long</code>, <code>xs:short</code>, * <code>xs:string</code>, <code>xs:time</code>, * <code>xs:unsignedInt</code>, <code>xs:unsignedLong</code>, * <code>xs:unsignedShort</code>, and * <code>xs:yearMonthDuration</code>.</p> * * @see ValueConverter#convertToJava(String,String) label * @param type The name of the XSD type to use for conversion. * @param as The class parameter * @param <T> The class to cast to * @return The value, cast to the specified type or */ public <T> T get(String type, Class<T> as) { return ValueConverter.convertToJava(type, value, as); } }
XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); metadata.put(metadataPropertyName, ValueConverter.convertToJava(type, value)); continue; } else {
XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); metadata.put(metadataPropertyName, ValueConverter.convertToJava(type, value)); continue; } else {
String type = property.getAttributeNS( XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); properties.put(propertyName, ValueConverter.convertToJava(type, value)); continue; } else {
String type = property.getAttributeNS( XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); properties.put(propertyName, ValueConverter.convertToJava(type, value)); continue; } else {
void checkProcessor(String type, String xsType, Object value) { assertEquals(type+" type", xsType, processor.type); assertEquals(type+" value", value, ValueConverter.convertToJava(processor.type, processor.value) ); }
Calendar c = Calendar.getInstance(); ValueConverter.convertFromJava(c, processor); Calendar d = (Calendar) ValueConverter.convertToJava( processor.type, processor.value ); e.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH)); ValueConverter.convertFromJava(e, processor); d = (Calendar) ValueConverter.convertToJava( processor.type, processor.value ); e.set(Calendar.MILLISECOND, c.get(Calendar.MILLISECOND)); ValueConverter.convertFromJava(e, processor); d = (Calendar) ValueConverter.convertToJava( processor.type, processor.value );
@Test public void testConvertFromJavaByteArray() { byte[] b = {'a', 'b', 'c'}; ValueConverter.convertFromJava(b, processor); assertEquals("byte array type", "xs:base64Binary", processor.type); byte[] c = (byte[]) ValueConverter.convertToJava( processor.type, processor.value ); boolean isSame = true; if (c == null || b.length != c.length) { isSame = false; } else { for (int i=0; i < c.length; i++) { if (b[i] != c[i]) isSame = false; } } assertTrue("byte array value", isSame); } @Test