Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle TopLink
11g Release 1 (11.1.1)

B32476-02


oracle.toplink.ox.mappings
Class XMLCompositeDirectCollectionMapping

java.lang.Object
  extended by oracle.toplink.mappings.DatabaseMapping
      extended by oracle.toplink.mappings.foundation.AbstractCompositeDirectCollectionMapping
          extended by oracle.toplink.ox.mappings.XMLCompositeDirectCollectionMapping

All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ContainerMapping, oracle.toplink.ox.mappings.XMLMapping
Direct Known Subclasses:
XMLBinaryDataCollectionMapping

public class XMLCompositeDirectCollectionMapping
extends AbstractCompositeDirectCollectionMapping
implements oracle.toplink.ox.mappings.XMLMapping

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 />
  <xsd:complexType >
    <xsd:sequence>
      <xsd:element />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType >
    <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 />
  <xsd:complexType >
    <xsd:sequence>
      <xsd:element />
    </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 />
  <xsd:simpleType >
    <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)
See Also:
Serialized Form

Constructor Summary
XMLCompositeDirectCollectionMapping()
           

 

Method Summary
 java.lang.String getXPath()
          Get the XPath String
 boolean isCDATA()
           
 void setIsCDATA(boolean CDATA)
           
 void setXPath(java.lang.String xpathString)
          Set the Mapping field name attribute to the given XPath String
 void useCollectionClassName(java.lang.String concreteContainerClassName)
           

 

Methods inherited from class oracle.toplink.mappings.foundation.AbstractCompositeDirectCollectionMapping
getAttributeElementClass, getFieldElementClass, getFieldName, getValueConverter, hasValueConverter, setAttributeElementClass, setContainerPolicy, setField, setFieldElementClass, setUsesSingleNode, setValueConverter, simpleAddToCollectionChangeRecord, simpleRemoveFromCollectionChangeRecord, useCollectionClass, useMapClass, usesSingleNode

 

Methods inherited from class oracle.toplink.mappings.DatabaseMapping
getAttributeAccessor, getAttributeClassification, getAttributeName, getGetMethodName, getProperty, getReferenceDescriptor, getSetMethodName, isLazy, isOptional, isUsingMethodAccess, readOnly, readWrite, setAttributeAccessor, setAttributeName, setGetMethodName, setIsLazy, setIsOptional, setIsReadOnly, setProperty, setSetMethodName, setWeight

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Constructor Detail

XMLCompositeDirectCollectionMapping

public XMLCompositeDirectCollectionMapping()

Method Detail

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)

setIsCDATA

public void setIsCDATA(boolean CDATA)

isCDATA

public boolean isCDATA()

Skip navigation links

Copyright © 1998, 2009, Oracle. All Rights Reserved.