Top Description Fields Constructors Methods
org.eclipse.persistence.oxm.mappings

public Class XMLCompositeDirectCollectionMapping

extends AbstractCompositeDirectCollectionMapping
implements DirectCollectionMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, XMLUnmarshaller, XMLRecord>, XMLMapping, XMLNillableMapping
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.oxm.mappings.XMLNillableMapping, org.eclipse.persistence.oxm.mappings.XMLMapping, org.eclipse.persistence.internal.oxm.mappings.Mapping, org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping, org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping, org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
Known Direct Subclasses
org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping
Imports
java.util.Enumeration, .Vector, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.DatabaseException, .DescriptorException, org.eclipse.persistence.internal.helper.ClassConstants, .DatabaseField, org.eclipse.persistence.internal.identitymaps.CacheKey, org.eclipse.persistence.internal.oxm.XMLConversionManager, org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping, .XMLContainerMapping, org.eclipse.persistence.internal.queries.CollectionContainerPolicy, .ContainerPolicy, .JoinedAttributeManager, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, org.eclipse.persistence.mappings.AttributeAccessor, org.eclipse.persistence.mappings.converters.Converter, .TypeConversionConverter, org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping, org.eclipse.persistence.oxm.XMLConstants, .XMLField, .XMLMarshaller, .XMLUnmarshaller, org.eclipse.persistence.oxm.mappings.converters.XMLConverter, org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy, .NullPolicy, .XMLNullRepresentationType, org.eclipse.persistence.oxm.record.DOMRecord, .XMLRecord, org.eclipse.persistence.queries.ObjectBuildingQuery, org.eclipse.persistence.sessions.Session

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 statements
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.

Since
Oracle TopLink 10g Release 2 (10.1.3)

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private boolean
private boolean
private boolean
private AbstractNullPolicy
protected transient Object
nullValue

Support specification of the value to use for null.

protected boolean
private AbstractNullPolicy
Inherited from org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping:
elementDataTypeNamefieldvalueConverter

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
public Object
public AbstractNullPolicy
public Object
getNullValue()

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.getNullValue.

PUBLIC: Allow for the value used for null to be specified.
public boolean
getReuseContainer()

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.getReuseContainer.

Return true if the original container on the object should be used if present.
public AbstractNullPolicy
public String

Returns:

String the XPath String associated with this Mapping
getXPath
()

Get the XPath String

public void
public boolean
public boolean
isCollapsingStringValues()

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.isCollapsingStringValues.

PUBLIC: Returns true if this mapping should collapse all string values before adding them to the collection.
public boolean
isDefaultEmptyContainer()

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.isDefaultEmptyContainer.

INTERNAL Return true if an empty container should be set on the object if there is no presence of the collection in the XML document.
public boolean
isNormalizingStringValues()

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.isNormalizingStringValues.

PUBLIC: Returns true if this mapping is normalizing string values on unmarshal before adding them to the collection.
public boolean
isWriteOnly()

Overrides org.eclipse.persistence.mappings.DatabaseMapping.isWriteOnly.

Implements org.eclipse.persistence.oxm.mappings.XMLMapping.isWriteOnly.

INTERNAL: Some mappings support no attribute (transformation and multitenant primary key).
public boolean
public void
preInitialize(AbstractSession session)

Overrides org.eclipse.persistence.mappings.DatabaseMapping.preInitialize.

INTERNAL: Allow for initialization of properties and validation.
public void
public void
setCollapsingStringValues(boolean collapse)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setCollapsingStringValues.

PUBLIC: Indicates that this mapping should collapse all string values before adding them to the collection on unmarshal.
public void
setDefaultEmptyContainer(boolean defaultEmptyContainer)

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.setDefaultEmptyContainer.

INTERNAL Indicate whether by default an empty container should be set on the field/property if the collection is not present in the XML document.
public void
public void
public void
setNormalizingStringValues(boolean normalize)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setNormalizingStringValues.

PUBLIC: Indicates that this mapping should normalize all string values before adding them to the collection on unmarshal.
public void
public void
setNullValue(Object nullValue)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setNullValue.

PUBLIC: Allow for the value used for null to be specified.
public void
setReuseContainer(boolean reuseContainer)

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.setReuseContainer.

Specify whether the original container on the object should be used if present.
public void
public void
setXPath(String
String
xpathString
)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setXPath.

Set the Mapping field name attribute to the given XPath String
public void
public Object
valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed)

Overrides org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping.valueFromRow.

INTERNAL: Build the nested collection from the database row.
public void
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.eclipse.persistence.internal.oxm.mappings.Mapping.writeSingleValue, org.eclipse.persistence.oxm.mappings.XMLMapping.writeSingleValue.

INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath.
Inherited from org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping:
buildAddedElementFromChangeSetbuildBackupClonebuildChangeSetbuildClonebuildCloneFromRowbuildClonePartbuildCopybuildElementFromChangeSetbuildElementFromElementbuildRemovedElementFromChangeSetcascadePerformRemoveIfRequiredcascadeRegisterNewIfRequiredcollectFieldscompareElementscompareElementsForChangecompareForChangecompareObjectsconvertClassNamesToClassesconvertToChangeRecordcreateMapComponentFromRowfixObjectReferencesgetAttributeElementClassgetContainerPolicygetFieldgetFieldClassificationgetFieldElementClassgetFieldNamegetRealCollectionAttributeValueFromObjectgetValueConverterhasValueConverterisAbstractCompositeDirectCollectionMappingisCollectionMappingiteratemapKeyHasChangedmergeChangesIntoObjectmergeIntoObjectsetAttributeElementClasssetAttributeElementClassNamesetContainerPolicysetFieldsetFieldElementClasssetUsesSingleNodesetValueConvertersimpleAddToCollectionChangeRecordsimpleRemoveFromCollectionChangeRecorduseCollectionClassuseListClassNameuseMapClassuseMapClassNameusesSingleNodewriteFromObjectIntoRowForUpdatewriteFromObjectIntoRowWithChangeRecordwriteInsertFieldsIntoRow

Field Detail

isCDATAback to summary
private boolean isCDATA
isCollapsingStringValuesback to summary
private boolean isCollapsingStringValues
isDefaultEmptyContainerback to summary
private boolean isDefaultEmptyContainer
isNormalizingStringValuesback to summary
private boolean isNormalizingStringValues
isWriteOnlyback to summary
private boolean isWriteOnly
nullPolicyback to summary
private AbstractNullPolicy nullPolicy
nullValueback to summary
protected transient Object nullValue

Support specification of the value to use for null.

reuseContainerback to summary
protected boolean reuseContainer
wrapperNullPolicyback to summary
private AbstractNullPolicy wrapperNullPolicy

Constructor Detail

XMLCompositeDirectCollectionMappingback to summary
public XMLCompositeDirectCollectionMapping()

Method Detail

convertDataValueToObjectValueback to summary
public Object convertDataValueToObjectValue(Object value, Session session, XMLUnmarshaller unmarshaller)

Implements org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping.convertDataValueToObjectValue.

INTERNAL

Annotations
@Override
Since
EclipseLink 2.5.0
convertObjectValueToDataValueback to summary
public Object convertObjectValueToDataValue(Object value, Session session, XMLMarshaller marshaller)

Implements org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping.convertObjectValueToDataValue.

INTERNAL

Annotations
@Override
Since
EclipseLink 2.5.0
getNullPolicyback to summary
public AbstractNullPolicy getNullPolicy()

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.getNullPolicy, org.eclipse.persistence.oxm.mappings.XMLNillableMapping.getNullPolicy.

Doc from org.eclipse.persistence.oxm.mappings.XMLNillableMapping.getNullPolicy.

Get the AbstractNullPolicy from the Mapping.
The default policy is NullPolicy.

Annotations
@Override
getNullValueback to summary
public Object getNullValue()

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.getNullValue.

PUBLIC: Allow for the value used for null to be specified. This can be used to convert database null values to application specific values, when null values are not allowed by the application (such as in primitives).

Note

the default value for NULL is used on reads, writes, and query SQL generation

Annotations
@Override
getReuseContainerback to summary
public boolean getReuseContainer()

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.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.

Annotations
@Override
getWrapperNullPolicyback to summary
public AbstractNullPolicy getWrapperNullPolicy()

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.getWrapperNullPolicy.

Doc from org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.getWrapperNullPolicy.

Get the Wrapper NullPolicy from the Mapping.

Annotations
@Override
getXPathback to summary
public String getXPath()

Get the XPath String

Returns:String

String the XPath String associated with this Mapping

initializeback to summary
public void initialize(AbstractSession session) throws DescriptorException

Overrides org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping.initialize.

INTERNAL: Initialize the mapping.

Annotations
@Override
isCDATAback to summary
public boolean isCDATA()

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.isCDATA.

Annotations
@Override
isCollapsingStringValuesback to summary
public boolean isCollapsingStringValues()

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.isCollapsingStringValues.

PUBLIC: Returns true if this mapping should collapse all string values before adding them to the collection. Collapse removes leading and trailing whitespaces, and replaces any sequence of whitespace characters with a single space.

Annotations
@Override
isDefaultEmptyContainerback to summary
public boolean isDefaultEmptyContainer()

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.isDefaultEmptyContainer.

INTERNAL Return true if an empty container should be set on the object if there is no presence of the collection in the XML document.

Annotations
@Override
Since
EclipseLink 2.3.3
isNormalizingStringValuesback to summary
public boolean isNormalizingStringValues()

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.isNormalizingStringValues.

PUBLIC: Returns true if this mapping is normalizing string values on unmarshal before adding them to the collection. Normalize replaces any CR, LF or Tab characters with a single space character.

Annotations
@Override
isWriteOnlyback to summary
public boolean isWriteOnly()

Overrides org.eclipse.persistence.mappings.DatabaseMapping.isWriteOnly.

Implements org.eclipse.persistence.oxm.mappings.XMLMapping.isWriteOnly.

Doc from org.eclipse.persistence.mappings.DatabaseMapping.isWriteOnly.

INTERNAL: Some mappings support no attribute (transformation and multitenant primary key).

Returns:boolean

Doc from org.eclipse.persistence.core.mappings.CoreMapping.isWriteOnly.

TODO

Annotations
@Override
isXMLMappingback to summary
public boolean isXMLMapping()

Overrides org.eclipse.persistence.mappings.DatabaseMapping.isXMLMapping.

INTERNAL:

Annotations
@Override
preInitializeback to summary
public void preInitialize(AbstractSession session) throws DescriptorException

Overrides org.eclipse.persistence.mappings.DatabaseMapping.preInitialize.

Doc from org.eclipse.persistence.mappings.DatabaseMapping.preInitialize.

INTERNAL: Allow for initialization of properties and validation.

Annotations
@Override
setAttributeValueInObjectback to summary
public void setAttributeValueInObject(Object object, Object value) throws DescriptorException

Overrides org.eclipse.persistence.mappings.DatabaseMapping.setAttributeValueInObject.

Implements org.eclipse.persistence.internal.oxm.mappings.Mapping.setAttributeValueInObject.

Doc from org.eclipse.persistence.mappings.DatabaseMapping.setAttributeValueInObject.

INTERNAL: Set the value of the attribute mapped by this mapping.

Parameters
object:Object

Doc from org.eclipse.persistence.core.mappings.CoreMapping.setAttributeValueInObject.

TODO

value:Object

Doc from org.eclipse.persistence.core.mappings.CoreMapping.setAttributeValueInObject.

TODO

Annotations
@Override
setCollapsingStringValuesback to summary
public void setCollapsingStringValues(boolean collapse)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setCollapsingStringValues.

PUBLIC: Indicates that this mapping should collapse all string values before adding them to the collection on unmarshal. Collapse removes leading and trailing whitespaces, and replaces any sequence of whitespace characters with a single space.

Annotations
@Override
setDefaultEmptyContainerback to summary
public void setDefaultEmptyContainer(boolean defaultEmptyContainer)

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.setDefaultEmptyContainer.

INTERNAL Indicate whether by default an empty container should be set on the field/property if the collection is not present in the XML document.

Annotations
@Override
Since
EclipseLink 2.3.3
setIsCDATAback to summary
public void setIsCDATA(boolean CDATA)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setIsCDATA.

Annotations
@Override
setIsWriteOnlyback to summary
public void setIsWriteOnly(boolean b)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setIsWriteOnly, org.eclipse.persistence.oxm.mappings.XMLMapping.setIsWriteOnly.

Annotations
@Override
setNormalizingStringValuesback to summary
public void setNormalizingStringValues(boolean normalize)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setNormalizingStringValues.

PUBLIC: Indicates that this mapping should normalize all string values before adding them to the collection on unmarshal. Normalize replaces any CR, LF or Tab characters with a single space character.

Annotations
@Override
setNullPolicyback to summary
public void setNullPolicy(AbstractNullPolicy value)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setNullPolicy, org.eclipse.persistence.oxm.mappings.XMLNillableMapping.setNullPolicy.

Doc from org.eclipse.persistence.oxm.mappings.XMLNillableMapping.setNullPolicy.

Set the AbstractNullPolicy on the mapping
The default policy is NullPolicy.

Annotations
@Override
setNullValueback to summary
public void setNullValue(Object nullValue)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setNullValue.

PUBLIC: Allow for the value used for null to be specified. This can be used to convert database null values to application specific values, when null values are not allowed by the application (such as in primitives).

Note

the default value for NULL is used on reads

Annotations
@Override
setReuseContainerback to summary
public void setReuseContainer(boolean reuseContainer)

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.setReuseContainer.

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.

Annotations
@Override
setWrapperNullPolicyback to summary
public void setWrapperNullPolicy(AbstractNullPolicy policy)

Implements org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.setWrapperNullPolicy.

Doc from org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping.setWrapperNullPolicy.

Set the Wrapper NullPolicy on the Mapping.

Annotations
@Override
setXPathback to summary
public void setXPath(String xpathString)

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.setXPath.

Set the Mapping field name attribute to the given XPath String

Parameters
xpathString:String

String

Annotations
@Override
useCollectionClassNameback to summary
public void useCollectionClassName(String concreteContainerClassName)

Overrides org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping.useCollectionClassName.

Implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping.useCollectionClassName, org.eclipse.persistence.mappings.ContainerMapping.useCollectionClassName.

Doc from org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping.useCollectionClassName.

INTERNAL: Used to set the collection class by name. This is required when building from metadata to allow the correct class loader to be used.

Annotations
@Override
valueFromRowback to summary
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException

Overrides org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping.valueFromRow.

INTERNAL: Build the nested collection from the database row.

Annotations
@Override
writeFromObjectIntoRowback to summary
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, DatabaseMapping.WriteType writeType)

Overrides org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping.writeFromObjectIntoRow.

INTERNAL:

Annotations
@Override
writeSingleValueback to summary
public void writeSingleValue(Object value, Object parent, XMLRecord record, AbstractSession session)

Implements org.eclipse.persistence.internal.oxm.mappings.Mapping.writeSingleValue, org.eclipse.persistence.oxm.mappings.XMLMapping.writeSingleValue.

Doc from org.eclipse.persistence.oxm.mappings.XMLMapping.writeSingleValue.

INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath. Used for Sequenced marshalling.

Parameters
value:Object

- The value to be marshalled

record:XMLRecord

- The Record the value is being marshalled too.

Annotations
@Override