Class XMLCompositeCollectionMapping

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping<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.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.XMLContainerMapping, org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping<XMLMarshaller,​Session,​XMLUnmarshaller>, ContainerMapping, ArrayCollectionMapping, XMLMapping, XMLNillableMapping
    Direct Known Subclasses:
    XMLVariableXPathCollectionMapping

    public class XMLCompositeCollectionMapping
    extends AbstractCompositeCollectionMapping
    implements org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping<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>, XMLMapping, XMLNillableMapping

    Composite collection XML mappings map an attribute that contains a homogeneous collection of objects to multiple XML elements. Use composite collection XML mappings to represent one-to-many relationships. Composite collection XML mappings can reference any class that has a TopLink descriptor. The attribute in the object mapped must implement either the Java Collection interface (for example, Vector or HashSet) or Map interface (for example, Hashtable or TreeMap). The CompositeCollectionMapping class allows a reference to the mapped class and the indexing type for that class. This mapping is, by definition, privately owned.

    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 Description
    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 a Composite Collection:

    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="phone-number">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="number" type="xsd:string"/>
              </xsd:sequence>
              <xsd:attribute name="type" type="xsd:string"/>
            </xsd:complexType>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>

    Code Sample
    XMLCompositeCollectionMapping phoneNumbersMapping = new XMLCompositeCollectionMapping();
    phoneNumbersMapping.setAttributeName("phoneNumbers");
    phoneNumbersMapping.setXPath("phone-number");
    phoneNumbersMapping.setReferenceClass(PhoneNumber.class);

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

    See Also:
    Serialized Form
    Since:
    Oracle TopLink 10g Release 2 (10.1.3)
    • Constructor Detail

      • XMLCompositeCollectionMapping

        public XMLCompositeCollectionMapping()
    • Method Detail

      • 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​(java.lang.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 java.lang.String getContainerAttributeName()
        Deprecated.
        Replaced by getInverseReferenceMapping().getAttributeName()
        Gets the name of the backpointer attribute on the target object.
      • setContainerGetMethodName

        @Deprecated
        public void setContainerGetMethodName​(java.lang.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 isn't declared on the reference class of this mapping, a DescriptorException will be thrown during initialize.
        Parameters:
        methodName - - the name of the getter method to be used.
      • getContainerGetMethodName

        @Deprecated
        public java.lang.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 java.lang.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.
      • setContainerSetMethodName

        @Deprecated
        public void setContainerSetMethodName​(java.lang.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 isn't declared on the reference class of this mapping, a DescriptorException will be raised during initialize.
        Parameters:
        methodName - - the name of the setter method to be used.
      • convertClassNamesToClasses

        public void convertClassNamesToClasses​(java.lang.ClassLoader classLoader)
        Description copied from class: AbstractCompositeCollectionMapping
        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 AbstractCompositeCollectionMapping
      • initializeMapContainerPolicy

        protected void initializeMapContainerPolicy​(org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                    org.eclipse.persistence.internal.queries.MapContainerPolicy cp)
      • initializeReferenceDescriptorAndField

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

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

        public void setXPath​(java.lang.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
      • buildCompositeObject

        protected java.lang.Object buildCompositeObject​(ClassDescriptor descriptor,
                                                        org.eclipse.persistence.internal.sessions.AbstractRecord nestedRow,
                                                        ObjectBuildingQuery query,
                                                        org.eclipse.persistence.internal.identitymaps.CacheKey parentCacheKey,
                                                        org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManger,
                                                        org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
        Specified by:
        buildCompositeObject in class AbstractCompositeCollectionMapping
      • buildCompositeRow

        protected org.eclipse.persistence.internal.sessions.AbstractRecord buildCompositeRow​(java.lang.Object attributeValue,
                                                                                             org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                                                             org.eclipse.persistence.internal.sessions.AbstractRecord parentRow,
                                                                                             DatabaseMapping.WriteType writeType)
        Specified by:
        buildCompositeRow in class AbstractCompositeCollectionMapping
      • buildCompositeRowForDescriptor

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

        public java.lang.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,
                                             java.lang.Boolean[] wasCacheUsed)
                                      throws DatabaseException
        Description copied from class: AbstractCompositeCollectionMapping
        INTERNAL: Build and return an aggregate collection from the specified row.
        Overrides:
        valueFromRow in class AbstractCompositeCollectionMapping
        Throws:
        DatabaseException
      • buildObjectFromNestedRow

        public java.lang.Object buildObjectFromNestedRow​(org.eclipse.persistence.internal.sessions.AbstractRecord nestedRow,
                                                         org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager,
                                                         ObjectBuildingQuery sourceQuery,
                                                         org.eclipse.persistence.internal.sessions.AbstractSession executionSession,
                                                         boolean isTargetProtected)
      • writeSingleValue

        public void writeSingleValue​(java.lang.Object value,
                                     java.lang.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.
      • setAttributeValueInObject

        public void setAttributeValueInObject​(java.lang.Object object,
                                              java.lang.Object value)
                                       throws DescriptorException
        Description copied from class: DatabaseMapping
        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 DatabaseMapping
        Throws:
        DescriptorException
      • getReuseContainer

        public boolean getReuseContainer()
        Return true if the original container on the object should be used if present. If it is not present then the container policy will be used to create the container.
        Specified by:
        getReuseContainer in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
      • setReuseContainer

        public void setReuseContainer​(boolean reuseContainer)
        Specify whether the original container on the object should be used if present. If it is not present then the container policy will be used to create the container.
        Specified by:
        setReuseContainer in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
      • isDefaultEmptyContainer

        public boolean isDefaultEmptyContainer()
        INTERNAL Return true if an empty container should be set on the object if there is no presence of the collection in the XML document.
        Specified by:
        isDefaultEmptyContainer in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
        Since:
        EclipseLink 2.3.3
      • setDefaultEmptyContainer

        public void setDefaultEmptyContainer​(boolean defaultEmptyContainer)
        INTERNAL Indicate whether by default an empty container should be set on the field/property if the collection is not present in the XML document.
        Specified by:
        setDefaultEmptyContainer in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
        Since:
        EclipseLink 2.3.3
      • getWrapperNullPolicy

        public AbstractNullPolicy getWrapperNullPolicy()
        Specified by:
        getWrapperNullPolicy in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
      • setWrapperNullPolicy

        public void setWrapperNullPolicy​(AbstractNullPolicy policy)
        Specified by:
        setWrapperNullPolicy in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
      • convertObjectValueToDataValue

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

        public java.lang.Object convertDataValueToObjectValue​(java.lang.Object value,
                                                              Session session,
                                                              XMLUnmarshaller unmarshaller)
        INTERNAL
        Specified by:
        convertDataValueToObjectValue in interface org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping<XMLMarshaller,​Session,​XMLUnmarshaller>
        Since:
        EclipseLink 2.5.0