Module org.eclipse.persistence.core
Class XMLConversionManager
- java.lang.Object
-
- org.eclipse.persistence.internal.core.helper.CoreConversionManager
-
- org.eclipse.persistence.internal.helper.ConversionManager
-
- org.eclipse.persistence.internal.oxm.XMLConversionManager
-
- All Implemented Interfaces:
Serializable,Cloneable,TimeZoneHolder,ConversionManager
public class XMLConversionManager extends ConversionManager implements ConversionManager, TimeZoneHolder
INTERNAL:Purpose: Primarily used to convert objects from a given XML Schema type to a different type in Java. Uses a singleton instance
- Since:
- OracleAS TopLink 10g
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DatatypeFactorydatatypeFactoryprotected static Map<Class<?>,QName>defaultJavaTypesprotected static XMLConversionManagerdefaultXMLManagerprotected static Map<QName,Class<?>>defaultXMLTypesprotected static StringGMT_IDprotected static StringGMT_SUFFIXprotected TimeZonetimeZoneprotected booleantimeZoneQualifiedprotected static intTOTAL_MS_DIGITSprotected static intTOTAL_NS_DIGITS-
Fields inherited from class org.eclipse.persistence.internal.helper.ConversionManager
dataTypesConvertedFromAClass, dataTypesConvertedToAClass, defaultManager, defaultNullValues, loader, shouldUseClassLoaderFromCurrentThread
-
-
Constructor Summary
Constructors Constructor Description XMLConversionManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringbuildBase64StringFromBytes(byte[] bytes)StringbuildBase64StringFromObjectBytes(Byte[] bytes)protected StringbuildHexStringFromObjectBytes(Byte[] bytes)QNamebuildQNameFromString(String stringValue, AbstractUnmarshalRecord record)Objectclone()INTERNAL:StringcollapseStringValue(String value)Removes all leading and trailing whitespaces, and replaces any sequences of whitespaces that occur in the string with a single ' ' character.StringconvertArrayToString(Object[] sourceObject, QName schemaType)ObjectconvertHexBinaryListToByteArrayList(Object sourceObject, CoreContainerPolicy containerPolicy, CoreAbstractSession session)StringconvertListToString(Object sourceObject, QName schemaType)<T> TconvertObject(Object sourceObject, Class<T> javaClass)Convert the given object to the appropriate type by invoking the appropriate ConversionManager method.<T> TconvertObject(Object sourceObject, Class<T> javaClass, QName schemaTypeQName)Convert the given object to the appropriate type by invoking the appropriate ConversionManager method.protected BigDecimalconvertObjectToBigDecimal(Object sourceObject)Build a valid instance of BigDecimal from the given sourceObjectprotected BigIntegerconvertObjectToBigInteger(Object sourceObject)Build a valid instance of BigInteger from the provided sourceObject.protected BooleanconvertObjectToBoolean(Object sourceObject)Build a valid instance of Boolean from the source object.protected ByteconvertObjectToByte(Object sourceObject)Build a valid instance of Byte from the provided sourceObjectprotected CalendarconvertObjectToCalendar(Object sourceObject)INTERNAL: Converts given object to a Calendar objectprotected CharacterconvertObjectToChar(Object sourceObject)Build a valid instance of Character from the provided sourceObject.protected CharacterconvertObjectToChar(Object sourceObject, QName schemaTypeQName)Build a valid instance of Character from the provided sourceObject.protected DateconvertObjectToDate(Object sourceObject)Convert the object to an instance of java.sql.Date.protected DoubleconvertObjectToDouble(Object sourceObject)Convert the object to an instance of Double.protected DurationconvertObjectToDuration(Object sourceObject)Build a valid instance of Duration from the provided sourceObject.protected FloatconvertObjectToFloat(Object sourceObject)Build a valid Float instance from a String or another Number instance.protected IntegerconvertObjectToInteger(Object sourceObject)Build a valid Integer instance from a String or another Number instance.protected LongconvertObjectToLong(Object sourceObject)Build a valid Long instance from a String or another Number instance.protected BigDecimalconvertObjectToNumber(Object sourceObject)INTERNAL: Build a valid BigDecimal instance from a String or another Number instance.protected QNameconvertObjectToQName(Object sourceObject)INTERNAL: Converts given object to a QName objectprotected ShortconvertObjectToShort(Object sourceObject)INTERNAL: Build a valid Short instance from a String or another Number instance.protected DateconvertObjectToSQLDate(Object sourceObject, QName schemaTypeQName)protected TimeconvertObjectToSQLTime(Object sourceObject, QName schemaTypeQName)protected StringconvertObjectToString(Object sourceObject)INTERNAL: Converts objects to their string representations.protected StringconvertObjectToString(Object sourceObject, QName schemaTypeQName)protected TimestampconvertObjectToTimestamp(Object sourceObject, QName schemaTypeQName)protected URIconvertObjectToURI(Object sourceObject)Convert a String to a URI.protected XMLGregorianCalendarconvertObjectToXMLGregorianCalendar(Object sourceObject)Build a valid instance of XMLGregorianCalendar from the provided sourceObject.protected XMLGregorianCalendarconvertObjectToXMLGregorianCalendar(Object sourceObject, QName schemaTypeQName)Build a valid instance of XMLGregorianCalendar from the provided sourceObject.ObjectconvertSchemaBase64ListToByteArrayList(Object sourceObject, CoreContainerPolicy containerPolicy, CoreAbstractSession session)byte[]convertSchemaBase64ToByteArray(Object sourceObject)INTERNAL: Converts a String which is in Base64 format to a Byte[]protected Byte[]convertSchemaBase64ToByteObjectArray(Object sourceObject)CalendarconvertStringToCalendar(String sourceString, QName schemaTypeQName)DateconvertStringToDate(String sourceString, QName schemaType)DurationconvertStringToDuration(String sourceString)Return a Duration created with a given date string.protected FileconvertStringToFile(String path)protected List<String>convertStringToList(Object sourceObject)<T> Collection<T>convertStringToList(Object sourceObject, Class<T> elementType, ContainerPolicy containerPolicy, QName schemaType)Convert the given sourceObject (String) to the appropriate collection type specified by the containerPolicy, using the elementType to properly convert each element of the list.protected TimestampconvertStringToTimestamp(String sourceObject)TimestampconvertStringToTimestamp(String sourceString, QName schemaType)XMLGregorianCalendarconvertStringToXMLGregorianCalendar(String sourceString)Return an XMLGregorianCalander created with a given date stringXMLGregorianCalendarconvertStringToXMLGregorianCalendar(String sourceString, QName schemaTypeQName)protected DatatypeFactorygetDatatypeFactory()INTERNAL: Return the DatatypeFactory instance.static Map<Class<?>,QName>getDefaultJavaTypes()static XMLConversionManagergetDefaultXMLManager()static Map<QName,Class<?>>getDefaultXMLTypes()TimeZonegetTimeZone()Return the specified TimeZone used for all String to date object conversions.booleanisTimeZoneQualified()<T> Class<T>javaType(QName schemaType)StringnormalizeStringValue(String value)Replaces any CR, Tab or LF characters in the string with a single ' ' character.QNameschemaType(Class<?> javaType)voidsetTimeZone(TimeZone timeZone)The specified TimeZone will be used for all String to date object conversions.voidsetTimeZoneQualified(boolean timeZoneQualified)Specify if Specify if when date objects are converted to Strings in the XML Schema time or dateTime formatStringstringFromCalendar(Calendar sourceCalendar, QName schemaTypeQName)StringstringFromDate(Date sourceDate, QName schemaType)This method returns a string representing a given java.util.Date based on a given schema type QName.-
Methods inherited from class org.eclipse.persistence.internal.helper.ConversionManager
buildAllTypesToAClassVec, buildDataTypesConvertedFromAClass, buildDataTypesConvertedToAClass, buildDateTimeVec, buildFromBigDecimalVec, buildFromBigIntegerVec, buildFromBlobVec, buildFromBooleanVec, buildFromByteArrayVec, buildFromByteObjectArraryVec, buildFromByteVec, buildFromCalendarVec, buildFromCharacterArrayVec, buildFromCharacterVec, buildFromCharArrayVec, buildFromClobVec, buildFromDateVec, buildFromDoubleVec, buildFromFloatVec, buildFromIntegerVec, buildFromLongVec, buildFromNumberVec, buildFromShortVec, buildFromStringVec, buildFromTimestampVec, buildFromTimeVec, buildFromUtilDateVec, buildNumberVec, buildToBigDecimalVec, buildToBigIntegerVec, buildToBlobVec, buildToBooleanVec, buildToByteArrayVec, buildToByteObjectArrayVec, buildToByteVec, buildToCalendarVec, buildToCharacterArrayVec, buildToCharacterVec, buildToCharArrayVec, buildToClobVec, buildToDateVec, buildToDoubleVec, buildToFloatVec, buildToIntegerVec, buildToLongVec, buildToNumberVec, buildToShortVec, buildToStringVec, buildToTimestampVec, buildToTimeVec, buildToUtilDateVec, convertClassNameToClass, convertObjectToByteArray, convertObjectToByteObjectArray, convertObjectToCharacterArray, convertObjectToCharArray, convertObjectToClass, convertObjectToLocalDate, convertObjectToLocalDateTime, convertObjectToLocalTime, convertObjectToOffsetDateTime, convertObjectToOffsetTime, convertObjectToTime, convertObjectToTimestamp, convertObjectToUrl, convertObjectToUtilDate, convertObjectToUUID, getDataTypesConvertedFrom, getDataTypesConvertedTo, getDefaultLoader, getDefaultManager, getDefaultNullValue, getDefaultNullValues, getLoader, getObjectClass, getPrimitiveClass, hasDefaultNullValues, loadClass, setDefaultLoader, setDefaultManager, setDefaultNullValue, setDefaultNullValues, setLoader, setShouldUseClassLoaderFromCurrentThread, shouldUseClassLoaderFromCurrentThread
-
-
-
-
Field Detail
-
GMT_ID
protected static final String GMT_ID
- See Also:
- Constant Field Values
-
GMT_SUFFIX
protected static final String GMT_SUFFIX
- See Also:
- Constant Field Values
-
defaultXMLManager
protected static XMLConversionManager defaultXMLManager
-
timeZoneQualified
protected boolean timeZoneQualified
-
timeZone
protected TimeZone timeZone
-
TOTAL_MS_DIGITS
protected static final int TOTAL_MS_DIGITS
- See Also:
- Constant Field Values
-
TOTAL_NS_DIGITS
protected static final int TOTAL_NS_DIGITS
- See Also:
- Constant Field Values
-
datatypeFactory
protected DatatypeFactory datatypeFactory
-
-
Method Detail
-
getDatatypeFactory
protected DatatypeFactory getDatatypeFactory()
INTERNAL: Return the DatatypeFactory instance.
-
getDefaultXMLManager
public static XMLConversionManager getDefaultXMLManager()
-
getTimeZone
public TimeZone getTimeZone()
Return the specified TimeZone used for all String to date object conversions.- Specified by:
getTimeZonein interfaceTimeZoneHolder
-
setTimeZone
public void setTimeZone(TimeZone timeZone)
The specified TimeZone will be used for all String to date object conversions. By default the TimeZone from the JVM is used.
-
isTimeZoneQualified
public boolean isTimeZoneQualified()
-
setTimeZoneQualified
public void setTimeZoneQualified(boolean timeZoneQualified)
Specify if Specify if when date objects are converted to Strings in the XML Schema time or dateTime format
-
convertObject
public <T> T convertObject(Object sourceObject, Class<T> javaClass) throws ConversionException
Convert the given object to the appropriate type by invoking the appropriate ConversionManager method.- Overrides:
convertObjectin classConversionManager- Parameters:
sourceObject- - will always be a string if read from XMLjavaClass- - the class that the object must be converted to- Returns:
- - the newly converted object
- Throws:
ConversionException- all exceptions will be thrown as this type.
-
convertObject
public <T> T convertObject(Object sourceObject, Class<T> javaClass, QName schemaTypeQName) throws ConversionException
Convert the given object to the appropriate type by invoking the appropriate ConversionManager method.- Specified by:
convertObjectin interfaceConversionManager- Parameters:
sourceObject- - will always be a string if read from XMLjavaClass- - the class that the object must be converted toschemaTypeQName- - the XML schema that the object is being converted from- Returns:
- - the newly converted object
- Throws:
ConversionException
-
convertObjectToXMLGregorianCalendar
protected XMLGregorianCalendar convertObjectToXMLGregorianCalendar(Object sourceObject, QName schemaTypeQName) throws ConversionException
Build a valid instance of XMLGregorianCalendar from the provided sourceObject.- Throws:
ConversionException
-
convertObjectToXMLGregorianCalendar
protected XMLGregorianCalendar convertObjectToXMLGregorianCalendar(Object sourceObject) throws ConversionException
Build a valid instance of XMLGregorianCalendar from the provided sourceObject.- Throws:
ConversionException
-
convertObjectToDuration
protected Duration convertObjectToDuration(Object sourceObject) throws ConversionException
Build a valid instance of Duration from the provided sourceObject.- Throws:
ConversionException
-
convertObjectToChar
protected Character convertObjectToChar(Object sourceObject, QName schemaTypeQName) throws ConversionException
Build a valid instance of Character from the provided sourceObject.- Throws:
ConversionException
-
convertObjectToChar
protected Character convertObjectToChar(Object sourceObject) throws ConversionException
Build a valid instance of Character from the provided sourceObject.- Overrides:
convertObjectToCharin classConversionManager- Parameters:
sourceObject- Valid instance of String or any Number- Throws:
ConversionException
-
convertObjectToURI
protected URI convertObjectToURI(Object sourceObject) throws ConversionException
Convert a String to a URI.- Throws:
ConversionException
-
convertObjectToQName
protected QName convertObjectToQName(Object sourceObject) throws ConversionException
INTERNAL: Converts given object to a QName object- Throws:
ConversionException
-
convertObjectToCalendar
protected Calendar convertObjectToCalendar(Object sourceObject) throws ConversionException
INTERNAL: Converts given object to a Calendar object- Overrides:
convertObjectToCalendarin classConversionManager- Parameters:
sourceObject- Valid instance of java.util.Date, String, java.sql.Timestamp, or Long- Throws:
ConversionException
-
convertObjectToString
protected String convertObjectToString(Object sourceObject) throws ConversionException
INTERNAL: Converts objects to their string representations.- Overrides:
convertObjectToStringin classConversionManager- Throws:
ConversionException
-
convertObjectToString
protected String convertObjectToString(Object sourceObject, QName schemaTypeQName) throws ConversionException
- Throws:
ConversionException
-
convertObjectToDate
protected Date convertObjectToDate(Object sourceObject) throws ConversionException
Description copied from class:ConversionManagerConvert the object to an instance of java.sql.Date.- Overrides:
convertObjectToDatein classConversionManager- Parameters:
sourceObject- Object of type java.sql.Timestamp, java.util.Date, String or Long- Throws:
ConversionException
-
convertObjectToDouble
protected Double convertObjectToDouble(Object sourceObject) throws ConversionException
Convert the object to an instance of Double.- Overrides:
convertObjectToDoublein classConversionManager- Parameters:
sourceObject- Object of type String or Number.- Throws:
ConversionException- The Double(String) constructor throws a NumberFormatException if the String does not contain a parsable double.
-
convertObjectToFloat
protected Float convertObjectToFloat(Object sourceObject) throws ConversionException
Build a valid Float instance from a String or another Number instance.- Overrides:
convertObjectToFloatin classConversionManager- Throws:
ConversionException- The Float(String) constructor throws a NumberFormatException if the String does not contain a parsable Float.
-
convertObjectToInteger
protected Integer convertObjectToInteger(Object sourceObject) throws ConversionException
Build a valid Integer instance from a String or another Number instance.- Overrides:
convertObjectToIntegerin classConversionManager- Throws:
ConversionException- The Integer(String) constructor throws a NumberFormatException if the String does not contain a parsable integer.
-
convertObjectToLong
protected Long convertObjectToLong(Object sourceObject) throws ConversionException
Build a valid Long instance from a String or another Number instance.- Overrides:
convertObjectToLongin classConversionManager- Throws:
ConversionException- The Long(String) constructor throws a NumberFormatException if the String does not contain a parsable long.
-
convertObjectToShort
protected Short convertObjectToShort(Object sourceObject) throws ConversionException
INTERNAL: Build a valid Short instance from a String or another Number instance.- Overrides:
convertObjectToShortin classConversionManager- Throws:
ConversionException- The Short(String) constructor throws a NumberFormatException if the String does not contain a parsable short.
-
convertObjectToNumber
protected BigDecimal convertObjectToNumber(Object sourceObject) throws ConversionException
INTERNAL: Build a valid BigDecimal instance from a String or another Number instance. BigDecimal is the most general type so is must be returned when an object is converted to a number.- Overrides:
convertObjectToNumberin classConversionManager- Throws:
ConversionException- The BigDecimal(String) constructor throws a NumberFormatException if the String does not contain a parsable BigDecimal.
-
convertObjectToBigInteger
protected BigInteger convertObjectToBigInteger(Object sourceObject) throws ConversionException
Build a valid instance of BigInteger from the provided sourceObject.- Overrides:
convertObjectToBigIntegerin classConversionManager- Parameters:
sourceObject- Valid instance of String, BigDecimal, or any Number- Throws:
ConversionException
-
convertObjectToBigDecimal
protected BigDecimal convertObjectToBigDecimal(Object sourceObject) throws ConversionException
Build a valid instance of BigDecimal from the given sourceObject- Overrides:
convertObjectToBigDecimalin classConversionManager- Parameters:
sourceObject- Valid instance of String, BigInteger, any Number- Throws:
ConversionException
-
convertObjectToBoolean
protected Boolean convertObjectToBoolean(Object sourceObject)
Description copied from class:ConversionManagerBuild a valid instance of Boolean from the source object. 't', 'T', "true", "TRUE", 1,'1' -> Boolean(true) 'f', 'F', "false", "FALSE", 0 ,'0' -> Boolean(false)- Overrides:
convertObjectToBooleanin classConversionManager
-
convertObjectToByte
protected Byte convertObjectToByte(Object sourceObject) throws ConversionException
Build a valid instance of Byte from the provided sourceObject- Overrides:
convertObjectToBytein classConversionManager- Parameters:
sourceObject- Valid instance of String or any Number- Throws:
ConversionException- The Byte(String) constructor throws a NumberFormatException if the String does not contain a parsable byte.
-
convertStringToXMLGregorianCalendar
public XMLGregorianCalendar convertStringToXMLGregorianCalendar(String sourceString, QName schemaTypeQName)
-
convertStringToXMLGregorianCalendar
public XMLGregorianCalendar convertStringToXMLGregorianCalendar(String sourceString)
Return an XMLGregorianCalander created with a given date string
-
convertStringToDuration
public Duration convertStringToDuration(String sourceString)
Return a Duration created with a given date string.
-
convertStringToCalendar
public Calendar convertStringToCalendar(String sourceString, QName schemaTypeQName)
-
convertObjectToSQLDate
protected Date convertObjectToSQLDate(Object sourceObject, QName schemaTypeQName)
-
convertObjectToSQLTime
protected Time convertObjectToSQLTime(Object sourceObject, QName schemaTypeQName)
-
convertObjectToTimestamp
protected Timestamp convertObjectToTimestamp(Object sourceObject, QName schemaTypeQName)
-
convertStringToTimestamp
public Timestamp convertStringToTimestamp(String sourceString, QName schemaType)
-
stringFromCalendar
public String stringFromCalendar(Calendar sourceCalendar, QName schemaTypeQName)
-
stringFromDate
public String stringFromDate(Date sourceDate, QName schemaType)
This method returns a string representing a given java.util.Date based on a given schema type QName. BC dates (sourceDate.getTime() < YEAR_ONE_AD_TIME) are handled as follows: '2007 BC' --> '-2006 AD'.
-
convertSchemaBase64ToByteArray
public byte[] convertSchemaBase64ToByteArray(Object sourceObject) throws ConversionException
INTERNAL: Converts a String which is in Base64 format to a Byte[]- Specified by:
convertSchemaBase64ToByteArrayin interfaceConversionManager- Throws:
ConversionException
-
convertSchemaBase64ListToByteArrayList
public Object convertSchemaBase64ListToByteArrayList(Object sourceObject, CoreContainerPolicy containerPolicy, CoreAbstractSession session) throws ConversionException
- Specified by:
convertSchemaBase64ListToByteArrayListin interfaceConversionManager- Throws:
ConversionException
-
convertSchemaBase64ToByteObjectArray
protected Byte[] convertSchemaBase64ToByteObjectArray(Object sourceObject) throws ConversionException
- Throws:
ConversionException
-
buildBase64StringFromBytes
public String buildBase64StringFromBytes(byte[] bytes)
- Specified by:
buildBase64StringFromBytesin interfaceConversionManager
-
convertStringToList
protected List<String> convertStringToList(Object sourceObject) throws ConversionException
- Throws:
ConversionException
-
convertStringToList
public <T> Collection<T> convertStringToList(Object sourceObject, Class<T> elementType, ContainerPolicy containerPolicy, QName schemaType) throws ConversionException
Convert the given sourceObject (String) to the appropriate collection type specified by the containerPolicy, using the elementType to properly convert each element of the list.- Parameters:
sourceObject- - will always be a string if read from XMLelementType- - the type of the elements contained in the list- Returns:
- - the newly converted object
- Throws:
ConversionException
-
convertListToString
public String convertListToString(Object sourceObject, QName schemaType) throws ConversionException
- Throws:
ConversionException
-
convertArrayToString
public String convertArrayToString(Object[] sourceObject, QName schemaType) throws ConversionException
- Throws:
ConversionException
-
clone
public Object clone()
INTERNAL:- Overrides:
clonein classConversionManager
-
buildQNameFromString
public QName buildQNameFromString(String stringValue, AbstractUnmarshalRecord record)
- Specified by:
buildQNameFromStringin interfaceConversionManager
-
normalizeStringValue
public String normalizeStringValue(String value)
Replaces any CR, Tab or LF characters in the string with a single ' ' character.- Specified by:
normalizeStringValuein interfaceConversionManager
-
collapseStringValue
public String collapseStringValue(String value)
Removes all leading and trailing whitespaces, and replaces any sequences of whitespaces that occur in the string with a single ' ' character.- Specified by:
collapseStringValuein interfaceConversionManager
-
javaType
public <T> Class<T> javaType(QName schemaType)
- Specified by:
javaTypein interfaceConversionManager- Parameters:
schemaType- The type you want to find a corresponding Java class for.- Returns:
- the Java class for the XML schema type.
- Since:
- EclipseLink 2.6.0
-
schemaType
public QName schemaType(Class<?> javaType)
- Specified by:
schemaTypein interfaceConversionManager- Parameters:
javaType- The type you want to find a corresponding schema type for.- Returns:
- the schema type for the Java class.
- Since:
- EclipseLink 2.6.0
-
convertHexBinaryListToByteArrayList
public Object convertHexBinaryListToByteArrayList(Object sourceObject, CoreContainerPolicy containerPolicy, CoreAbstractSession session)
- Specified by:
convertHexBinaryListToByteArrayListin interfaceConversionManager
-
-