EclipseLink 1.2.0, build 'v20091016-r5565' API Reference

org.eclipse.persistence.oxm.mappings
Class XMLCompositeObjectMapping

java.lang.Object
  extended by org.eclipse.persistence.mappings.DatabaseMapping
      extended by org.eclipse.persistence.mappings.AggregateMapping
          extended by org.eclipse.persistence.mappings.foundation.AbstractCompositeObjectMapping
              extended by org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, XMLMapping, XMLNillableMapping

public class XMLCompositeObjectMapping
extends AbstractCompositeObjectMapping
implements XMLMapping, XMLNillableMapping

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.

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

Field Summary
 
Fields inherited from class org.eclipse.persistence.mappings.foundation.AbstractCompositeObjectMapping
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, isDerivedIdMapping, isLazy, isMapKeyMapping, isOptional, isPrimaryKeyMapping, isReadOnly, isRemotelyInitialized, mappedByIdValue, NO_FIELDS, NO_WEIGHT, properties, weight, WEIGHT_1
 
Constructor Summary
XMLCompositeObjectMapping()
           
 
Method Summary
protected  java.lang.Object buildCompositeObject(org.eclipse.persistence.internal.descriptors.ObjectBuilder objectBuilder, org.eclipse.persistence.internal.sessions.AbstractRecord nestedRow, ObjectBuildingQuery query, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager)
           
protected  java.lang.Object buildCompositeRow(java.lang.Object attributeValue, org.eclipse.persistence.internal.sessions.AbstractSession session, org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow)
           
 void configureNestedRow(org.eclipse.persistence.internal.sessions.AbstractRecord parent, org.eclipse.persistence.internal.sessions.AbstractRecord child)
           
 AttributeAccessor getContainerAccessor()
          Gets the AttributeAccessor that is used to get and set the value of the container on the target object.
 java.lang.String getContainerAttributeName()
          Gets the name of the backpointer attribute on the target object.
 java.lang.String getContainerGetMethodName()
          Gets the name of the method to be used when accessing the value of the back pointer on the target object of this mapping.
 java.lang.String getContainerSetMethodName()
          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 getDescriptor(XMLRecord xmlRecord, org.eclipse.persistence.internal.sessions.AbstractSession session, javax.xml.namespace.QName rootQName)
           
 UnmarshalKeepAsElementPolicy getKeepAsElementPolicy()
           
 AbstractNullPolicy getNullPolicy()
          INTERNAL: Get the AbstractNullPolicy from the Mapping.
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 isWriteOnly()
          INTERNAL: Some mappings support no attribute (transformation).
 boolean isXMLMapping()
          INTERNAL:
 void preInitialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Allow for initialization of properties and validation.
 java.lang.Object readFromRowIntoObject(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, java.lang.Object targetObject, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
          INTERNAL: Extract value from the row and set the attribute to this value in the object.
 void setAttributeValueInObject(java.lang.Object object, java.lang.Object value)
          INTERNAL: Set the value of the attribute mapped by this mapping.
 void setContainerAccessor(AttributeAccessor anAttributeAccessor)
          Sets the AttributeAccessor that is used to get and set the value of the container on the target object.
 void setContainerAttributeName(java.lang.String attributeName)
          Sets the name of the backpointer attribute on the target object.
 void setContainerGetMethodName(java.lang.String methodName)
          Sets the method name to be used when accessing the value of the back pointer on the target object of this mapping.
 void setContainerSetMethodName(java.lang.String methodName)
          Sets the name of the method to be used when setting the value of the back pointer on the target object of this mapping.
 void setIsWriteOnly(boolean b)
           
 void setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy keepAsElementPolicy)
           
 void setNullPolicy(AbstractNullPolicy aNullPolicy)
          Set the AbstractNullPolicy on the mapping
The default policy is NullPolicy.
 void setXPath(java.lang.String xpathString)
          Set the Mapping field name attribute to the given XPath String
 boolean shouldAddXsiType(XMLRecord record, ClassDescriptor aDescriptor)
          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: Extract and return the aggregate object from the specified row.
 java.lang.Object valueFromRow(java.lang.Object fieldValue, XMLRecord nestedRow, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
           
 void writeFromObjectIntoRow(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, 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 org.eclipse.persistence.mappings.foundation.AbstractCompositeObjectMapping
buildShallowOriginalFromRow, cascadeDiscoverAndPersistUnregisteredNewObjects, cascadePerformRemoveIfRequired, cascadeRegisterNewIfRequired, collectFields, convertClassNamesToClasses, getAttributeValueFromObject, getConverter, getField, hasConverter, isAbstractCompositeObjectMapping, setConverter, setField, valueFromObject, writeFromObjectIntoRowForUpdate, writeFromObjectIntoRowWithChangeRecord, writeInsertFieldsIntoRow
 
Methods inherited from class org.eclipse.persistence.mappings.AggregateMapping
buildAggregateDeleteQuery, buildAggregateModifyQuery, buildAggregateWriteQuery, buildBackupClone, buildBackupClonePart, buildClone, buildCloneFromRow, buildClonePart, buildClonePart, buildCopy, buildCopyOfAttributeValue, buildExpression, buildNewMergeInstanceOf, compareAttributeValues, compareForChange, compareObjects, executeEvent, fixAttributeValue, fixObjectReferences, getAttributeValueFromBackupClone, getObjectBuilder, getObjectBuilderForClass, getQueryManager, getReferenceClass, getReferenceClassName, getReferenceDescriptor, getReferenceDescriptor, isAggregateMapping, iterate, iterateOnAttributeValue, mergeAttributeValue, mergeChangesIntoObject, mergeIntoObject, postDelete, postDeleteAttributeValue, postInsert, postInsertAttributeValue, postUpdate, postUpdateAttributeValue, preDelete, preDeleteAttributeValue, preInsert, preInsertAttributeValue, preUpdate, preUpdateAttributeValue, remoteInitialization, setReferenceClass, setReferenceClassName, setReferenceDescriptor, updateChangeRecord, verifyDelete, verifyDeleteOfAttributeValue
 
Methods inherited from class org.eclipse.persistence.mappings.DatabaseMapping
buildBackupCloneForPartObject, buildChangeRecord, buildCloneForPartObject, buildObjectJoinExpression, buildObjectJoinExpression, calculateDeferredChanges, cascadeMerge, cascadePerformRemovePrivateOwnedObjectFromChangeSetIfRequired, clone, cloneFields, createUnitOfWorkValueHolder, earlyPreDelete, extractNestedExpressions, fixRealObjectReferences, getAttributeAccessor, getAttributeClassification, getAttributeName, getContainerPolicy, getDescriptor, getFieldClassification, getFields, getGetMethodName, getMappedByIdValue, getObjectCorrespondingTo, getProperties, getProperty, getRealAttributeValueFromAttribute, getRealAttributeValueFromObject, getRealCollectionAttributeValueFromObject, getRelationshipPartner, getSelectFields, getSelectTables, getSetMethodName, getValueFromRemoteValueHolder, getWeight, hasConstraintDependency, hasDependency, hasInverseConstraintDependency, hasMappedByIdValue, hasRootExpressionThatShouldUseOuterJoin, instantiateAttribute, isAbstractCompositeCollectionMapping, isAbstractCompositeDirectCollectionMapping, isAbstractDirectMapping, isAggregateCollectionMapping, isAggregateObjectMapping, isCandidateForPrivateOwnedRemoval, isCascadedLockingSupported, isChangeTrackingSupported, isCloningRequired, isCollectionMapping, isDatabaseMapping, isDerivedIdMapping, isDirectCollectionMapping, isDirectMapMapping, isDirectToFieldMapping, isDirectToXMLTypeMapping, isEISMapping, isForeignReferenceMapping, isJoiningSupported, isLazy, isLockableMapping, isManyToManyMapping, isMapKeyMapping, isNestedTableMapping, isObjectReferenceMapping, isOneToManyMapping, isOneToOneMapping, isOptional, isPrimaryKeyMapping, isPrivateOwned, isReadOnly, isReferenceMapping, isRelationalMapping, isRemotelyInitialized, isStructureMapping, isTransformationMapping, isUnidirectionalOneToManyMapping, isUsingMethodAccess, isVariableOneToOneMapping, iterateOnRealAttributeValue, performDataModificationEvent, postCalculateChanges, postCalculateChangesOnDeleted, postInitialize, prepareCascadeLockingPolicy, readFromResultSetIntoObject, readOnly, readWrite, recordPrivateOwnedRemovals, rehashFieldDependancies, remotelyInitialized, replaceValueHoldersIn, setAttributeAccessor, setAttributeName, setChangeListener, setDescriptor, setFields, setGetMethodName, setIsDerivedIdMapping, setIsLazy, setIsMapKeyMapping, setIsOptional, setIsPrimaryKeyMapping, setIsReadOnly, setMappedByIdValue, setProperties, setProperty, setRealAttributeValueInObject, setSetMethodName, setWeight, simpleAddToCollectionChangeRecord, simpleRemoveFromCollectionChangeRecord, toString, updateCollectionChangeRecord, validateAfterInitialization, validateBeforeInitialization, valueFromResultSet, valueFromRow, writeFromAttributeIntoRow, writeFromObjectIntoRowForShallowInsert, writeFromObjectIntoRowForShallowInsertWithChangeRecord, writeFromObjectIntoRowForWhereClause, writeUpdateFieldsIntoRow
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLCompositeObjectMapping

public XMLCompositeObjectMapping()
Method Detail

getContainerAccessor

public AttributeAccessor getContainerAccessor()
Gets the AttributeAccessor that is used to get and set the value of the container on the target object.


setContainerAccessor

public void setContainerAccessor(AttributeAccessor anAttributeAccessor)
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

public void setContainerAttributeName(java.lang.String attributeName)
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

public java.lang.String getContainerAttributeName()
Gets the name of the backpointer attribute on the target object. Used to populate the backpointer.


setContainerGetMethodName

public void setContainerGetMethodName(java.lang.String methodName)
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.

Parameters:
methodName - - the getter method to be used.

setContainerSetMethodName

public void setContainerSetMethodName(java.lang.String methodName)
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.

Parameters:
methodName - - the setter method to be used.

getContainerGetMethodName

public java.lang.String getContainerGetMethodName()
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

public java.lang.String getContainerSetMethodName()
Gets the name of the method to be used when setting the value of the back pointer on the target object of this mapping.


initialize

public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
                throws DescriptorException
INTERNAL: The mapping is initialized with the given session. This mapping is fully initialized after this.

Overrides:
initialize in class AbstractCompositeObjectMapping
Throws:
DescriptorException

setNullPolicy

public void setNullPolicy(AbstractNullPolicy aNullPolicy)
Set the AbstractNullPolicy on the mapping
The default policy is NullPolicy.

Specified by:
setNullPolicy in interface XMLNillableMapping
Parameters:
aNullPolicy -

getNullPolicy

public AbstractNullPolicy getNullPolicy()
INTERNAL: Get the AbstractNullPolicy from the Mapping.
The default policy is NullPolicy.

Specified by:
getNullPolicy in interface XMLNillableMapping
Returns:

isXMLMapping

public boolean isXMLMapping()
INTERNAL:

Overrides:
isXMLMapping in class DatabaseMapping

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

Parameters:
xpathString - String

buildCompositeRow

protected java.lang.Object buildCompositeRow(java.lang.Object attributeValue,
                                             org.eclipse.persistence.internal.sessions.AbstractSession session,
                                             org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow)
Specified by:
buildCompositeRow in class AbstractCompositeObjectMapping

buildCompositeObject

protected java.lang.Object buildCompositeObject(org.eclipse.persistence.internal.descriptors.ObjectBuilder objectBuilder,
                                                org.eclipse.persistence.internal.sessions.AbstractRecord nestedRow,
                                                ObjectBuildingQuery query,
                                                org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager)
Specified by:
buildCompositeObject in class AbstractCompositeObjectMapping

readFromRowIntoObject

public java.lang.Object readFromRowIntoObject(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow,
                                              org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager,
                                              java.lang.Object targetObject,
                                              ObjectBuildingQuery sourceQuery,
                                              org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
                                       throws DatabaseException
Description copied from class: DatabaseMapping
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.

Overrides:
readFromRowIntoObject in class DatabaseMapping
Throws:
DatabaseException

valueFromRow

public java.lang.Object valueFromRow(java.lang.Object fieldValue,
                                     XMLRecord nestedRow,
                                     org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager,
                                     ObjectBuildingQuery sourceQuery,
                                     org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
                              throws DatabaseException
Throws:
DatabaseException

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.sessions.AbstractSession executionSession)
                              throws DatabaseException
Description copied from class: AbstractCompositeObjectMapping
INTERNAL: Extract and return the aggregate object from the specified row.

Overrides:
valueFromRow in class AbstractCompositeObjectMapping
Throws:
DatabaseException

writeFromObjectIntoRow

public void writeFromObjectIntoRow(java.lang.Object object,
                                   org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow,
                                   org.eclipse.persistence.internal.sessions.AbstractSession session)
                            throws DescriptorException
INTERNAL:

Overrides:
writeFromObjectIntoRow in class AbstractCompositeObjectMapping
Throws:
DescriptorException

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 XMLMapping
Parameters:
value - - The value to be marshalled
record - - The Record the value is being marshalled too.

configureNestedRow

public void configureNestedRow(org.eclipse.persistence.internal.sessions.AbstractRecord parent,
                               org.eclipse.persistence.internal.sessions.AbstractRecord child)

getReferenceDescriptor

public ClassDescriptor getReferenceDescriptor(DOMRecord xmlRecord)

getReferenceDescriptor

protected ClassDescriptor getReferenceDescriptor(java.lang.Class theClass,
                                                 org.eclipse.persistence.internal.sessions.AbstractSession session)
Description copied from class: AggregateMapping
INTERNAL: For inheritance purposes.

Overrides:
getReferenceDescriptor in class AggregateMapping

shouldAddXsiType

public boolean shouldAddXsiType(XMLRecord record,
                                ClassDescriptor aDescriptor)
INTERNAL:


getKeepAsElementPolicy

public UnmarshalKeepAsElementPolicy getKeepAsElementPolicy()

setKeepAsElementPolicy

public void setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy keepAsElementPolicy)

getDescriptor

protected XMLDescriptor getDescriptor(XMLRecord xmlRecord,
                                      org.eclipse.persistence.internal.sessions.AbstractSession session,
                                      javax.xml.namespace.QName rootQName)
                               throws XMLMarshalException
Throws:
XMLMarshalException

setIsWriteOnly

public void setIsWriteOnly(boolean b)
Specified by:
setIsWriteOnly in interface XMLMapping

isWriteOnly

public boolean isWriteOnly()
Description copied from class: DatabaseMapping
INTERNAL: Some mappings support no attribute (transformation).

Specified by:
isWriteOnly in interface XMLMapping
Overrides:
isWriteOnly in class DatabaseMapping

preInitialize

public void preInitialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
                   throws DescriptorException
Description copied from class: DatabaseMapping
INTERNAL: Allow for initialization of properties and validation.

Overrides:
preInitialize in class DatabaseMapping
Throws:
DescriptorException

setAttributeValueInObject

public void setAttributeValueInObject(java.lang.Object object,
                                      java.lang.Object value)
                               throws DescriptorException
Description copied from class: AbstractCompositeObjectMapping
INTERNAL: Set the value of the attribute mapped by this mapping.

Overrides:
setAttributeValueInObject in class AbstractCompositeObjectMapping
Throws:
DescriptorException

EclipseLink 1.2.0, build 'v20091016-r5565' API Reference