Class XMLCompositeObjectMapping

java.lang.Object
org.eclipse.persistence.core.mappings.CoreMapping<AttributeAccessor,org.eclipse.persistence.internal.sessions.AbstractSession,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField>
All Implemented Interfaces:
Serializable, Cloneable, org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>, org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLRecord>, org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping<XMLMarshaller,Session,XMLUnmarshaller>, XMLMapping, XMLNillableMapping
Direct Known Subclasses:
XMLVariableXPathObjectMapping

public class XMLCompositeObjectMapping extends AbstractCompositeObjectMapping implements XMLMapping, org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>, XMLNillableMapping

Composite object XML mappings represent a relationship between two classes. In XML, the "owned" class may be nested with the element tag representing the "owning" class. This mapping is, by definition, privately owned.

Composite object XML mappings can be used in the following scenarios:

  • Mapping into the Parent Record
  • Mapping to an Element
  • Mapping to Different Elements by Element Name
  • Mapping to Different Elements by Element Position

Setting the XPath: TopLink XML mappings make use of XPath statements to find the relevant data in an XML document. The XPath statement is relative to the context node specified in the descriptor. The XPath may contain path and positional information; the last node in the XPath forms the local root node for the composite object. The XPath is specified on the mapping using the setXPath method.

The following XPath statements may be used to specify the location of XML data relating to an object's name attribute:

XPath statements
XPath Description
. Indicates "self".
phone-number The phone-number information is stored in the phone-number element.
contact-info/phone-number The XPath statement may be used to specify any valid path.
phone-number[2] The XPath statement may contain positional information. In this case the phone-number information is stored in the second occurrence of the phone-number element.

Mapping into the Parent Record: The composite object may be mapped into the parent record in a corresponding XML document.

XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="customer" type="customer-type"/>
  <xsd:complexType name="customer-type">
    <xsd:sequence>
      <xsd:element name="first-name" type="xsd:string"/>
      <xsd:element name="last-name" type="xsd:string"/>
      <xsd:element name="street" type="xsd:string"/>
      <xsd:element name="city" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

Code Sample
XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
addressMapping.setAttributeName("address");
addressMapping.setXPath(".");
addressMapping.setReferenceClass(Address.class);

Mapping to an Element: The composite object may be mapped to an element in a corresponding XML document.

XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="customer" type="customer-type"/>
  <xsd:complexType name="customer-type">
    <xsd:sequence>
      <xsd:element name="first-name" type="xsd:string"/>
      <xsd:element name="last-name" type="xsd:string"/>
      <xsd:element name="address">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="street" type="xsd:string"/>
            <xsd:element name="city" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

Code Sample
XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
addressMapping.setAttributeName("address");
addressMapping.setXPath("address");
addressMapping.setReferenceClass(Address.class);

More Information: For more information about using the XML Composite Object Mapping, see the "Understanding XML Mappings" chapter of the Oracle TopLink Developer's Guide.

See Also:
  • Constructor Details

    • XMLCompositeObjectMapping

      public XMLCompositeObjectMapping()
  • Method Details

    • getContainerAccessor

      @Deprecated public AttributeAccessor getContainerAccessor()
      Deprecated.
      Replaced by getInverseReferenceMapping().getAttributeAccessor()
      Gets the AttributeAccessor that is used to get and set the value of the container on the target object.
    • setContainerAccessor

      @Deprecated public void setContainerAccessor(AttributeAccessor anAttributeAccessor)
      Deprecated.
      Replaced by getInverseReferenceMapping().setAttributeAccessor()
      Sets the AttributeAccessor that is used to get and set the value of the container on the target object.
      Parameters:
      anAttributeAccessor - - the accessor to be used.
    • setContainerAttributeName

      @Deprecated public void setContainerAttributeName(String attributeName)
      Deprecated.
      Replaced by getInverseReferenceMapping().setAttributeName()
      Sets the name of the backpointer attribute on the target object. Used to populate the backpointer. If the specified attribute doesn't exist on the reference class of this mapping, a DescriptorException will be thrown during initialize.
      Parameters:
      attributeName - - the name of the backpointer attribute to be populated
    • getContainerAttributeName

      @Deprecated public String getContainerAttributeName()
      Deprecated.
      Replaced by getInverseReferenceMapping().getAttributeName()
      Gets the name of the backpointer attribute on the target object. Used to populate the backpointer.
    • setContainerGetMethodName

      @Deprecated public void setContainerGetMethodName(String methodName)
      Deprecated.
      Replaced by getInverseReferenceMapping().setGetMethodName()
      Sets the method name to be used when accessing the value of the back pointer on the target object of this mapping. If the specified method doesn't exist on the reference class of this mapping, a DescriptorException will be thrown during initialize.
      Parameters:
      methodName - - the getter method to be used.
    • setContainerSetMethodName

      @Deprecated public void setContainerSetMethodName(String methodName)
      Deprecated.
      Replaced by getInverseReferenceMapping().setSetMethodName()
      Sets the name of the method to be used when setting the value of the back pointer on the target object of this mapping. If the specified method doesn't exist on the reference class of this mapping, a DescriptorException will be thrown during initialize.
      Parameters:
      methodName - - the setter method to be used.
    • getContainerGetMethodName

      @Deprecated public String getContainerGetMethodName()
      Deprecated.
      Replaced by getInverseReferenceMapping().getGetMethodName()
      Gets the name of the method to be used when accessing the value of the back pointer on the target object of this mapping.
    • getContainerSetMethodName

      @Deprecated public String getContainerSetMethodName()
      Deprecated.
      Replaced by getInverseReferenceMapping().getSetMethodName()
      Gets the name of the method to be used when setting the value of the back pointer on the target object of this mapping.
    • convertClassNamesToClasses

      public void convertClassNamesToClasses(ClassLoader classLoader)
      Description copied from class: AggregateMapping
      INTERNAL: Convert all the class-name-based settings in this mapping to actual class-based settings. This method is used when converting a project that has been built with class names to a project with classes.
      Specified by:
      convertClassNamesToClasses in interface org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLRecord>
      Specified by:
      convertClassNamesToClasses in interface XMLMapping
      Overrides:
      convertClassNamesToClasses in class AggregateMapping
    • initialize

      public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session) throws DescriptorException
      INTERNAL: The mapping is initialized with the given session. This mapping is fully initialized after this.
      Overrides:
      initialize in class AbstractCompositeObjectMapping
      Throws:
      DescriptorException
    • initializeReferenceDescriptorAndField

      protected void initializeReferenceDescriptorAndField(org.eclipse.persistence.internal.sessions.AbstractSession session)
    • setNullPolicy

      public void setNullPolicy(AbstractNullPolicy aNullPolicy)
      Set the AbstractNullPolicy on the mapping
      The default policy is NullPolicy.
      Specified by:
      setNullPolicy in interface org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>
      Specified by:
      setNullPolicy in interface XMLNillableMapping
      Parameters:
      aNullPolicy -
    • getNullPolicy

      public AbstractNullPolicy getNullPolicy()
      INTERNAL: Get the AbstractNullPolicy from the Mapping.
      The default policy is NullPolicy.
      Specified by:
      getNullPolicy in interface org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>
      Specified by:
      getNullPolicy in interface XMLNillableMapping
      Returns:
    • isXMLMapping

      public boolean isXMLMapping()
      INTERNAL:
      Overrides:
      isXMLMapping in class DatabaseMapping
    • getXPath

      public String getXPath()
      Get the XPath String
      Returns:
      String the XPath String associated with this Mapping
    • setXPath

      public void setXPath(String xpathString)
      Set the Mapping field name attribute to the given XPath String
      Specified by:
      setXPath in interface org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>
      Parameters:
      xpathString - String
    • buildCompositeRow

      protected Object buildCompositeRow(Object attributeValue, org.eclipse.persistence.internal.sessions.AbstractSession session, org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, DatabaseMapping.WriteType writeType)
      Specified by:
      buildCompositeRow in class AbstractCompositeObjectMapping
    • buildCompositeRowForDescriptor

      protected org.eclipse.persistence.internal.sessions.AbstractRecord buildCompositeRowForDescriptor(ClassDescriptor classDesc, Object attributeValue, org.eclipse.persistence.internal.sessions.AbstractSession session, XMLRecord parentRow, DatabaseMapping.WriteType writeType)
    • buildCompositeObject

      protected Object buildCompositeObject(org.eclipse.persistence.internal.descriptors.ObjectBuilder objectBuilder, org.eclipse.persistence.internal.sessions.AbstractRecord nestedRow, ObjectBuildingQuery query, org.eclipse.persistence.internal.identitymaps.CacheKey parentCacheKey, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
      Specified by:
      buildCompositeObject in class AbstractCompositeObjectMapping
    • readFromRowIntoObject

      public Object readFromRowIntoObject(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, Object targetObject, org.eclipse.persistence.internal.identitymaps.CacheKey parentCacheKey, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.sessions.AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException
      Description copied from class: DatabaseMapping
      INTERNAL: Extract value from the row and set the attribute to this value in the object. return value as this value will have been converted to the appropriate type for the object.
      Overrides:
      readFromRowIntoObject in class DatabaseMapping
      Throws:
      DatabaseException
    • valueFromRow

      public Object valueFromRow(Object fieldValue, XMLRecord nestedRow, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.sessions.AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException
      Throws:
      DatabaseException
    • valueFromRow

      public Object valueFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.identitymaps.CacheKey cacheKey, org.eclipse.persistence.internal.sessions.AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException
      Description copied from class: AbstractCompositeObjectMapping
      INTERNAL: Extract and return the aggregate object from the specified row.
      Overrides:
      valueFromRow in class AbstractCompositeObjectMapping
      Throws:
      DatabaseException
    • writeFromObjectIntoRow

      public void writeFromObjectIntoRow(Object object, org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, org.eclipse.persistence.internal.sessions.AbstractSession session, DatabaseMapping.WriteType writeType) throws DescriptorException
      INTERNAL:
      Overrides:
      writeFromObjectIntoRow in class AbstractCompositeObjectMapping
      Throws:
      DescriptorException
    • writeSingleValue

      public void writeSingleValue(Object value, Object parent, XMLRecord record, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Description copied from interface: XMLMapping
      INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath. Used for Sequenced marshalling.
      Specified by:
      writeSingleValue in interface org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLRecord>
      Specified by:
      writeSingleValue in interface XMLMapping
      Parameters:
      value - - The value to be marshalled
      record - - The Record the value is being marshalled too.
    • configureNestedRow

      public void configureNestedRow(org.eclipse.persistence.internal.sessions.AbstractRecord parent, org.eclipse.persistence.internal.sessions.AbstractRecord child)
    • getReferenceDescriptor

      public ClassDescriptor getReferenceDescriptor(DOMRecord xmlRecord)
    • getReferenceDescriptor

      protected ClassDescriptor getReferenceDescriptor(Class theClass, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Description copied from class: AggregateMapping
      INTERNAL: For inheritance purposes.
      Overrides:
      getReferenceDescriptor in class AggregateMapping
    • getKeepAsElementPolicy

      public UnmarshalKeepAsElementPolicy getKeepAsElementPolicy()
      Specified by:
      getKeepAsElementPolicy in interface org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>
    • setKeepAsElementPolicy

      public void setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy keepAsElementPolicy)
      Specified by:
      setKeepAsElementPolicy in interface org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>
    • getDescriptor

      protected XMLDescriptor getDescriptor(XMLRecord xmlRecord, org.eclipse.persistence.internal.sessions.AbstractSession session, QName rootQName) throws XMLMarshalException
      Throws:
      XMLMarshalException
    • setIsWriteOnly

      public void setIsWriteOnly(boolean b)
      Specified by:
      setIsWriteOnly in interface org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>
      Specified by:
      setIsWriteOnly in interface XMLMapping
    • isWriteOnly

      public boolean isWriteOnly()
      Description copied from class: DatabaseMapping
      INTERNAL: Some mappings support no attribute (transformation and multitenant primary key).
      Specified by:
      isWriteOnly in interface XMLMapping
      Overrides:
      isWriteOnly in class DatabaseMapping
    • preInitialize

      public void preInitialize(org.eclipse.persistence.internal.sessions.AbstractSession session) throws DescriptorException
      Description copied from class: DatabaseMapping
      INTERNAL: Allow for initialization of properties and validation.
      Overrides:
      preInitialize in class DatabaseMapping
      Throws:
      DescriptorException
    • setAttributeValueInObject

      public void setAttributeValueInObject(Object object, Object value) throws DescriptorException
      Description copied from class: AbstractCompositeObjectMapping
      INTERNAL: Set the value of the attribute mapped by this mapping.
      Specified by:
      setAttributeValueInObject in interface org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLRecord>
      Overrides:
      setAttributeValueInObject in class AbstractCompositeObjectMapping
      Throws:
      DescriptorException
    • getInverseReferenceMapping

      public XMLInverseReferenceMapping getInverseReferenceMapping()
      Specified by:
      getInverseReferenceMapping in interface org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,Converter,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>
    • convertObjectValueToDataValue

      public Object convertObjectValueToDataValue(Object value, Session session, XMLMarshaller marshaller)
      INTERNAL
      Specified by:
      convertObjectValueToDataValue in interface org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping<XMLMarshaller,Session,XMLUnmarshaller>
    • convertDataValueToObjectValue

      public Object convertDataValueToObjectValue(Object fieldValue, Session session, XMLUnmarshaller unmarshaller)
      INTERNAL
      Specified by:
      convertDataValueToObjectValue in interface org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping<XMLMarshaller,Session,XMLUnmarshaller>