Class XMLUnionField
- java.lang.Object
-
- org.eclipse.persistence.internal.helper.DatabaseField
-
- org.eclipse.persistence.oxm.XMLField
-
- org.eclipse.persistence.oxm.XMLUnionField
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>,org.eclipse.persistence.internal.oxm.mappings.UnionField<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
public class XMLUnionField extends XMLField implements org.eclipse.persistence.internal.oxm.mappings.UnionField<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
Subclass of XMLField for fields that are mapped to unions. Maintains a list of schema types instead of just one single schema type. Schema types can be added using the addSchemaType api. XMLConstants has a list of useful constants including a list of QNames for built-in schema types that can be used when adding schema types.
When reading and writing an element that is mapped with an XMLUnionField, a conversion to each of the schema types on the field (in the order they are specified ) is tried until a conversion is successful. The java type to convert to is based on the list of schema type to java conversion pairs specified on the field. These conversion pairs can be modified using the addXMLConversion api.
Code Sample
In this example the age field could be a date or an int.
XMLUnionField field = new XMLUnionField("age/text()");
field.addSchemaType(XMLConstants.DATE_QNAME);
field.addSchemaType(XMLConstants.INT_QNAME)
- See Also:
XMLField,XMLConstants, Serialized Form
-
-
Field Summary
-
Fields inherited from class org.eclipse.persistence.oxm.XMLField
isTypedTextField, leafElementType, userJavaTypes, userXMLTypes
-
Fields inherited from class org.eclipse.persistence.internal.helper.DatabaseField
columnDefinition, index, isCreatable, isInsertable, isNullable, isPrimaryKey, isTranslated, isUnique, isUpdatable, keepInRow, length, name, nameForComparisons, NULL_SQL_TYPE, precision, qualifiedName, scale, sqlType, table, type, typeName, useDelimiters, useUpperCaseForComparisons
-
-
Constructor Summary
Constructors Constructor Description XMLUnionField()Constructs an XMLUnionFieldXMLUnionField(java.lang.String xPath)Constructs an XMLUnionField with the xpath set to the specified xPath
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSchemaType(javax.xml.namespace.QName value)Adds the new type value to the list of typesjava.lang.ObjectconvertValueBasedOnSchemaType(java.lang.Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord record)INTERNAL:java.lang.ClassgetJavaClass(javax.xml.namespace.QName qname)Return the class for a given qualified XML Schema type.java.lang.ClassgetJavaClass(javax.xml.namespace.QName qname, org.eclipse.persistence.internal.oxm.ConversionManager conversionManager)INTERNALjavax.xml.namespace.QNamegetSchemaType()Return the first schema type in the list of schema typesjavax.xml.namespace.QNamegetSchemaTypeForValue(java.lang.Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)INTERNAL:java.util.ArrayListgetSchemaTypes()Return the list of schema typesprotected javax.xml.namespace.QNamegetSingleValueToWriteForUnion(java.lang.Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)booleanisSchemaType(javax.xml.namespace.QName schemaType)INTERNALbooleanisUnionField()INTERNAL: returns true since this is a union fieldvoidsetSchemaType(javax.xml.namespace.QName value)Adds the new type value to the list of typesvoidsetSchemaTypes(java.util.ArrayList value)Sets the schema types that this attribute can be mapped to Valid QName schema types can be found on org.eclipse.persistence.oxm.XMLConstants-
Methods inherited from class org.eclipse.persistence.oxm.XMLField
addConversion, addJavaConversion, addXMLConversion, equals, getLastXPathFragment, getLeafElementType, getNamespaceResolver, getUserJavaTypesForDeploymentXML, getUserXMLTypesForDeploymentXML, getXMLType, getXMLType, getXPath, getXPathFragment, hashCode, hasLastXPathFragment, initialize, isCDATA, isNestedArray, isRequired, isSelfField, isTypedTextField, removeConversion, removeJavaConversion, removeXMLConversion, setIsCDATA, setIsTypedTextField, setLastXPathFragment, setLeafElementType, setName, setName, setNamespaceResolver, setNestedArray, setRequired, setUserJavaTypesForDeploymentXML, setUserXMLTypesForDeploymentXML, setUsesSingleNode, setXPath, setXPathFragment, usesSingleNode
-
Methods inherited from class org.eclipse.persistence.internal.helper.DatabaseField
clone, convertClassNamesToClasses, equals, getColumnDefinition, getIndex, getLength, getName, getNameDelimited, getNameForComparisons, getPrecision, getQualifiedName, getQualifiedNameDelimited, getScale, getSqlType, getTable, getTableName, getType, getTypeName, getUseUpperCaseForComparisons, hasTableName, initDDLFields, isCreatable, isInsertable, isNullable, isObjectRelationalDatabaseField, isPrimaryKey, isReadOnly, isTranslated, isUnique, isUpdatable, keepInRow, resetQualifiedName, setColumnDefinition, setCreatable, setIndex, setInsertable, setIsTranslated, setKeepInRow, setLength, setName, setNameForComparisons, setNullable, setPrecision, setPrimaryKey, setScale, setSqlType, setTable, setTableName, setType, setTypeName, setUnique, setUpdatable, setUseDelimiters, shouldUseDelimiters, toString, useUpperCaseForComparisons
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.persistence.internal.core.helper.CoreField
setName, setType
-
Methods inherited from interface org.eclipse.persistence.internal.oxm.mappings.Field
getLastXPathFragment, getLeafElementType, getName, getNamespaceResolver, getType, getXMLType, getXPath, getXPathFragment, hasLastXPathFragment, initialize, isCDATA, isNestedArray, isRequired, isSelfField, isTypedTextField, setIsCDATA, setIsTypedTextField, setNamespaceResolver, setNestedArray, setRequired, setUsesSingleNode, setXPath, usesSingleNode
-
-
-
-
Method Detail
-
getSchemaTypes
public java.util.ArrayList getSchemaTypes()
Return the list of schema types- Specified by:
getSchemaTypesin interfaceorg.eclipse.persistence.internal.oxm.mappings.UnionField<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Returns:
- the list of types
-
setSchemaTypes
public void setSchemaTypes(java.util.ArrayList value)
Sets the schema types that this attribute can be mapped to Valid QName schema types can be found on org.eclipse.persistence.oxm.XMLConstants- Parameters:
value- An ArrayList containing the schema types.- See Also:
XMLConstants
-
addSchemaType
public void addSchemaType(javax.xml.namespace.QName value)
Adds the new type value to the list of types- Specified by:
addSchemaTypein interfaceorg.eclipse.persistence.internal.oxm.mappings.UnionField<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Parameters:
value- QName to be added to the list of schema types
-
getSchemaType
public javax.xml.namespace.QName getSchemaType()
Return the first schema type in the list of schema types- Specified by:
getSchemaTypein interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Overrides:
getSchemaTypein classXMLField- Returns:
- the first item in the collection of schema types
-
setSchemaType
public void setSchemaType(javax.xml.namespace.QName value)
Adds the new type value to the list of types- Specified by:
setSchemaTypein interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Overrides:
setSchemaTypein classXMLField- Parameters:
value- The value to be added to the list of schema types
-
isUnionField
public boolean isUnionField()
INTERNAL: returns true since this is a union field- Specified by:
isUnionFieldin interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Overrides:
isUnionFieldin classXMLField
-
getSchemaTypeForValue
public javax.xml.namespace.QName getSchemaTypeForValue(java.lang.Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)Description copied from class:XMLFieldINTERNAL:- Specified by:
getSchemaTypeForValuein interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Overrides:
getSchemaTypeForValuein classXMLField
-
getSingleValueToWriteForUnion
protected javax.xml.namespace.QName getSingleValueToWriteForUnion(java.lang.Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)
-
convertValueBasedOnSchemaType
public java.lang.Object convertValueBasedOnSchemaType(java.lang.Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord record)INTERNAL:- Specified by:
convertValueBasedOnSchemaTypein interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Overrides:
convertValueBasedOnSchemaTypein classXMLField
-
getJavaClass
public java.lang.Class getJavaClass(javax.xml.namespace.QName qname)
Return the class for a given qualified XML Schema type. If the class is a primitive the corresponding wrapper class is returned- Overrides:
getJavaClassin classXMLField- Parameters:
qname- The qualified name of the XML Schema type to use as a key in the lookup- Returns:
- The class associated with the specified schema type, if no corresponding match found returns null
-
getJavaClass
public java.lang.Class getJavaClass(javax.xml.namespace.QName qname, org.eclipse.persistence.internal.oxm.ConversionManager conversionManager)INTERNAL- Specified by:
getJavaClassin interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Overrides:
getJavaClassin classXMLField- Returns:
- the class for a given qualified XML Schema type.
- Since:
- EclipseLink 2.6.0
-
isSchemaType
public boolean isSchemaType(javax.xml.namespace.QName schemaType)
INTERNAL- Specified by:
isSchemaTypein interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>- Overrides:
isSchemaTypein classXMLField
-
-