Class XMLUnionField

java.lang.Object
org.eclipse.persistence.internal.helper.DatabaseField
org.eclipse.persistence.oxm.XMLField
org.eclipse.persistence.oxm.XMLUnionField
All Implemented Interfaces:
Serializable, 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:
  • Constructor Details

    • XMLUnionField

      public XMLUnionField()
      Constructs an XMLUnionField
    • XMLUnionField

      public XMLUnionField(String xPath)
      Constructs an XMLUnionField with the xpath set to the specified xPath
      Parameters:
      xPath - The xpath expression for the field
  • Method Details

    • getSchemaTypes

      public ArrayList getSchemaTypes()
      Return the list of schema types
      Specified by:
      getSchemaTypes in interface org.eclipse.persistence.internal.oxm.mappings.UnionField<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
      Returns:
      the list of types
    • setSchemaTypes

      public 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
      Parameters:
      value - An ArrayList containing the schema types.
      See Also:
    • addSchemaType

      public void addSchemaType(QName value)
      Adds the new type value to the list of types
      Specified by:
      addSchemaType in interface org.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 QName getSchemaType()
      Return the first schema type in the list of schema types
      Specified by:
      getSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
      Overrides:
      getSchemaType in class XMLField
      Returns:
      the first item in the collection of schema types
    • setSchemaType

      public void setSchemaType(QName value)
      Adds the new type value to the list of types
      Specified by:
      setSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
      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
      Specified by:
      isUnionField in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
      Overrides:
      isUnionField in class XMLField
    • getSchemaTypeForValue

      public QName getSchemaTypeForValue(Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)
      Description copied from class: XMLField
      INTERNAL:
      Specified by:
      getSchemaTypeForValue in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
      Overrides:
      getSchemaTypeForValue in class XMLField
    • getSingleValueToWriteForUnion

      protected QName getSingleValueToWriteForUnion(Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session)
    • convertValueBasedOnSchemaType

      public Object convertValueBasedOnSchemaType(Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord record)
      INTERNAL:
      Specified by:
      convertValueBasedOnSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
      Overrides:
      convertValueBasedOnSchemaType in class XMLField
    • getJavaClass

      public Class getJavaClass(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
    • getJavaClass

      public Class getJavaClass(QName qname, org.eclipse.persistence.internal.oxm.ConversionManager conversionManager)
      INTERNAL
      Specified by:
      getJavaClass in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
      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 for a given qualified XML Schema type.
    • isSchemaType

      public boolean isSchemaType(QName schemaType)
      INTERNAL
      Specified by:
      isSchemaType in interface org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,NamespaceResolver>
      Overrides:
      isSchemaType in class XMLField