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 Jakarta XML Binding 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.
The static methods defined in the class can also be used to specify a parse or a print method in a javaType binding declaration.
Jakarta XML Binding Providers are required to call the
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.
DatatypeConverterInterface, ParseConversionEvent, PrintConversionEvent
| Modifier and Type | Field and Description |
|---|---|
| private static final JAXBPermission | |
| private static volatile DatatypeConverterInterface |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static synchronized void | |
| public static String | Returns: A string containing the lexical representation of the simple type.A string containing lexical
representation of the simple type. lexicalXSDAnySimpleType)Return a string containing the lexical representation of the simple type. |
| public static byte[] | Returns: An array of bytes represented by the string argument.A string containing lexical representation
of xsd:base64Binary. lexicalXSDBase64Binary)Converts the string argument into an array of bytes. |
| public static boolean | Returns: A boolean value represented by the string argument.A string containing lexical representation of
xsd:boolean. lexicalXSDBoolean)Converts the string argument into a boolean value. |
| public static byte | |
| public static Calendar | |
| public static Calendar | Returns: A Calendar object represented by the string argument.A string containing lexical representation of
xsd:datetime. lexicalXSDDateTime)Converts the string argument into a Calendar value. |
| public static BigDecimal | Returns: A BigDecimal value represented by the string argument.A string containing lexical representation of
xsd:decimal. lexicalXSDDecimal)Converts the string argument into a BigDecimal value. |
| public static double | Returns: A double value represented by the string argument.A string containing lexical representation of
xsd:double. lexicalXSDDouble)Converts the string argument into a double value. |
| public static float | Returns: A float value represented by the string argument.A string containing lexical representation of
xsd:float. lexicalXSDFloat)Converts the string argument into a float value. |
| public static byte[] | Returns: An array of bytes represented by the string argument.A string containing lexical representation of
xsd:hexBinary. lexicalXSDHexBinary)Converts the string argument into an array of bytes. |
| public static int | |
| public static BigInteger | Returns: A BigInteger value represented by the string argument.A string containing a lexical representation of
xsd:integer. lexicalXSDInteger)Convert the string argument into a BigInteger value. |
| public static long | |
| public static QName | Returns: A QName value represented by the string argument.A string containing lexical representation of xsd:QName. lexicalXSDQName, NamespaceContext A namespace context for interpreting a prefix within a QName. nsc)Converts the string argument into a byte value. |
| public static short | Returns: A short value represented by the string argument.A string containing lexical representation of
xsd:short. lexicalXSDShort)Converts the string argument into a short value. |
| public static String | Returns: A String value represented by the string argument.A string containing a lexical representation of
xsd:string. lexicalXSDString)Convert the lexical XSD string argument into a String value. |
| public static Calendar | |
| public static long | Returns: A long value represented by the string argument.A string containing lexical representation
of xsd:unsignedInt. lexicalXSDUnsignedInt)Converts the string argument into a long value. |
| public static int | Returns: An int value represented by the string argument.A string containing lexical
representation of xsd:unsignedShort. lexicalXSDUnsignedShort)Converts the string argument into an int value. |
| public static String | Returns: A string containing a lexical representation of xsd:AnySimpleTypeA string value val)Converts a string value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:base64BinaryAn array of bytes val)Converts an array of bytes into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:booleanA boolean value val)Converts a boolean value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:byteA byte value val)Converts a byte value into a string. |
| public static String | |
| public static String | Returns: A string containing a lexical representation of xsd:dateTimeA Calendar value val)Converts a Calendar value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:decimalA BigDecimal value val)Converts a BigDecimal value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:doubleA double value val)Converts a double value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:floatA float value val)Converts a float value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:hexBinaryAn array of bytes val)Converts an array of bytes into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:intAn int value val)Converts an int value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:integerA BigInteger value val)Converts a BigInteger value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:longA long value val)Converts A long value into a string. |
| public static String | Returns: A string containing a lexical representation of QNameA QName value val, NamespaceContext A namespace context for interpreting a prefix within a QName. nsc)Converts a QName instance into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:shortA short value val)Converts a short value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:string.A string value. val)Converts the string argument into a string. |
| public static String | |
| public static String | Returns: A string containing a lexical representation of xsd:unsignedIntA long value val)Converts a long value into a string. |
| public static String | Returns: A string containing a lexical representation of xsd:unsignedShortAn int value val)Converts an int value into a string. |
| public static void | setDatatypeConverter(DatatypeConverterInterface
an instance of a class that implements the
DatatypeConverterInterface class - this parameter must not be null. converter)This method is for Jakarta XML Binding provider use only. |
| SET_DATATYPE_CONVERTER_PERMISSION | back to summary |
|---|---|
| private static final JAXBPermission SET_DATATYPE_CONVERTER_PERMISSION | |
| theConverter | back to summary |
|---|---|
| private static volatile DatatypeConverterInterface theConverter | |
| DatatypeConverter | back to summary |
|---|---|
| private DatatypeConverter() | |
| initConverter | back to summary |
|---|---|
| private static synchronized void initConverter() | |
| parseAnySimpleType | back to summary |
|---|---|
| public static String parseAnySimpleType(String lexicalXSDAnySimpleType) Return a string containing the lexical representation of the simple type. | |
| parseBase64Binary | back to summary |
|---|---|
| public static byte[] parseBase64Binary(String lexicalXSDBase64Binary) Converts the string argument into an array of bytes.
| |
| parseBoolean | back to summary |
|---|---|
| public static boolean parseBoolean(String lexicalXSDBoolean) Converts the string argument into a boolean value.
| |
| parseByte | back to summary |
|---|---|
| public static byte parseByte(String lexicalXSDByte) Converts the string argument into a byte value.
| |
| parseDate | back to summary |
|---|---|
| public static Calendar parseDate(String lexicalXSDDate) Converts the string argument into a Calendar value.
| |
| parseDateTime | back to summary |
|---|---|
| public static Calendar parseDateTime(String lexicalXSDDateTime) Converts the string argument into a Calendar value.
| |
| parseDecimal | back to summary |
|---|---|
| public static BigDecimal parseDecimal(String lexicalXSDDecimal) Converts the string argument into a BigDecimal value.
| |
| parseDouble | back to summary |
|---|---|
| public static double parseDouble(String lexicalXSDDouble) Converts the string argument into a double value.
| |
| parseFloat | back to summary |
|---|---|
| public static float parseFloat(String lexicalXSDFloat) Converts the string argument into a float value.
| |
| parseHexBinary | back to summary |
|---|---|
| public static byte[] parseHexBinary(String lexicalXSDHexBinary) Converts the string argument into an array of bytes.
| |
| parseInt | back to summary |
|---|---|
| public static int parseInt(String lexicalXSDInt) Convert the string argument into an int value.
| |
| parseInteger | back to summary |
|---|---|
| public static BigInteger parseInteger(String lexicalXSDInteger) Convert the string argument into a BigInteger value.
| |
| parseLong | back to summary |
|---|---|
| public static long parseLong(String lexicalXSDLong) Converts the string argument into a long value.
| |
| parseQName | back to summary |
|---|---|
| public static QName parseQName(String lexicalXSDQName, NamespaceContext nsc) Converts the string argument into a byte value.
String parameter
| |
| parseShort | back to summary |
|---|---|
| public static short parseShort(String lexicalXSDShort) Converts the string argument into a short value.
| |
| parseString | back to summary |
|---|---|
| public static String parseString(String lexicalXSDString) Convert the lexical XSD string argument into a String value. | |
| parseTime | back to summary |
|---|---|
| public static Calendar parseTime(String lexicalXSDTime) Converts the string argument into a Calendar value.
| |
| parseUnsignedInt | back to summary |
|---|---|
| public static long parseUnsignedInt(String lexicalXSDUnsignedInt) Converts the string argument into a long value.
| |
| parseUnsignedShort | back to summary |
|---|---|
| public static int parseUnsignedShort(String lexicalXSDUnsignedShort) Converts the string argument into an int value.
| |
| printAnySimpleType | back to summary |
|---|---|
| public static String printAnySimpleType(String val) Converts a string value into a string. | |
| printBase64Binary | back to summary |
|---|---|
| public static String printBase64Binary(byte[] val) Converts an array of bytes into a string.
| |
| printBoolean | back to summary |
|---|---|
| public static String printBoolean(boolean val) Converts a boolean value into a string.
| |
| printByte | back to summary |
|---|---|
| public static String printByte(byte val) Converts a byte value into a string.
| |
| printDate | back to summary |
|---|---|
| public static String printDate(Calendar val) Converts a Calendar value into a string.
| |
| printDateTime | back to summary |
|---|---|
| public static String printDateTime(Calendar val) Converts a Calendar value into a string.
| |
| printDecimal | back to summary |
|---|---|
| public static String printDecimal(BigDecimal val) Converts a BigDecimal value into a string.
| |
| printDouble | back to summary |
|---|---|
| public static String printDouble(double val) Converts a double value into a string.
| |
| printFloat | back to summary |
|---|---|
| public static String printFloat(float val) Converts a float value into a string.
| |
| printHexBinary | back to summary |
|---|---|
| public static String printHexBinary(byte[] val) Converts an array of bytes into a string.
| |
| printInt | back to summary |
|---|---|
| public static String printInt(int val) Converts an int value into a string.
| |
| printInteger | back to summary |
|---|---|
| public static String printInteger(BigInteger val) Converts a BigInteger value into a string.
| |
| printLong | back to summary |
|---|---|
| public static String printLong(long val) Converts A long value into a string.
| |
| printQName | back to summary |
|---|---|
| public static String printQName(QName val, NamespaceContext nsc) Converts a QName instance into a string.
| |
| printShort | back to summary |
|---|---|
| public static String printShort(short val) Converts a short value into a string.
| |
| printString | back to summary |
|---|---|
| public static String printString(String val) Converts the string argument into a string. | |
| printTime | back to summary |
|---|---|
| public static String printTime(Calendar val) Converts a Calendar value into a string.
| |
| printUnsignedInt | back to summary |
|---|---|
| public static String printUnsignedInt(long val) Converts a long value into a string.
| |
| printUnsignedShort | back to summary |
|---|---|
| public static String printUnsignedShort(int val) Converts an int value into a string.
| |
| setDatatypeConverter | back to summary |
|---|---|
| public static void setDatatypeConverter(DatatypeConverterInterface converter) This method is for Jakarta XML Binding provider use only. Jakarta XML Binding Providers are required to call this method at some point before allowing any of the Jakarta XML Binding 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.
| |