|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.xml.bind.DatatypeConverter
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
.
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
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.
DatatypeConverterInterface
,
ParseConversionEvent
,
PrintConversionEvent
Method Summary | |
static java.lang.String |
parseAnySimpleType(java.lang.String lexicalAnySimpleType)
Return a string containing the lexical representation of the simple type. |
static byte[] |
parseBase64Binary(java.lang.String lexicalXSDBase64Binary)
Converts the string argument into an array of bytes. |
static boolean |
parseBoolean(java.lang.String lexicalXSDBoolean)
Converts the string argument into a boolean value. |
static byte |
parseByte(java.lang.String lexicalXSDByte)
Converts the string argument into a byte value. |
static java.util.Calendar |
parseDate(java.lang.String lexicalXSDDate)
Converts the string argument into a Calendar value. |
static java.util.Calendar |
parseDateTime(java.lang.String lexicalXSDDateTime)
Converts the string argument into a Calendar value. |
static java.math.BigDecimal |
parseDecimal(java.lang.String lexicalXSDDecimal)
Converts the string argument into a BigDecimal value. |
static double |
parseDouble(java.lang.String lexicalXSDDouble)
Converts the string argument into a double value. |
static float |
parseFloat(java.lang.String lexicalXSDFloat)
Converts the string argument into a float value. |
static byte[] |
parseHexBinary(java.lang.String lexicalXSDHexBinary)
Converts the string argument into an array of bytes. |
static int |
parseInt(java.lang.String lexicalXSDInt)
Convert the string argument into an int value. |
static java.math.BigInteger |
parseInteger(java.lang.String lexicalXSDInteger)
Convert the string argument into a BigInteger value. |
static long |
parseLong(java.lang.String lexicalXSLong)
Converts the string argument into a long value. |
static QName |
parseQName(java.lang.String lexicalXSDQName,
NamespaceContext nsc)
Converts the string argument into a byte value. |
static short |
parseShort(java.lang.String lexicalXSShort)
Converts the string argument into a short value. |
static java.lang.String |
parseString(java.lang.String lexicalXSDString)
Convert the lexical XSD string argument into a String value. |
static java.util.Calendar |
parseTime(java.lang.String lexicalXSDTime)
Converts the string argument into a Calendar value. |
static long |
parseUnsignedInt(java.lang.String lexicalXSDUnsignedInt)
Converts the string argument into a long value. |
static int |
parseUnsignedShort(java.lang.String lexicalXSDUnsignedShort)
Converts the string argument into an int value. |
static java.lang.String |
printAnySimpleType(java.lang.String val)
Converts a string value into a string. |
static java.lang.String |
printBase64Binary(byte[] val)
Converts an array of bytes into a string. |
static java.lang.String |
printBoolean(boolean val)
Converts a boolean value into a string. |
static java.lang.String |
printByte(byte val)
Converts a byte value into a string. |
static java.lang.String |
printDate(java.util.Calendar val)
Converts a Calendar value into a string. |
static java.lang.String |
printDateTime(java.util.Calendar val)
Converts a Calendar value into a string. |
static java.lang.String |
printDecimal(java.math.BigDecimal val)
Converts a BigDecimal value into a string. |
static java.lang.String |
printDouble(double val)
Converts a double value into a string. |
static java.lang.String |
printFloat(float val)
Converts a float value into a string. |
static java.lang.String |
printHexBinary(byte[] val)
Converts an array of bytes into a string. |
static java.lang.String |
printInt(int val)
Converts an int value into a string. |
static java.lang.String |
printInteger(java.math.BigInteger val)
Converts a BigInteger value into a string. |
static java.lang.String |
printLong(long val)
Converts A long value into a string. |
static java.lang.String |
printQName(QName val,
NamespaceContext nsc)
Converts a QName instance into a string. |
static java.lang.String |
printShort(short val)
Converts a short value into a string. |
static java.lang.String |
printString(java.lang.String val)
Converts the string argument into a string. |
static java.lang.String |
printTime(java.util.Calendar val)
Converts a Calendar value into a string. |
static java.lang.String |
printUnsignedInt(long val)
Converts a long value into a string. |
static java.lang.String |
printUnsignedShort(int val)
Converts an int value into a string. |
static void |
setDatatypeConverter(DatatypeConverterInterface converter)
This method is for JAXB provider use only. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void setDatatypeConverter(DatatypeConverterInterface converter)
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.
converter
- an instance of a class that implements the
DatatypeConverterInterface class - this parameter must not be null.
java.lang.IllegalArgumentException
- if the parameter is nullpublic static java.lang.String parseString(java.lang.String lexicalXSDString)
Convert the lexical XSD string argument into a String value.
lexicalXSDString
- A string containing a lexical representation of
xsd:string.
public static java.math.BigInteger parseInteger(java.lang.String lexicalXSDInteger)
Convert the string argument into a BigInteger value.
lexicalXSDInteger
- A string containing a lexical representation of
xsd:integer.
public static int parseInt(java.lang.String lexicalXSDInt)
Convert the string argument into an int value.
lexicalXSDInt
- A string containing a lexical representation of
xsd:int.
public static long parseLong(java.lang.String lexicalXSLong)
Converts the string argument into a long value.
public static short parseShort(java.lang.String lexicalXSShort)
Converts the string argument into a short value.
public static java.math.BigDecimal parseDecimal(java.lang.String lexicalXSDDecimal)
Converts the string argument into a BigDecimal value.
lexicalXSDDecimal
- A string containing lexical representation of
xsd:decimal.
public static float parseFloat(java.lang.String lexicalXSDFloat)
Converts the string argument into a float value.
lexicalXSDFloat
- A string containing lexical representation of
xsd:float.
public static double parseDouble(java.lang.String lexicalXSDDouble)
Converts the string argument into a double value.
lexicalXSDDouble
- A string containing lexical representation of
xsd:double.
public static boolean parseBoolean(java.lang.String lexicalXSDBoolean)
Converts the string argument into a boolean value.
lexicalXSDBoolean
- A string containing lexical representation of
xsd:boolean.
public static byte parseByte(java.lang.String lexicalXSDByte)
Converts the string argument into a byte value.
lexicalXSDByte
- A string containing lexical representation of
xsd:byte.
public static QName parseQName(java.lang.String lexicalXSDQName, NamespaceContext nsc)
Converts the string argument into a byte value.
lexicalXSDQName
- A string containing lexical representation of xsd:QName.nsc
- A namespace context for interpreting a prefix within a QName.
public static java.util.Calendar parseDateTime(java.lang.String lexicalXSDDateTime)
Converts the string argument into a Calendar value.
lexicalXSDDateTime
- A string containing lexical representation of
xsd:datetime.
public static byte[] parseBase64Binary(java.lang.String lexicalXSDBase64Binary)
Converts the string argument into an array of bytes.
lexicalXSDBase64Binary
- A string containing lexical representation
of xsd:base64Binary.
public static byte[] parseHexBinary(java.lang.String lexicalXSDHexBinary)
Converts the string argument into an array of bytes.
lexicalXSDHexBinary
- A string containing lexical representation of
xsd:hexBinary.
public static long parseUnsignedInt(java.lang.String lexicalXSDUnsignedInt)
Converts the string argument into a long value.
lexicalXSDUnsignedInt
- A string containing lexical representation
of xsd:unsignedInt.
public static int parseUnsignedShort(java.lang.String lexicalXSDUnsignedShort)
Converts the string argument into an int value.
lexicalXSDUnsignedShort
- A string containing lexical
representation of xsd:unsignedShort.
public static java.util.Calendar parseTime(java.lang.String lexicalXSDTime)
Converts the string argument into a Calendar value.
lexicalXSDTime
- A string containing lexical representation of
xsd:time.
public static java.util.Calendar parseDate(java.lang.String lexicalXSDDate)
Converts the string argument into a Calendar value.
lexicalXSDDate
- A string containing lexical representation of
xsd:Date.
public static java.lang.String parseAnySimpleType(java.lang.String lexicalAnySimpleType)
Return a string containing the lexical representation of the simple type.
public static java.lang.String printString(java.lang.String val)
Converts the string argument into a string.
val
- A string value.
public static java.lang.String printInteger(java.math.BigInteger val)
Converts a BigInteger value into a string.
val
- A BigInteger value
public static java.lang.String printInt(int val)
Converts an int value into a string.
val
- An int value
public static java.lang.String printLong(long val)
Converts A long value into a string.
val
- A long value
public static java.lang.String printShort(short val)
Converts a short value into a string.
val
- A short value
public static java.lang.String printDecimal(java.math.BigDecimal val)
Converts a BigDecimal value into a string.
val
- A BigDecimal value
public static java.lang.String printFloat(float val)
Converts a float value into a string.
val
- A float value
public static java.lang.String printDouble(double val)
Converts a double value into a string.
val
- A double value
public static java.lang.String printBoolean(boolean val)
Converts a boolean value into a string.
val
- A boolean value
public static java.lang.String printByte(byte val)
Converts a byte value into a string.
val
- A byte value
public static java.lang.String printQName(QName val, NamespaceContext nsc)
Converts a QName instance into a string.
val
- A QName valuensc
- A namespace context for interpreting a prefix within a QName.
public static java.lang.String printDateTime(java.util.Calendar val)
Converts a Calendar value into a string.
val
- A Calendar value
public static java.lang.String printBase64Binary(byte[] val)
Converts an array of bytes into a string.
val
- An array of bytes
public static java.lang.String printHexBinary(byte[] val)
Converts an array of bytes into a string.
val
- An array of bytes
public static java.lang.String printUnsignedInt(long val)
Converts a long value into a string.
val
- A long value
public static java.lang.String printUnsignedShort(int val)
Converts an int value into a string.
val
- An int value
public static java.lang.String printTime(java.util.Calendar val)
Converts a Calendar value into a string.
val
- A Calendar value
public static java.lang.String printDate(java.util.Calendar val)
Converts a Calendar value into a string.
val
- A Calendar value
public static java.lang.String printAnySimpleType(java.lang.String val)
Converts a string value into a string.
val
- A string value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |