Class XMLCompositeDirectCollectionMapping

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>, org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLRecord>, org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping, org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping<XMLMarshaller,​Session,​XMLUnmarshaller>, ContainerMapping, ArrayCollectionMapping, XMLMapping, XMLNillableMapping
    Direct Known Subclasses:
    XMLBinaryDataCollectionMapping

    public class XMLCompositeDirectCollectionMapping
    extends AbstractCompositeDirectCollectionMapping
    implements org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>, 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:

    • Mapping to Multiple Text Nodes
    • Mapping to Multiple Attributes
    • Mapping to a Single Text Node
    • Mapping to a Single Attribute
    • Mapping to a List of Unions
    • Mapping a Union of Lists
    • Specifying the Content Type of a Collection

    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)
    • Field Detail

      • reuseContainer

        protected boolean reuseContainer
      • nullValue

        protected transient java.lang.Object nullValue
        Support specification of the value to use for null.
    • 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
        Specified by:
        setXPath in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>
        Parameters:
        xpathString - String
      • getXPath

        public java.lang.String getXPath()
        Get the XPath String
        Returns:
        String the XPath String associated with this Mapping
      • 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,
                                             java.lang.Boolean[] wasCacheUsed)
                                      throws DatabaseException
        INTERNAL: Build the nested collection from the database row.
        Overrides:
        valueFromRow in class AbstractCompositeDirectCollectionMapping
        Throws:
        DatabaseException
      • 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 org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLRecord>
        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)
        Specified by:
        setIsCDATA in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>
      • isCDATA

        public boolean isCDATA()
        Specified by:
        isCDATA in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>
      • 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.
        Specified by:
        setAttributeValueInObject in interface org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLRecord>
        Overrides:
        setAttributeValueInObject in class DatabaseMapping
        Throws:
        DescriptorException
      • 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.
        Specified by:
        getReuseContainer in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
      • 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.
        Specified by:
        setReuseContainer in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
      • isNormalizingStringValues

        public boolean 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.
        Specified by:
        isNormalizingStringValues in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>
      • setNormalizingStringValues

        public void setNormalizingStringValues​(boolean normalize)
        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.
        Specified by:
        setNormalizingStringValues in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>
        Parameters:
        normalize -
      • setCollapsingStringValues

        public void setCollapsingStringValues​(boolean collapse)
        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.
        Specified by:
        setCollapsingStringValues in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>
        Parameters:
        collapse -
      • isCollapsingStringValues

        public boolean 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.
        Specified by:
        isCollapsingStringValues in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>
      • isDefaultEmptyContainer

        public boolean 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.
        Specified by:
        isDefaultEmptyContainer in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
        Since:
        EclipseLink 2.3.3
      • setDefaultEmptyContainer

        public void setDefaultEmptyContainer​(boolean defaultEmptyContainer)
        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.
        Specified by:
        setDefaultEmptyContainer in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
        Since:
        EclipseLink 2.3.3
      • getWrapperNullPolicy

        public AbstractNullPolicy getWrapperNullPolicy()
        Specified by:
        getWrapperNullPolicy in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
      • setWrapperNullPolicy

        public void setWrapperNullPolicy​(AbstractNullPolicy policy)
        Specified by:
        setWrapperNullPolicy in interface org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping
      • convertObjectValueToDataValue

        public java.lang.Object convertObjectValueToDataValue​(java.lang.Object value,
                                                              Session session,
                                                              XMLMarshaller marshaller)
        INTERNAL
        Specified by:
        convertObjectValueToDataValue in interface org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping<XMLMarshaller,​Session,​XMLUnmarshaller>
        Since:
        EclipseLink 2.5.0
      • convertDataValueToObjectValue

        public java.lang.Object convertDataValueToObjectValue​(java.lang.Object value,
                                                              Session session,
                                                              XMLUnmarshaller unmarshaller)
        INTERNAL
        Specified by:
        convertDataValueToObjectValue in interface org.eclipse.persistence.internal.oxm.mappings.XMLConverterMapping<XMLMarshaller,​Session,​XMLUnmarshaller>
        Since:
        EclipseLink 2.5.0
      • getNullValue

        public java.lang.Object 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
        Specified by:
        getNullValue in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>
      • setNullValue

        public void setNullValue​(java.lang.Object nullValue)
        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
        Specified by:
        setNullValue in interface org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping<org.eclipse.persistence.internal.sessions.AbstractSession,​AttributeAccessor,​org.eclipse.persistence.internal.queries.ContainerPolicy,​Converter,​ClassDescriptor,​org.eclipse.persistence.internal.helper.DatabaseField,​XMLMarshaller,​Session,​XMLUnmarshaller,​XMLRecord>