EclipseLink 2.2.0, build 'v20110202-r8913' API Reference

org.eclipse.persistence.oxm.mappings
Class XMLCompositeDirectCollectionMapping

java.lang.Object
  extended by org.eclipse.persistence.mappings.DatabaseMapping
      extended by org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping
          extended by org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ContainerMapping, XMLMapping, XMLNillableMapping
Direct Known Subclasses:
XMLBinaryDataCollectionMapping

public class XMLCompositeDirectCollectionMapping
extends AbstractCompositeDirectCollectionMapping
implements XMLMapping, XMLNillableMapping

Composite direct collection XML mappings map a collection of simple types (String, Number, Date, etc.) to and from a sequence of composite XML nodes.

Composite direct collection XML mappings can be used in the following scenarios:

Setting the XPath: TopLink XML mappings make use of an XPath statement 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 node type, path, and positional information. 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
@tasks The "@" character indicates that the node is an attribute. This XPath applies only to the single attribute node case; each member of the collection is mapped to a single node.
tasks/@task The "@" character indicates that the node is an attribute. The information is stored in the attribute node of the tasks element.
text() "text()" indicates that the node is a text node. In this case the task value in the text node belongs to the context node.
tasks/text() The task information is stored in the text node of the tasks element.
tasks/task/text() The XPath statement may be used to specify any valid path.
task[2]/text() The XPath statement may contain positional information. In this case the task information is stored in the text node of the second occurrence of the task element.

Mapping to a Single Text Node: By default, TopLink maps each member of a collection to it's own node. It is possible, however, to mapping a collection to a single node; here the contents of the node is treated as a space-separated list. This behavior is set on the mapping using the setUsesSingleNode method, with 'true' as the parameter.

XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="employee" type="employee-type"/>
  <xsd:complexType name="employee-type">
    <xsd:sequence>
      <xsd:element name="tasks" type="tasks-type"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType name="tasks-type">
    <xsd:list itemType="xsd:string"/>
  </xsd:simpleType>
</xsd:schema>

Code Sample
XMLCompositeDirectCollectionMapping tasksMapping = new XMLCompositeDirectCollectionMapping();
tasksMapping.setAttributeName("tasks");
tasksMapping.setXPath("tasks/text()");
tasksMapping.setUsesSingleNode(true);

Specifying the Content Type of a Collection: By default, TopLink will treat the node values read in by a composite direct collection XML mapping as objects of type String. You can override this behavior by specifying the type of the collection's contents.

XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="employee" type="employee-type"/>
  <xsd:complexType name="employee-type">
    <xsd:sequence>
      <xsd:element name="vacation" type="xsd:string" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

Code Sample
XMLCompositeDirectCollectionMapping tasksMapping = new XMLCompositeDirectCollectionMapping();
tasksMapping.setAttributeName("vacationDays");
tasksMapping.setXPath("vacation/text()");
tasksMapping.setAttributeElementClass(Calendar.class);

Mapping to a List of Unions:

XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="vacation" type="listOfUnions"/>
  <xsd:simpleType name="listOfUnions">
    <xsd:list>
      <xsd:simpleType>
        <xsd:union memberTypes="xsd:date xsd:integer"/>
      </xsd:simpleType>
    </xsd:list>
  </xsd:simpleType>
</xsd:schema>

Code Sample
XMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping();
mapping.setAttributeName("myattribute");
XMLUnionField field = new XMLUnionField("listOfUnions/text()");
mapping.addSchemaType(new QName(url,XMLConstants.INT));
mapping.addSchemaType(new QName(url,XMLConstants.DATE));
mapping.setField(field);
mapping.useSingleElement(false);

More Information: For more information about using the XML Composite Direct Collection 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)

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.persistence.mappings.DatabaseMapping
DatabaseMapping.WriteType
 
Field Summary
protected  boolean reuseContainer
           
 
Fields inherited from class org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping
elementDataTypeName, field, valueConverter
 
Fields inherited from class org.eclipse.persistence.mappings.DatabaseMapping
attributeAccessor, attributeName, derivedIdMapping, derivesId, descriptor, fields, isCacheable, isJPAId, isLazy, isMapKeyMapping, isOptional, isPrimaryKeyMapping, isReadOnly, isRemotelyInitialized, mapsIdValue, NO_FIELDS, NO_WEIGHT, properties, weight, WEIGHT_AGGREGATE, WEIGHT_DIRECT, WEIGHT_TO_ONE, WEIGHT_TRANSFORM
 
Constructor Summary
XMLCompositeDirectCollectionMapping()
           
 
Method Summary
 AbstractNullPolicy getNullPolicy()
          Get the AbstractNullPolicy from the Mapping.
 boolean getReuseContainer()
          Return true if the original container on the object should be used if present.
 java.lang.String getXPath()
          Get the XPath String
 void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Initialize the mapping.
 boolean isCDATA()
           
 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.
 void setAttributeValueInObject(java.lang.Object object, java.lang.Object value)
          INTERNAL: Set the value of the attribute mapped by this mapping.
 void setIsCDATA(boolean CDATA)
           
 void setIsWriteOnly(boolean b)
           
 void setNullPolicy(AbstractNullPolicy value)
          Set the AbstractNullPolicy on the mapping
The default policy is NullPolicy.
 void setReuseContainer(boolean reuseContainer)
          Specify whether the original container on the object should be used if present.
 void setXPath(java.lang.String xpathString)
          Set the Mapping field name attribute to the given XPath String
 void useCollectionClassName(java.lang.String concreteContainerClassName)
           
 java.lang.Object valueFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.identitymaps.CacheKey cacheKey, org.eclipse.persistence.internal.sessions.AbstractSession executionSession, boolean isTargetProtected)
          INTERNAL: Build the nested collection from the database row.
 void writeFromObjectIntoRow(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session, DatabaseMapping.WriteType writeType)
          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.AbstractCompositeDirectCollectionMapping
buildAddedElementFromChangeSet, buildBackupClone, buildChangeSet, buildClone, buildCloneFromRow, buildClonePart, buildCopy, buildElementFromChangeSet, buildElementFromElement, buildRemovedElementFromChangeSet, cascadePerformRemoveIfRequired, cascadeRegisterNewIfRequired, collectFields, compareElements, compareElementsForChange, compareForChange, compareObjects, convertClassNamesToClasses, convertToChangeRecord, fixObjectReferences, getAttributeElementClass, getContainerPolicy, getField, getFieldClassification, getFieldElementClass, getFieldName, getRealCollectionAttributeValueFromObject, getValueConverter, hasValueConverter, isAbstractCompositeDirectCollectionMapping, isCollectionMapping, iterate, mapKeyHasChanged, mergeChangesIntoObject, mergeIntoObject, setAttributeElementClass, setContainerPolicy, setField, setFieldElementClass, setUsesSingleNode, setValueConverter, simpleAddToCollectionChangeRecord, simpleRemoveFromCollectionChangeRecord, useCollectionClass, useMapClass, usesSingleNode, writeFromObjectIntoRowForUpdate, writeFromObjectIntoRowWithChangeRecord, writeInsertFieldsIntoRow
 
Methods inherited from class org.eclipse.persistence.mappings.DatabaseMapping
buildBackupCloneForPartObject, buildChangeRecord, buildCloneForPartObject, buildContainerClone, buildExpression, buildObjectJoinExpression, buildObjectJoinExpression, buildShallowOriginalFromRow, calculateDeferredChanges, cascadeDiscoverAndPersistUnregisteredNewObjects, cascadeMerge_, cascadePerformRemovePrivateOwnedObjectFromChangeSetIfRequired, clone, cloneFields, collectQueryParameters, createCloneValueHolder, derivesId, earlyPreDelete, extractNestedExpressions, fixRealObjectReferences, getAttributeAccessor, getAttributeClassification, getAttributeName, getAttributeValueFromObject, getDerivedIdMapping, getDescriptor, getFields, getGetMethodName, getMapsIdValue, getObjectCorrespondingTo, getProperties, getProperty, getRealAttributeValueFromAttribute, getRealAttributeValueFromObject, getReferenceDescriptor, getRelationshipPartner, getSelectFields, getSelectTables, getSetMethodName, getValueFromRemoteValueHolder, getWeight, hasConstraintDependency, hasDependency, hasInverseConstraintDependency, hasMapsIdValue, hasRootExpressionThatShouldUseOuterJoin, instantiateAttribute, isAbstractCompositeCollectionMapping, isAbstractCompositeObjectMapping, isAbstractDirectMapping, isAggregateCollectionMapping, isAggregateMapping, isAggregateObjectMapping, isCacheable, isCandidateForPrivateOwnedRemoval, isCascadedLockingSupported, isChangeTrackingSupported, isCloningRequired, isDatabaseMapping, isDirectCollectionMapping, isDirectMapMapping, isDirectToFieldMapping, isDirectToXMLTypeMapping, isEISMapping, isForeignReferenceMapping, isJoiningSupported, isJPAId, isLazy, isLockableMapping, isManyToManyMapping, isManyToOneMapping, isMapKeyMapping, isNestedTableMapping, isObjectReferenceMapping, isOneToManyMapping, isOneToOneMapping, isOptional, isOwned, isPrimaryKeyMapping, isPrivateOwned, isReadOnly, isReferenceMapping, isRelationalMapping, isRemotelyInitialized, isStructureMapping, isTransformationMapping, isUnidirectionalOneToManyMapping, isUsingMethodAccess, isVariableOneToOneMapping, iterateOnRealAttributeValue, performDataModificationEvent, postCalculateChanges, postCalculateChangesOnDeleted, postDelete, postInitialize, postInsert, postUpdate, preDelete, preInsert, prepareCascadeLockingPolicy, preUpdate, readFromResultSetIntoObject, readFromRowIntoObject, readOnly, readWrite, recordPrivateOwnedRemovals, rehashFieldDependancies, remoteInitialization, remotelyInitialized, replaceValueHoldersIn, setAttributeAccessor, setAttributeName, setChangeListener, setDerivedIdMapping, setDerivesId, setDescriptor, setFields, setGetMethodName, setIsCacheable, setIsJPAId, setIsLazy, setIsMapKeyMapping, setIsOptional, setIsPrimaryKeyMapping, setIsReadOnly, setMapsIdValue, setProperties, setProperty, setRealAttributeValueInObject, setSetMethodName, setWeight, toString, updateChangeRecord, updateCollectionChangeRecord, validateAfterInitialization, validateBeforeInitialization, valueFromObject, valueFromResultSet, valueFromRow, verifyDelete, writeFromAttributeIntoRow, writeFromObjectIntoRowForShallowInsert, writeFromObjectIntoRowForShallowInsertWithChangeRecord, writeFromObjectIntoRowForWhereClause, writeUpdateFieldsIntoRow
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

reuseContainer

protected boolean reuseContainer
Constructor Detail

XMLCompositeDirectCollectionMapping

public XMLCompositeDirectCollectionMapping()
Method Detail

isXMLMapping

public boolean isXMLMapping()
INTERNAL:

Overrides:
isXMLMapping in class DatabaseMapping

initialize

public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
                throws DescriptorException
INTERNAL: Initialize the mapping.

Overrides:
initialize in class AbstractCompositeDirectCollectionMapping
Throws:
DescriptorException

setXPath

public void setXPath(java.lang.String xpathString)
Set the Mapping field name attribute to the given XPath String

Parameters:
xpathString - String

getXPath

public java.lang.String getXPath()
Get the XPath String

Returns:
String the XPath String associated with this Mapping

useCollectionClassName

public void useCollectionClassName(java.lang.String concreteContainerClassName)

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.identitymaps.CacheKey cacheKey,
                                     org.eclipse.persistence.internal.sessions.AbstractSession executionSession,
                                     boolean isTargetProtected)
                              throws DatabaseException
INTERNAL: Build the nested collection from the database row.

Overrides:
valueFromRow in class AbstractCompositeDirectCollectionMapping
Throws:
DatabaseException

writeFromObjectIntoRow

public void writeFromObjectIntoRow(java.lang.Object object,
                                   org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                   org.eclipse.persistence.internal.sessions.AbstractSession session,
                                   DatabaseMapping.WriteType writeType)
INTERNAL:

Overrides:
writeFromObjectIntoRow in class AbstractCompositeDirectCollectionMapping

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.

setIsCDATA

public void setIsCDATA(boolean CDATA)

isCDATA

public boolean isCDATA()

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

setAttributeValueInObject

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

Overrides:
setAttributeValueInObject in class DatabaseMapping
Throws:
DescriptorException

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

getNullPolicy

public AbstractNullPolicy getNullPolicy()
Description copied from interface: XMLNillableMapping
Get the AbstractNullPolicy from the Mapping.
The default policy is NullPolicy.

Specified by:
getNullPolicy in interface XMLNillableMapping
Returns:

setNullPolicy

public void setNullPolicy(AbstractNullPolicy value)
Description copied from interface: XMLNillableMapping
Set the AbstractNullPolicy on the mapping
The default policy is NullPolicy.

Specified by:
setNullPolicy in interface XMLNillableMapping

getReuseContainer

public boolean getReuseContainer()
Return true if the original container on the object should be used if present. If it is not present then the container policy will be used to create the container.


setReuseContainer

public void setReuseContainer(boolean reuseContainer)
Specify whether the original container on the object should be used if present. If it is not present then the container policy will be used to create the container.


EclipseLink 2.2.0, build 'v20110202-r8913' API Reference