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:
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 |
|---|---|
| . | 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.
| Modifier and Type | Field and Description |
|---|---|
| private XMLInverseReferenceMapping | |
| private boolean | |
| private UnmarshalKeepAsElementPolicy | |
| pack-priv AbstractNullPolicy |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Object | buildCompositeObject(ObjectBuilder objectBuilder, AbstractRecord nestedRow, ObjectBuildingQuery query, CacheKey parentCacheKey, JoinedAttributeManager joinManager, AbstractSession targetSession)
Implements abstract org. |
| protected Object | buildCompositeRow(Object attributeValue, AbstractSession session, AbstractRecord databaseRow, DatabaseMapping.
Implements abstract org. |
| protected AbstractRecord | buildCompositeRowForDescriptor(ClassDescriptor classDesc, Object attributeValue, AbstractSession session, XMLRecord parentRow, DatabaseMapping.
|
| public void | |
| public void | convertClassNamesToClasses(ClassLoader
TODO classLoader)Overrides org. Implements org. |
| public Object | convertDataValueToObjectValue(Object fieldValue, Session session, XMLUnmarshaller unmarshaller)
Implements org. |
| public Object | convertObjectValueToDataValue(Object value, Session session, XMLMarshaller marshaller)
Implements org. |
| private Object | convertToSimpleTypeIfPresent(Object toReturn, XMLRecord 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 String | |
| public void | initialize(AbstractSession session)
Overrides org. |
| protected void | |
| public boolean | isWriteOnly()
Overrides org. Implements org. |
| public boolean | |
| public void | preInitialize(AbstractSession session)
Overrides org. |
| public Object | readFromRowIntoObject(AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object targetObject, CacheKey parentCacheKey, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected)
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 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 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.
|
| pack-priv void | |
| public void | |
| public void | |
| public void | setNullPolicy(AbstractNullPolicy aNullPolicy)
Implements org. |
| public void | setXPath(String
String xpathString)Implements org. |
| public Object | valueFromRow(Object fieldValue, XMLRecord nestedRow, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected)
|
| 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 databaseRow, AbstractSession session, DatabaseMapping.
Overrides org. |
| 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. |
| inverseReferenceMapping | back to summary |
|---|---|
| private XMLInverseReferenceMapping inverseReferenceMapping | |
| isWriteOnly | back to summary |
|---|---|
| private boolean isWriteOnly | |
| keepAsElementPolicy | back to summary |
|---|---|
| private UnmarshalKeepAsElementPolicy keepAsElementPolicy | |
| nullPolicy | back to summary |
|---|---|
| pack-priv AbstractNullPolicy nullPolicy | |
| XMLCompositeObjectMapping | back to summary |
|---|---|
| public XMLCompositeObjectMapping() | |
| buildCompositeObject | back to summary |
|---|---|
| protected Object buildCompositeObject(ObjectBuilder objectBuilder, AbstractRecord nestedRow, ObjectBuildingQuery query, CacheKey parentCacheKey, JoinedAttributeManager joinManager, AbstractSession targetSession) Implements abstract org.
| |
| buildCompositeRow | back to summary |
|---|---|
| protected Object buildCompositeRow(Object attributeValue, AbstractSession session, AbstractRecord databaseRow, DatabaseMapping. Implements abstract org.
| |
| buildCompositeRowForDescriptor | back to summary |
|---|---|
| protected AbstractRecord buildCompositeRowForDescriptor(ClassDescriptor classDesc, Object attributeValue, AbstractSession session, XMLRecord parentRow, DatabaseMapping. | |
| configureNestedRow | back to summary |
|---|---|
| public void configureNestedRow(AbstractRecord parent, AbstractRecord child) | |
| convertClassNamesToClasses | back to summary |
|---|---|
| public void convertClassNamesToClasses(ClassLoader classLoader) Overrides org. Implements org. Doc from org. 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.
| |
| convertDataValueToObjectValue | back to summary |
|---|---|
| public Object convertDataValueToObjectValue(Object fieldValue, Session session, XMLUnmarshaller unmarshaller) Implements org. INTERNAL
| |
| convertObjectValueToDataValue | back to summary |
|---|---|
| public Object convertObjectValueToDataValue(Object value, Session session, XMLMarshaller marshaller) Implements org. INTERNAL
| |
| convertToSimpleTypeIfPresent | back to summary |
|---|---|
| private Object convertToSimpleTypeIfPresent(Object toReturn, XMLRecord nestedRow, AbstractSession executionSession) | |
| getContainerAccessor | back to summary |
|---|---|
| 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.
| |
| getContainerAttributeName | back to summary |
|---|---|
| public String getContainerAttributeName()
Deprecated Replaced by getInverseReferenceMapping().getAttributeName() Gets the name of the backpointer attribute on the target object. Used to populate the backpointer.
| |
| getContainerGetMethodName | back to summary |
|---|---|
| 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 | back to summary |
|---|---|
| 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.
| |
| getDescriptor | back to summary |
|---|---|
| protected XMLDescriptor getDescriptor(XMLRecord xmlRecord, AbstractSession session, QName rootQName) throws XMLMarshalException | |
| getInverseReferenceMapping | back to summary |
|---|---|
| public XMLInverseReferenceMapping getInverseReferenceMapping() Implements org.
| |
| getKeepAsElementPolicy | back to summary |
|---|---|
| public UnmarshalKeepAsElementPolicy getKeepAsElementPolicy() Implements org.
| |
| getNullPolicy | back to summary |
|---|---|
| public AbstractNullPolicy getNullPolicy() Implements org. INTERNAL:
Get the AbstractNullPolicy from the Mapping.
| |
| getReferenceDescriptor | back to summary |
|---|---|
| public ClassDescriptor getReferenceDescriptor(DOMRecord xmlRecord) | |
| getReferenceDescriptor | back to summary |
|---|---|
| protected ClassDescriptor getReferenceDescriptor(Class<?> theClass, AbstractSession session) Overrides org. Doc from org. INTERNAL: For inheritance purposes.
| |
| getXPath | back to summary |
|---|---|
| public String getXPath() Get the XPath String
| |
| initialize | back to summary |
|---|---|
| public void initialize(AbstractSession session) throws DescriptorException Overrides org. INTERNAL: The mapping is initialized with the given session. This mapping is fully initialized after this.
| |
| initializeReferenceDescriptorAndField | back to summary |
|---|---|
| protected void initializeReferenceDescriptorAndField(AbstractSession session) | |
| isWriteOnly | back to summary |
|---|---|
| public boolean isWriteOnly() Overrides org. Implements org. Doc from org. INTERNAL: Some mappings support no attribute (transformation and multitenant primary key).
| |
| isXMLMapping | back to summary |
|---|---|
| public boolean isXMLMapping() Overrides org. INTERNAL:
| |
| preInitialize | back to summary |
|---|---|
| public void preInitialize(AbstractSession session) throws DescriptorException Overrides org. Doc from org. INTERNAL: Allow for initialization of properties and validation.
| |
| readFromRowIntoObject | back to summary |
|---|---|
| public Object readFromRowIntoObject(AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object targetObject, CacheKey parentCacheKey, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException Overrides org. Doc from org. 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.
| |
| setAttributeValueInObject | back to summary |
|---|---|
| public void setAttributeValueInObject(Object object, Object value) throws DescriptorException Overrides org. Implements org. Doc from org. INTERNAL: Set the value of the attribute mapped by this mapping.
| |
| setContainerAccessor | back to summary |
|---|---|
| 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.
| |
| setContainerAttributeName | back to summary |
|---|---|
| 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.
| |
| setContainerGetMethodName | back to summary |
|---|---|
| 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.
| |
| setContainerSetMethodName | back to summary |
|---|---|
| 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.
| |
| setInverseReferenceMapping | back to summary |
|---|---|
| pack-priv void setInverseReferenceMapping(XMLInverseReferenceMapping inverseReferenceMapping) | |
| setIsWriteOnly | back to summary |
|---|---|
| public void setIsWriteOnly(boolean b) Implements org.
| |
| setKeepAsElementPolicy | back to summary |
|---|---|
| public void setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy keepAsElementPolicy) Implements org.
| |
| setNullPolicy | back to summary |
|---|---|
| public void setNullPolicy(AbstractNullPolicy aNullPolicy) Implements org. Set the AbstractNullPolicy on the mapping
| |
| setXPath | back to summary |
|---|---|
| public void setXPath(String xpathString) Implements org. Set the Mapping field name attribute to the given XPath String | |
| valueFromRow | back to summary |
|---|---|
| public Object valueFromRow(Object fieldValue, XMLRecord nestedRow, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException | |
| valueFromRow | back to summary |
|---|---|
| public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException Overrides org. Doc from org. INTERNAL: Extract and return the aggregate object from the specified row.
| |
| writeFromObjectIntoRow | back to summary |
|---|---|
| public void writeFromObjectIntoRow(Object object, AbstractRecord databaseRow, AbstractSession session, DatabaseMapping. Overrides org. INTERNAL:
| |
| writeSingleValue | back to summary |
|---|---|
| public void writeSingleValue(Object value, Object parent, XMLRecord record, AbstractSession session) Implements org. Doc from org. INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath. Used for Sequenced marshalling. | |