Class XMLCompositeCollectionMapping

All Implemented Interfaces:
Serializable, Cloneable, CompositeCollectionMapping<AbstractSession,AttributeAccessor,ContainerPolicy,Converter,ClassDescriptor,DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>, CompositeObjectMapping<AbstractSession,AttributeAccessor,ContainerPolicy,Converter,ClassDescriptor,DatabaseField,XMLMarshaller,Session,UnmarshalKeepAsElementPolicy,XMLUnmarshaller,XMLRecord>, Mapping<AbstractSession,AttributeAccessor,ContainerPolicy,ClassDescriptor,DatabaseField,XMLRecord>, XMLContainerMapping, XMLConverterMapping<XMLMarshaller,Session,XMLUnmarshaller>, ContainerMapping, ArrayCollectionMapping, XMLMapping, XMLNillableMapping
Direct Known Subclasses:
XMLVariableXPathCollectionMapping

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 statements
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.

Since:
Oracle TopLink 10g Release 2 (10.1.3)
See Also: