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.
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private XMLInverseReferenceMapping | |
| private boolean | |
| private UnmarshalKeepAsElementPolicy | |
| pack-priv AbstractNullPolicy | |
| private boolean | |
| private AbstractNullPolicy |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Object | buildCompositeObject(ClassDescriptor descriptor, AbstractRecord nestedRow, ObjectBuildingQuery query, CacheKey parentCacheKey, JoinedAttributeManager joinManger, AbstractSession targetSession)
Implements abstract org. |
| protected AbstractRecord | buildCompositeRow(Object attributeValue, AbstractSession session, AbstractRecord parentRow, DatabaseMapping.
Implements abstract org. |
| protected AbstractRecord | buildCompositeRowForDescriptor(ClassDescriptor classDesc, Object attributeValue, AbstractSession session, XMLRecord parentRow, DatabaseMapping.
|
| public Object | buildObjectFromNestedRow(AbstractRecord nestedRow, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected)
|
| public void | convertClassNamesToClasses(ClassLoader
TODO classLoader)
Implements org. |
| public Object | convertDataValueToObjectValue(Object value, Session session, XMLUnmarshaller unmarshaller)
Implements org. |
| public Object | convertObjectValueToDataValue(Object value, Session session, XMLMarshaller marshaller)
Implements org. |
| private Object | convertToSimpleTypeIfPresent(Object objectToAdd, AbstractRecord nestedRow, AbstractSession executionSession)
|
| 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.
|
| public String | getContainerAttributeName()
Deprecated
Replaced by getInverseReferenceMapping().getAttributeName()
Gets the name of the backpointer attribute on the target object.
|
| 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.
|
| 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.
|
| protected XMLDescriptor | |
| public XMLInverseReferenceMapping | |
| public UnmarshalKeepAsElementPolicy | |
| public AbstractNullPolicy | getNullPolicy()
Implements org. |
| public ClassDescriptor | |
| protected ClassDescriptor | getReferenceDescriptor(Class<?> theClass, AbstractSession session)
Overrides org. |
| public boolean | getReuseContainer()
Implements org. |
| public AbstractNullPolicy | getWrapperNullPolicy()
Implements org. |
| public String | |
| public void | initialize(AbstractSession session)
Overrides org. |
| protected void | |
| protected void | |
| public boolean | isDefaultEmptyContainer()
Implements org. |
| public boolean | isWriteOnly()
Overrides org. Implements org. |
| public boolean | |
| public void | preInitialize(AbstractSession session)
Overrides org. |
| public void | setAttributeValueInObject(Object
TODO object, Object TODO value)Overrides org. Implements org. |
| public void | setContainerAccessor(AttributeAccessor
- the accessor to be used. 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.
|
| public void | setContainerAttributeName(String
- the name of the backpointer attribute to be populated attributeName)
Deprecated
Replaced by getInverseReferenceMapping().setAttributeName()
Sets the name of the backpointer attribute on the target object.
|
| public void | setContainerGetMethodName(String
- the name of the getter method to be used. 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.
|
| public void | setContainerSetMethodName(String
- the name of the setter method to be used. 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.
|
| public void | setDefaultEmptyContainer(boolean defaultEmptyContainer)
Implements org. |
| pack-priv void | |
| public void | |
| public void | |
| public void | setNullPolicy(AbstractNullPolicy aNullPolicy)
Implements org. |
| public void | setReuseContainer(boolean reuseContainer)
Implements org. |
| public void | setWrapperNullPolicy(AbstractNullPolicy policy)
Implements org. |
| public void | setXPath(String
String xpathString)Implements org. |
| public Object | valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed)
Overrides org. |
| public void | writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, DatabaseMapping.
|
| public void | writeSingleValue(Object
- The value to be marshalled value, Object parent, XMLRecord - The Record the value is being marshalled too. record, AbstractSession session)Implements org. |