javax.xml.bind

Class DatatypeConverter


public final class DatatypeConverter
extends java.lang.Object

This is a helper class for customized datatypes. It provides a set of static methods which may be useful in custom methods for parsing and printing values.

The JAXB provider is responsible to initialize the DatatypeConverter class by invoking setDatatypeConverter(DatatypeConverterInterface) as soon as possible.

Author:
JSR-31
Since:
JAXB1.0

Method Summary

static String
parseAnySimpleType(String pLexicalXSDAnySimpleType)
Returns the lexical representation of the input string, which is the unmodified input string.
static byte[]
parseBase64Binary(String pLexicalXSDBase64Binary)
Parses the lexical representation of the given byte array, which is encoded in base 64.
static boolean
parseBoolean(String pLexicalXSDBoolean)
Parses the lexical representation of the given boolean value and converts it into a primitive boolean value.
static byte
parseByte(String pLexicalXSDByte)
Parses the lexical representation of the given 8 bit integer value and converts it into a primitive byte value.
static Calendar
parseDate(String pLexicalXSDDate)
Parses the lexical representation of the given date value and converts it into an instance of java.util.Calendar.
static Calendar
parseDateTime(String pLexicalXSDDateTime)
Parses the lexical representation of the given dateTime value and converts it into an instance of java.util.Calendar.
static BigDecimal
parseDecimal(String pLexicalXSDDecimal)
Parses the lexical representation of the given decimal value (arbitrary precision) and converts it into an instance of java.math.BigDecimal.
static double
parseDouble(String pLexicalXSDDouble)
Parses the lexical representation of the given 64 bit floating point value and converts it into a primitive double value.
static float
parseFloat(String pLexicalXSDFloat)
Parses the lexical representation of the given 32 bit floating point value and converts it into a primitive float value.
static byte[]
parseHexBinary(String pLexicalXSDHexBinary)
Parses the lexical representation of the given byte array, which is encoded in hex digits.
static int
parseInt(String pLexicalXSDInt)
Parses the lexical representation of the given 32 bit integer value and converts it into a primitive int value.
static BigInteger
parseInteger(String pLexicalXSDInteger)
Parses the lexical representation of the given integer value (arbitrary precision) and converts it into an instance of java.math.BigInteger.
static long
parseLong(String pLexicalXSDLong)
Parses the lexical representation of the given 64 bit integer value and converts it into a primitive long value.
static QName
parseQName(String pLexicalXSDQName, NamespaceContext pNamespaceContext)
Parses the lexical representation of the given qualified name and converts it into an instance of QName.
static short
parseShort(String pLexicalXSDShort)
Parses the lexical representation of the given 16 bit integer value and converts it into a primitive short value.
static String
parseString(String pLexicalXSDString)
Parses the lexical representation and converts it into a String.
static Calendar
parseTime(String pLexicalXSDTime)
Parses the lexical representation of the given time value and converts it into an instance of java.util.Calendar.
static long
parseUnsignedInt(String pLexicalXSDUnsignedInt)
Parses the lexical representation of the given 32 bit unsignet integer value and converts it into a primitive long value.
static int
parseUnsignedShort(String pLexicalXSDUnsignedShort)
Parses the lexical representation of the given 16 bit unsignet integer value and converts it into a primitive int value.
static String
printAnySimpleType(String pValue)
Returns a lexical representation of the given input string, which is the unmodified input string.
static String
printBase64Binary(byte[] pValue)
Returns a lexical representation of the given byte array.
static String
printBoolean(boolean pValue)
Returns a lexical representation of the given primitive boolean value.
static String
printByte(byte pValue)
Returns a lexical representation of the given primitive 8 bit integer.
static String
printDate(Calendar pValue)
Returns a lexical representation of the given date value.
static String
printDateTime(Calendar pValue)
Returns a lexical representation of the given dateTime value.
static String
printDecimal(BigDecimal pValue)
Returns a lexical representation of the given instance of BigDecimal, which is a decimal number in arbitrary precision.
static String
printDouble(double pValue)
Returns a lexical representation of the given primitive 64 bit floating point number.
static String
printFloat(float pValue)
Returns a lexical representation of the given primitive 32 bit floating point number.
static String
printHexBinary(byte[] pValue)
Returns a lexical representation of the given byte array.
static String
printInt(int pValue)
Returns a lexical representation of the given primitive 32 bit integer.
static String
printInteger(BigInteger pValue)
Returns a lexical representation of the given instance of BigInteger, which is an integer in arbitrary precision.
static String
printLong(long pValue)
Returns a lexical representation of the given primitive 64 bit integer.
static String
printQName(QName pValue, NamespaceContext pNamespaceContext)
Returns a lexical representation of the given qualified name, which is a combination of namespace URI and local name.
static String
printShort(short pValue)
Returns a lexical representation of the given primitive 16 bit integer.
static String
printString(String pValue)
Returns a lexical representation of the given input string, which is the unmodified input string.
static String
printTime(Calendar pValue)
Returns a lexical representation of the given time value.
static String
printUnsignedInt(long pValue)
Returns a lexical representation of the given primitive, unsigned 32 bit integer.
static String
printUnsignedShort(int pValue)
Returns a lexical representation of the given primitive, unsigned 16 bit integer.
static void
setDatatypeConverter(DatatypeConverterInterface pConverter)
This method must be invoked by the JAXB provider to set the actual instance, which is invoked by the static methods.

Method Details

parseAnySimpleType

public static String parseAnySimpleType(String pLexicalXSDAnySimpleType)
Returns the lexical representation of the input string, which is the unmodified input string.
Parameters:
pLexicalXSDAnySimpleType - An input string in lexical representation.
Returns:
The unmodified input string.

parseBase64Binary

public static byte[] parseBase64Binary(String pLexicalXSDBase64Binary)
Parses the lexical representation of the given byte array, which is encoded in base 64.
Parameters:
pLexicalXSDBase64Binary - The input string being parsed, a base 64 encoded array of bytes.
Returns:
The decoded byte array.

parseBoolean

public static boolean parseBoolean(String pLexicalXSDBoolean)
Parses the lexical representation of the given boolean value and converts it into a primitive boolean value.
Parameters:
pLexicalXSDBoolean - The input string being parsed.
Returns:
The input string converted into a primitive boolean.

parseByte

public static byte parseByte(String pLexicalXSDByte)
Parses the lexical representation of the given 8 bit integer value and converts it into a primitive byte value.
Parameters:
pLexicalXSDByte - The input string being parsed.
Returns:
The input string converted into a primitive byte.

parseDate

public static Calendar parseDate(String pLexicalXSDDate)
Parses the lexical representation of the given date value and converts it into an instance of java.util.Calendar. Valid lexical representations of a date value include
   YYYY-MM-DD
   YYYY-MM-DDZ
   YYYY-MM-DD-01:00
 
The former examples are all specified in UTC time. The last example uses a negatice offset of one hour to UTC.
Parameters:
pLexicalXSDDate - The input string being parsed.
Returns:
The input string converted into an instance of java.util.Calendar.

parseDateTime

public static Calendar parseDateTime(String pLexicalXSDDateTime)
Parses the lexical representation of the given dateTime value and converts it into an instance of java.util.Calendar. Valid lexical representations of a dateTime value include
   YYYY-MM-DDThh:mm:ss
   YYYY-MM-DDThh:mm:ss.sss
   YYYY-MM-DDThh:mm:ssZ
   YYYY-MM-DDThh:mm:ss-01:00
 
The former examples are all specified in UTC time. The last example uses a negatice offset of one hour to UTC.
Parameters:
pLexicalXSDDateTime - The input string being parsed.
Returns:
The input string converted into an instance of java.util.Calendar.

parseDecimal

public static BigDecimal parseDecimal(String pLexicalXSDDecimal)
Parses the lexical representation of the given decimal value (arbitrary precision) and converts it into an instance of java.math.BigDecimal.
Parameters:
pLexicalXSDDecimal - The input string being parsed.
Returns:
The input string converted into an instance of java.math.BigDecimal.

parseDouble

public static double parseDouble(String pLexicalXSDDouble)
Parses the lexical representation of the given 64 bit floating point value and converts it into a primitive double value.
Parameters:
pLexicalXSDDouble - The input string being parsed.
Returns:
The input string converted into a primitive double.

parseFloat

public static float parseFloat(String pLexicalXSDFloat)
Parses the lexical representation of the given 32 bit floating point value and converts it into a primitive float value.
Parameters:
pLexicalXSDFloat - The input string being parsed.
Returns:
The input string converted into a primitive float.

parseHexBinary

public static byte[] parseHexBinary(String pLexicalXSDHexBinary)
Parses the lexical representation of the given byte array, which is encoded in hex digits.
Parameters:
pLexicalXSDHexBinary - The input string being parsed, an array of bytes encoded in hex digits.
Returns:
The decoded byte array.

parseInt

public static int parseInt(String pLexicalXSDInt)
Parses the lexical representation of the given 32 bit integer value and converts it into a primitive int value.
Parameters:
pLexicalXSDInt - The input string being parsed.
Returns:
The input string converted into a primitive int.

parseInteger

public static BigInteger parseInteger(String pLexicalXSDInteger)
Parses the lexical representation of the given integer value (arbitrary precision) and converts it into an instance of java.math.BigInteger.
Parameters:
pLexicalXSDInteger - The input string being parsed.
Returns:
The input string converted into an instance of BigInteger.

parseLong

public static long parseLong(String pLexicalXSDLong)
Parses the lexical representation of the given 64 bit integer value and converts it into a primitive long value.
Parameters:
pLexicalXSDLong - The input string being parsed.
Returns:
The input string converted into a primitive long.

parseQName

public static QName parseQName(String pLexicalXSDQName,
                               NamespaceContext pNamespaceContext)
Parses the lexical representation of the given qualified name and converts it into an instance of QName. The QName consists of a namespace URI and a local name.
Parameters:
pLexicalXSDQName - The input string being parsed, an optional namespace prefix, followed by the local name, if any. If a prefix is present, they are separated by a colon.
pNamespaceContext - The namespace context is used to query mappings between prefixes and namespace URI's.
Returns:
The input string converted into an instance of QName.

parseShort

public static short parseShort(String pLexicalXSDShort)
Parses the lexical representation of the given 16 bit integer value and converts it into a primitive short value.
Parameters:
pLexicalXSDShort - The input string being parsed.
Returns:
The input string converted into a primitive short.

parseString

public static String parseString(String pLexicalXSDString)
Parses the lexical representation and converts it into a String.
Parameters:
pLexicalXSDString - The input string being parsed.
Returns:
The unmodified input string.

parseTime

public static Calendar parseTime(String pLexicalXSDTime)
Parses the lexical representation of the given time value and converts it into an instance of java.util.Calendar. Valid lexical representations of a time value include
   hh:mm:ss
   hh:mm:ss.sss
   hh:mm:ssZ
   hh:mm:ss-01:00
 
The former examples are all specified in UTC time. The last example uses a negatice offset of one hour to UTC.
Parameters:
pLexicalXSDTime - The input string being parsed.
Returns:
The input string converted into an instance of java.util.Calendar.

parseUnsignedInt

public static long parseUnsignedInt(String pLexicalXSDUnsignedInt)
Parses the lexical representation of the given 32 bit unsignet integer value and converts it into a primitive long value.
Parameters:
pLexicalXSDUnsignedInt - The input string being parsed.
Returns:
The input string converted into a primitive long.

parseUnsignedShort

public static int parseUnsignedShort(String pLexicalXSDUnsignedShort)
Parses the lexical representation of the given 16 bit unsignet integer value and converts it into a primitive int value.
Parameters:
pLexicalXSDUnsignedShort - The input string being parsed.
Returns:
The input string conve rted into a primitive int.

printAnySimpleType

public static String printAnySimpleType(String pValue)
Returns a lexical representation of the given input string, which is the unmodified input string.
Parameters:
pValue - The input string.
Returns:
The unmodified input string.

printBase64Binary

public static String printBase64Binary(byte[] pValue)
Returns a lexical representation of the given byte array. The lexical representation is obtained by application of the base 64 encoding.
Parameters:
pValue - The byte array being converted.
Returns:
The converted byte array.

printBoolean

public static String printBoolean(boolean pValue)
Returns a lexical representation of the given primitive boolean value.
Parameters:
pValue - The boolean value being converted.
Returns:
A lexical representation of the input value.

printByte

public static String printByte(byte pValue)
Returns a lexical representation of the given primitive 8 bit integer.
Parameters:
pValue - The byte value being converted.
Returns:
A lexical representation of the input value.

printDate

public static String printDate(Calendar pValue)
Returns a lexical representation of the given date value. Valid lexical representations include:
   YYYY-MM-DD
   YYYY-MM-DDZ
   YYYY-MM-DD-01:00
 
The former examples are all specified in UTC time. The last example uses a negatice offset of one hour to UTC.
Parameters:
pValue - The date value being converted
Returns:
A lexical representation of the input value.

printDateTime

public static String printDateTime(Calendar pValue)
Returns a lexical representation of the given dateTime value. Valid lexical representations include:
   YYYY-MM-DDThh:mm:ss
   YYYY-MM-DDThh:mm:ss.sss
   YYYY-MM-DDThh:mm:ssZ
   YYYY-MM-DDThh:mm:ss-01:00
 
The former examples are all specified in UTC time. The last example uses a negatice offset of one hour to UTC.
Parameters:
pValue - The dateTime value being converted
Returns:
A lexical representation of the input value.

printDecimal

public static String printDecimal(BigDecimal pValue)
Returns a lexical representation of the given instance of BigDecimal, which is a decimal number in arbitrary precision.
Parameters:
pValue - The decimal value being converted.
Returns:
A lexical representation of the input value.

printDouble

public static String printDouble(double pValue)
Returns a lexical representation of the given primitive 64 bit floating point number.
Parameters:
pValue - The double value being converted.
Returns:
A lexical representation of the input value.

printFloat

public static String printFloat(float pValue)
Returns a lexical representation of the given primitive 32 bit floating point number.
Parameters:
pValue - The float value being converted.
Returns:
A lexical representation of the input value.

printHexBinary

public static String printHexBinary(byte[] pValue)
Returns a lexical representation of the given byte array. The lexical representation is obtained by encoding any byte as two hex digits.
Parameters:
pValue - The byte array being converted.
Returns:
The converted byte array.

printInt

public static String printInt(int pValue)
Returns a lexical representation of the given primitive 32 bit integer.
Parameters:
pValue - The int value being converted.
Returns:
A lexical representation of the input value.

printInteger

public static String printInteger(BigInteger pValue)
Returns a lexical representation of the given instance of BigInteger, which is an integer in arbitrary precision.
Parameters:
pValue - The integer value being converted.
Returns:
A lexical representation of the input value.

printLong

public static String printLong(long pValue)
Returns a lexical representation of the given primitive 64 bit integer.
Parameters:
pValue - The long value being converted.
Returns:
A lexical representation of the input value.

printQName

public static String printQName(QName pValue,
                                NamespaceContext pNamespaceContext)
Returns a lexical representation of the given qualified name, which is a combination of namespace URI and local name. The lexical representation is an optional prefix, which is currently mapped to namespace URI of the qualified name, followed by a colon and the local name. If the namespace URI is the current default namespace URI, then the prefix and the colon may be omitted.
Parameters:
pValue - The qualified name being converted.
pNamespaceContext - A mapping of prefixes to namespace URI's which may be used to determine a valid prefix.
Returns:
A lexical representation of the qualified name.

printShort

public static String printShort(short pValue)
Returns a lexical representation of the given primitive 16 bit integer.
Parameters:
pValue - The short value being converted.
Returns:
A lexical representation of the input value.

printString

public static String printString(String pValue)
Returns a lexical representation of the given input string, which is the unmodified input string.
Parameters:
pValue - The input string.
Returns:
The unmodified input string.

printTime

public static String printTime(Calendar pValue)
Returns a lexical representation of the given time value. Valid lexical representations include:
   hh:mm:ss
   hh:mm:ss.sss
   hh:mm:ssZ
   hh:mm:ss-01:00
 
The former examples are all specified in UTC time. The last example uses a negatice offset of one hour to UTC.
Parameters:
pValue - The time value being converted
Returns:
A lexical representation of the input value.

printUnsignedInt

public static String printUnsignedInt(long pValue)
Returns a lexical representation of the given primitive, unsigned 32 bit integer.
Parameters:
pValue - The long value being converted.
Returns:
A lexical representation of the input value.

printUnsignedShort

public static String printUnsignedShort(int pValue)
Returns a lexical representation of the given primitive, unsigned 16 bit integer.
Parameters:
pValue - The short value being converted.
Returns:
A lexical representation of the input value.

setDatatypeConverter

public static void setDatatypeConverter(DatatypeConverterInterface pConverter)
This method must be invoked by the JAXB provider to set the actual instance, which is invoked by the static methods. Subsequent invocations of the method are ignored: First come, first wins.