Class XMLAnyCollectionMapping

  • All Implemented Interfaces:
    Serializable, Cloneable, AnyCollectionMapping<AbstractSession,​AttributeAccessor,​ContainerPolicy,​XMLConverter,​ClassDescriptor,​DatabaseField,​XMLMarshaller,​Session,​UnmarshalKeepAsElementPolicy,​XMLUnmarshaller,​XMLRecord>, Mapping<AbstractSession,​AttributeAccessor,​ContainerPolicy,​ClassDescriptor,​DatabaseField,​XMLRecord>, XMLContainerMapping, XMLConverterMapping<XMLMarshaller,​Session,​XMLUnmarshaller>, ContainerMapping, XMLMapping

    public class XMLAnyCollectionMapping
    extends XMLAbstractAnyMapping
    implements AnyCollectionMapping<AbstractSession,​AttributeAccessor,​ContainerPolicy,​XMLConverter,​ClassDescriptor,​DatabaseField,​XMLMarshaller,​Session,​UnmarshalKeepAsElementPolicy,​XMLUnmarshaller,​XMLRecord>, XMLMapping, ContainerMapping

    Any collection XML mappings map an attribute that contains a heterogenous collection of objects to multiple XML elements. Unlike composite collection XML mappings, the referenced objects may be of different types (including String), and do not need to be related to each other through inheritance or a common interface. The corresponding object attribute should be generic enough for all possible application values. Note that each of the referenced objects (except String) must specify a default root element on their descriptor.

    Any collection mappings are useful with the following XML schema constructs:

    • any
    • choice
    • substitution groups

    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 node type, path, and positional information. The XPath is specified on the mapping using the setXPath method. Note that for XML Any Collection Mappings the XPath is optional.

    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
    contact-methods The name information is stored in the contact-methods element.
    contact-methods/info The XPath statement may be used to specify any valid path.
    contact-methods[2] The XPath statement may contain positional information. In this case the contact information is stored in the second occurrence of the contact-methods element.

    Mapping an element of type xs:anyType as an Any Collection Mapping:

    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="contact-methods" type="xsd:anyType"/>
        </xsd:sequence>
      </xsd:complexType>
      <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:element name="phone-number" type="xsd:string"/>
    </xsd:schema>

    Code Sample
    XMLAnyCollectionMapping contactMethodsMapping = new XMLAnyCollectionMapping();
    contactMethodsMapping.setAttributeName("contactMethods");
    contactMethodsMapping.setXPath("contact-methods");

    More Information: For more information about using the XML Any 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