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)
XMLField,
XMLConstants,
Serialized FormisTypedTextField, leafElementType, userJavaTypes, userXMLTypescolumnDefinition, 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 and Description |
|---|
XMLUnionField()
Constructs an XMLUnionField
|
XMLUnionField(String xPath)
Constructs an XMLUnionField with the xpath set to the specified xPath
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSchemaType(QName value)
Adds the new type value to the list of types
|
Object |
convertValueBasedOnSchemaType(Object value,
org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager,
org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord record)
INTERNAL:
|
Class |
getJavaClass(QName qname)
Return the class for a given qualified XML Schema type.
|
Class |
getJavaClass(QName qname,
org.eclipse.persistence.internal.oxm.ConversionManager conversionManager)
INTERNAL
|
QName |
getSchemaType()
Return the first schema type in the list of schema types
|
QName |
getSchemaTypeForValue(Object value,
org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)
INTERNAL:
|
ArrayList |
getSchemaTypes()
Return the list of schema types
|
protected QName |
getSingleValueToWriteForUnion(Object value,
org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session) |
boolean |
isSchemaType(QName schemaType)
INTERNAL
|
boolean |
isUnionField()
INTERNAL:
returns true since this is a union field
|
void |
setSchemaType(QName value)
Adds the new type value to the list of types
|
void |
setSchemaTypes(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
|
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, usesSingleNodeclone, 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, useUpperCaseForComparisonsfinalize, getClass, notify, notifyAll, wait, wait, waitgetLastXPathFragment, getLeafElementType, getName, getNamespaceResolver, getType, getXMLType, getXPath, getXPathFragment, hasLastXPathFragment, initialize, isCDATA, isNestedArray, isRequired, isSelfField, isTypedTextField, setIsCDATA, setIsTypedTextField, setNamespaceResolver, setNestedArray, setRequired, setUsesSingleNode, setXPath, usesSingleNodepublic XMLUnionField()
public XMLUnionField(String xPath)
xPath - The xpath expression for the fieldpublic ArrayList getSchemaTypes()
getSchemaTypes in interface org.eclipse.persistence.internal.oxm.mappings.UnionField<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>public void setSchemaTypes(ArrayList value)
value - An ArrayList containing the schema types.XMLConstantspublic void addSchemaType(QName value)
addSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.UnionField<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>value - QName to be added to the list of schema typespublic QName getSchemaType()
getSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>getSchemaType in class XMLFieldpublic void setSchemaType(QName value)
setSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>setSchemaType in class XMLFieldvalue - The value to be added to the list of schema typespublic boolean isUnionField()
isUnionField in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>isUnionField in class XMLFieldpublic QName getSchemaTypeForValue(Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)
XMLFieldgetSchemaTypeForValue in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>getSchemaTypeForValue in class XMLFieldprotected QName getSingleValueToWriteForUnion(Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)
public Object convertValueBasedOnSchemaType(Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord record)
convertValueBasedOnSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>convertValueBasedOnSchemaType in class XMLFieldpublic Class getJavaClass(QName qname)
getJavaClass in class XMLFieldqname - The qualified name of the XML Schema type to use as a key in the lookuppublic Class getJavaClass(QName qname, org.eclipse.persistence.internal.oxm.ConversionManager conversionManager)
getJavaClass in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>getJavaClass in class XMLFieldqname - The qualified name of the XML Schema type to use as a key in the lookuppublic boolean isSchemaType(QName schemaType)
isSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>isSchemaType in class XMLFieldCopyright © 2007–2021 Eclipse.org - EclipseLink Project. All rights reserved.