|
EclipseLink1.0 - 20080707 API Reference | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.persistence.mappings.DatabaseMapping org.eclipse.persistence.mappings.AggregateMapping org.eclipse.persistence.mappings.foundation.AbstractCompositeCollectionMapping org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping
public class XMLCompositeCollectionMapping
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.
Field Summary |
---|
Fields inherited from class org.eclipse.persistence.mappings.foundation.AbstractCompositeCollectionMapping |
---|
converter, field |
Fields inherited from class org.eclipse.persistence.mappings.AggregateMapping |
---|
referenceClass, referenceClassName, referenceDescriptor |
Fields inherited from class org.eclipse.persistence.mappings.DatabaseMapping |
---|
attributeAccessor, attributeName, descriptor, fields, isLazy, isOptional, isReadOnly, isRemotelyInitialized, NO_FIELDS, NO_WEIGHT, primaryKeyMapping, properties, weight, WEIGHT_1 |
Constructor Summary | |
---|---|
XMLCompositeCollectionMapping()
|
Method Summary | |
---|---|
protected java.lang.Object |
buildCompositeObject(ClassDescriptor descriptor,
org.eclipse.persistence.internal.sessions.AbstractRecord nestedRow,
ObjectBuildingQuery query,
org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManger)
|
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)
|
protected ClassDescriptor |
getReferenceDescriptor(java.lang.Class theClass,
org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: For inheritance purposes. |
ClassDescriptor |
getReferenceDescriptor(DOMRecord xmlRecord)
|
java.lang.String |
getXPath()
Get the XPath String |
void |
initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: The mapping is initialized with the given session. |
boolean |
isXMLMapping()
INTERNAL: |
void |
setXPath(java.lang.String xpathString)
Set the Mapping field name attribute to the given XPath String |
boolean |
shouldAddXsiType(XMLRecord record,
ClassDescriptor descriptor)
INTERNAL: |
java.lang.Object |
valueFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord row,
org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager,
ObjectBuildingQuery sourceQuery,
org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
INTERNAL: Build and return an aggregate collection from the specified row. |
void |
writeFromObjectIntoRow(java.lang.Object object,
org.eclipse.persistence.internal.sessions.AbstractRecord row,
org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: |
void |
writeSingleValue(java.lang.Object value,
java.lang.Object parent,
XMLRecord record,
org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public XMLCompositeCollectionMapping()
Method Detail |
---|
public boolean isXMLMapping()
isXMLMapping
in class DatabaseMapping
public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session) throws DescriptorException
initialize
in class AbstractCompositeCollectionMapping
DescriptorException
public java.lang.String getXPath()
public void setXPath(java.lang.String xpathString)
xpathString
- Stringprotected java.lang.Object buildCompositeObject(ClassDescriptor descriptor, org.eclipse.persistence.internal.sessions.AbstractRecord nestedRow, ObjectBuildingQuery query, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManger)
buildCompositeObject
in class AbstractCompositeCollectionMapping
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)
buildCompositeRow
in class AbstractCompositeCollectionMapping
public void writeFromObjectIntoRow(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session) throws DescriptorException
writeFromObjectIntoRow
in class AbstractCompositeCollectionMapping
DescriptorException
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.sessions.AbstractSession executionSession) throws DatabaseException
AbstractCompositeCollectionMapping
valueFromRow
in class AbstractCompositeCollectionMapping
DatabaseException
public ClassDescriptor getReferenceDescriptor(DOMRecord xmlRecord)
protected ClassDescriptor getReferenceDescriptor(java.lang.Class theClass, org.eclipse.persistence.internal.sessions.AbstractSession session)
AggregateMapping
getReferenceDescriptor
in class AggregateMapping
public boolean shouldAddXsiType(XMLRecord record, ClassDescriptor descriptor)
public void writeSingleValue(java.lang.Object value, java.lang.Object parent, XMLRecord record, org.eclipse.persistence.internal.sessions.AbstractSession session)
XMLMapping
writeSingleValue
in interface XMLMapping
value
- - The value to be marshalledrecord
- - The Record the value is being marshalled too.
|
EclipseLink1.0 - 20080707 API Reference | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |