Class XMLCompositeObjectMapping

  • All Implemented Interfaces:
    Serializable, Cloneable, CompositeObjectMapping<AbstractSession,​AttributeAccessor,​ContainerPolicy,​Converter,​ClassDescriptor,​DatabaseField,​XMLMarshaller,​Session,​UnmarshalKeepAsElementPolicy,​XMLUnmarshaller,​XMLRecord>, Mapping<AbstractSession,​AttributeAccessor,​ContainerPolicy,​ClassDescriptor,​DatabaseField,​XMLRecord>, XMLConverterMapping<XMLMarshaller,​Session,​XMLUnmarshaller>, XMLMapping, XMLNillableMapping
    Direct Known Subclasses:
    XMLVariableXPathObjectMapping

    public class XMLCompositeObjectMapping
    extends AbstractCompositeObjectMapping
    implements XMLMapping, CompositeObjectMapping<AbstractSession,​AttributeAccessor,​ContainerPolicy,​Converter,​ClassDescriptor,​DatabaseField,​XMLMarshaller,​Session,​UnmarshalKeepAsElementPolicy,​XMLUnmarshaller,​XMLRecord>, 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:

    • Mapping into the Parent Record
    • Mapping to an Element
    • Mapping to Different Elements by Element Name
    • Mapping to Different Elements by Element Position

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

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