EclipseLink 2.2.0, build 'v20110202-r8913' API Reference

org.eclipse.persistence.oxm
Class XMLUnionField

java.lang.Object
  extended by org.eclipse.persistence.internal.helper.DatabaseField
      extended by org.eclipse.persistence.oxm.XMLField
          extended by org.eclipse.persistence.oxm.XMLUnionField
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class XMLUnionField
extends XMLField

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
userJavaTypes, userXMLTypes
 
Fields inherited from class org.eclipse.persistence.internal.helper.DatabaseField
columnDefinition, index, isInsertable, isNullable, isUnique, isUpdatable, length, name, NULL_SQL_TYPE, precision, qualifiedName, scale, sqlType, table, type, typeName, useDelimiters
 
Constructor Summary
XMLUnionField()
          Constructs an XMLUnionField
XMLUnionField(java.lang.String xPath)
          Constructs an XMLUnionField with the xpath set to the specified xPath
 
Method Summary
 void addSchemaType(javax.xml.namespace.QName value)
          Adds the new type value to the list of types
 java.lang.Object convertValueBasedOnSchemaType(java.lang.Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, XMLRecord record)
          INTERNAL:
 java.lang.Class getJavaClass(javax.xml.namespace.QName qname)
          Return the class for a given qualified XML Schema type.
 javax.xml.namespace.QName getSchemaType()
          Return the first schema type in the list of schema types
 java.util.ArrayList getSchemaTypes()
          Return the list of schema types
 boolean isSchemaType(javax.xml.namespace.QName schemaType)
          INTERNAL
 boolean isUnionField()
          INTERNAL: returns true since this is a union field
 void setSchemaType(javax.xml.namespace.QName value)
          Adds the new type value to the list of types
 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
 
Methods inherited from class org.eclipse.persistence.oxm.XMLField
addConversion, addJavaConversion, addXMLConversion, buildQNameFromString, equals, getLastXPathFragment, getLeafElementType, getNamespaceResolver, getUserJavaTypesForDeploymentXML, getUserXMLTypesForDeploymentXML, getXMLType, getXPath, getXPathFragment, hashCode, hasLastXPathFragment, initialize, isCDATA, isRequired, isSelfField, isTypedTextField, removeConversion, removeJavaConversion, removeXMLConversion, setIsCDATA, setIsTypedTextField, setLastXPathFragment, setLeafElementType, setName, setName, setNamespaceResolver, setRequired, setUserJavaTypesForDeploymentXML, setUserXMLTypesForDeploymentXML, setUsesSingleNode, setXPath, setXPathFragment, usesSingleNode
 
Methods inherited from class org.eclipse.persistence.internal.helper.DatabaseField
clone, equals, getColumnDefinition, getIndex, getLength, getName, getNameDelimited, getNameForComparisons, getPrecision, getQualifiedName, getQualifiedNameDelimited, getScale, getSqlType, getTable, getTableName, getType, getTypeName, getUseUpperCaseForComparisons, hasTableName, initDDLFields, isInsertable, isNullable, isObjectRelationalDatabaseField, isReadOnly, isUnique, isUpdatable, resetQualifiedName, setColumnDefinition, setIndex, setInsertable, setLength, setName, setNameForComparisons, setNullable, setPrecision, 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
 

Constructor Detail

XMLUnionField

public XMLUnionField()
Constructs an XMLUnionField


XMLUnionField

public XMLUnionField(java.lang.String xPath)
Constructs an XMLUnionField with the xpath set to the specified xPath

Parameters:
xPath - The xpath expression for the field
Method Detail

getSchemaTypes

public java.util.ArrayList getSchemaTypes()
Return the list of schema types

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

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

Overrides:
getSchemaType in class XMLField
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

Overrides:
setSchemaType in class XMLField
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

Overrides:
isUnionField in class XMLField

convertValueBasedOnSchemaType

public java.lang.Object convertValueBasedOnSchemaType(java.lang.Object value,
                                                      org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager,
                                                      XMLRecord record)
INTERNAL:

Overrides:
convertValueBasedOnSchemaType in class XMLField

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:
getJavaClass in class XMLField
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

isSchemaType

public boolean isSchemaType(javax.xml.namespace.QName schemaType)
INTERNAL

Overrides:
isSchemaType in class XMLField

EclipseLink 2.2.0, build 'v20110202-r8913' API Reference