The javaType binding declaration can be used to customize the binding of
an XML schema datatype to a Java datatype. Customizations can involve
writing a parse and print method for parsing and printing lexical
representations of a XML schema datatype respectively. However, writing
parse and print methods requires knowledge of the lexical representations (
XML Schema Part2: Datatypes
specification ) and hence may be difficult to write.
This class makes it easier to write parse and print methods. It defines
static parse and print methods that provide access to a JAXB provider's
implementation of parse and print methods. These methods are invoked by
custom parse and print methods. For example, the binding of xsd:dateTime
to a long can be customized using parse and print methods as follows:
// Customized parse method
public long myParseCal( String dateTimeString ) {
java.util.Calendar cal = DatatypeConverter.parseDateTime(dateTimeString);
long longval = convert_calendar_to_long(cal); //application specific
return longval;
}
// Customized print method
public String myPrintCal( Long longval ) {
java.util.Calendar cal = convert_long_to_calendar(longval) ; //application specific
String dateTimeString = DatatypeConverter.printDateTime(cal);
return dateTimeString;
}
There is a static parse and print method corresponding to each parse and
print method respectively in the
DatatypeConverterInterface DatatypeConverterInterface .
The static methods defined in the class can also be used to specify
a parse or a print method in a javaType binding declaration.
JAXB Providers are required to call the
DatatypeConverter.setDatatypeConverter(DatatypeConverterInterface) setDatatypeConverter api at some point before the first marshal or unmarshal
operation (perhaps during the call to JAXBContext.newInstance). This step is
necessary to configure the converter that should be used to perform the
print and parse functionality.
A print method for a XML schema datatype can output any lexical
representation that is valid with respect to the XML schema datatype.
If an error is encountered during conversion, then an IllegalArgumentException,
or a subclass of IllegalArgumentException must be thrown by the method.
JAXB Providers are required to call this method at some point before
allowing any of the JAXB client marshal or unmarshal operations to
occur.
Method Detail
parseAnySimpleType
public static String parseAnySimpleType(String lexicalXSDAnySimpleType)(Code)
Return a string containing the lexical representation of the
simple type.
Parameters: lexicalXSDAnySimpleType - A string containing lexicalrepresentation of the simple type.A string containing the lexical representation of the simple type.
parseBase64Binary
public static byte[] parseBase64Binary(String lexicalXSDBase64Binary)(Code)
Converts the string argument into an array of bytes.
Parameters: lexicalXSDBase64Binary - A string containing lexical representationof xsd:base64Binary.An array of bytes represented by the string argument. throws: IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:base64Binary
parseBoolean
public static boolean parseBoolean(String lexicalXSDBoolean)(Code)
Converts the string argument into a boolean value.
Parameters: lexicalXSDBoolean - A string containing lexical representation ofxsd:boolean.A boolean value represented by the string argument. throws: IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:boolean.
parseByte
public static byte parseByte(String lexicalXSDByte)(Code)
Converts the string argument into a byte value.
Parameters: lexicalXSDByte - A string containing lexical representation ofxsd:byte.A byte value represented by the string argument. throws: IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:byte.
Converts the string argument into a Calendar value.
Parameters: lexicalXSDDate - A string containing lexical representation ofxsd:Date.A Calendar value represented by the string argument. throws: IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:Date.
Converts the string argument into a Calendar value.
Parameters: lexicalXSDDateTime - A string containing lexical representation ofxsd:datetime.A Calendar object represented by the string argument. throws: IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:dateTime.
Converts the string argument into a BigDecimal value.
Parameters: lexicalXSDDecimal - A string containing lexical representation ofxsd:decimal.A BigDecimal value represented by the string argument. throws: NumberFormatException - lexicalXSDDecimal is not a valid string representation of java.math.BigDecimal.
parseDouble
public static double parseDouble(String lexicalXSDDouble)(Code)
Converts the string argument into a double value.
Parameters: lexicalXSDDouble - A string containing lexical representation ofxsd:double.A double value represented by the string argument. throws: NumberFormatException - lexicalXSDDouble is not a valid string representation of a double value.
parseFloat
public static float parseFloat(String lexicalXSDFloat)(Code)
Converts the string argument into a float value.
Parameters: lexicalXSDFloat - A string containing lexical representation ofxsd:float.A float value represented by the string argument. throws: NumberFormatException - lexicalXSDFloat is not a valid string representation of a float value.
parseHexBinary
public static byte[] parseHexBinary(String lexicalXSDHexBinary)(Code)
Converts the string argument into an array of bytes.
Parameters: lexicalXSDHexBinary - A string containing lexical representation ofxsd:hexBinary.An array of bytes represented by the string argument. throws: IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:hexBinary.
parseInt
public static int parseInt(String lexicalXSDInt)(Code)
Convert the string argument into an int value.
Parameters: lexicalXSDInt - A string containing a lexical representation ofxsd:int.A int value represented by the string argument. throws: NumberFormatException - lexicalXSDInt is not a valid string representation of an int value.
Convert the string argument into a BigInteger value.
Parameters: lexicalXSDInteger - A string containing a lexical representation ofxsd:integer.A BigInteger value represented by the string argument. throws: NumberFormatException - lexicalXSDInteger is not a valid string representation of a java.math.BigInteger value.
parseLong
public static long parseLong(String lexicalXSDLong)(Code)
Converts the string argument into a long value.
Parameters: lexicalXSDLong - A string containing lexical representation ofxsd:long.A long value represented by the string argument. throws: NumberFormatException - lexicalXSDLong is not a valid string representation of a long value.
String parameter lexicalXSDQname must conform to lexical value space specifed at
XML Schema Part 2:Datatypes specification:QNames Parameters: lexicalXSDQName - A string containing lexical representation of xsd:QName. Parameters: nsc - A namespace context for interpreting a prefix within a QName.A QName value represented by the string argument. throws: IllegalArgumentException - if string parameter does not conform to XML Schema Part 2 specification or if namespace prefix of lexicalXSDQname is not bound to a URI in NamespaceContext nsc.
parseShort
public static short parseShort(String lexicalXSDShort)(Code)
Converts the string argument into a short value.
Parameters: lexicalXSDShort - A string containing lexical representation ofxsd:short.A short value represented by the string argument. throws: NumberFormatException - lexicalXSDShort is not a valid string representation of a short value.
Convert the lexical XSD string argument into a String value.
Parameters: lexicalXSDString - A string containing a lexical representation ofxsd:string.A String value represented by the string argument.
Converts the string argument into a Calendar value.
Parameters: lexicalXSDTime - A string containing lexical representation ofxsd:time.A Calendar value represented by the string argument. throws: IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:Time.
parseUnsignedInt
public static long parseUnsignedInt(String lexicalXSDUnsignedInt)(Code)
Converts the string argument into a long value.
Parameters: lexicalXSDUnsignedInt - A string containing lexical representationof xsd:unsignedInt.A long value represented by the string argument. throws: NumberFormatException - if string parameter can not be parsed into a long value.
parseUnsignedShort
public static int parseUnsignedShort(String lexicalXSDUnsignedShort)(Code)
Converts the string argument into an int value.
Parameters: lexicalXSDUnsignedShort - A string containing lexicalrepresentation of xsd:unsignedShort.An int value represented by the string argument. throws: NumberFormatException - if string parameter can not be parsed into an int value.
Converts a string value into a string.
Parameters: val - A string valueA string containing a lexical representation of xsd:AnySimpleType
printBase64Binary
public static String printBase64Binary(byte[] val)(Code)
Converts an array of bytes into a string.
Parameters: val - An array of bytesA string containing a lexical representation of xsd:base64Binary throws: IllegalArgumentException - if val is null.
printBoolean
public static String printBoolean(boolean val)(Code)
Converts a boolean value into a string.
Parameters: val - A boolean valueA string containing a lexical representation of xsd:boolean
Converts a Calendar value into a string.
Parameters: val - A Calendar valueA string containing a lexical representation of xsd:date throws: IllegalArgumentException - if val is null.
Converts a Calendar value into a string.
Parameters: val - A Calendar valueA string containing a lexical representation of xsd:dateTime throws: IllegalArgumentException - if val is null.
Converts a BigDecimal value into a string.
Parameters: val - A BigDecimal valueA string containing a lexical representation of xsd:decimal throws: IllegalArgumentException - val is null.
printDouble
public static String printDouble(double val)(Code)
Converts a double value into a string.
Parameters: val - A double valueA string containing a lexical representation of xsd:double
Converts a float value into a string.
Parameters: val - A float valueA string containing a lexical representation of xsd:float
printHexBinary
public static String printHexBinary(byte[] val)(Code)
Converts an array of bytes into a string.
Parameters: val - An array of bytesA string containing a lexical representation of xsd:hexBinary throws: IllegalArgumentException - if val is null.
Converts a BigInteger value into a string.
Parameters: val - A BigInteger valueA string containing a lexical representation of xsd:integer throws: IllegalArgumentException - val is null.
Converts a QName instance into a string.
Parameters: val - A QName value Parameters: nsc - A namespace context for interpreting a prefix within a QName.A string containing a lexical representation of QName throws: IllegalArgumentException - if val is null or if nsc is non-null or nsc.getPrefix(nsprefixFromVal) is null.
Converts a Calendar value into a string.
Parameters: val - A Calendar valueA string containing a lexical representation of xsd:time throws: IllegalArgumentException - if val is null.
printUnsignedInt
public static String printUnsignedInt(long val)(Code)
Converts a long value into a string.
Parameters: val - A long valueA string containing a lexical representation of xsd:unsignedInt
printUnsignedShort
public static String printUnsignedShort(int val)(Code)
Converts an int value into a string.
Parameters: val - An int valueA string containing a lexical representation of xsd:unsignedShort
JAXB Providers are required to call this method at some point before
allowing any of the JAXB client marshal or unmarshal operations to
occur. This is necessary to configure the datatype converter that
should be used to perform the print and parse conversions.
Calling this api repeatedly will have no effect - the
DatatypeConverterInterface instance passed into the first invocation is
the one that will be used from then on.
Parameters: converter - an instance of a class that implements the DatatypeConverterInterface class - this parameter must not be null. throws: IllegalArgumentException - if the parameter is null