Skip Headers
Oracle TopLink Developer's Guide
10g Release 3 (10.1.3)
B13593-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

XML Any Object Mapping

The XML any object mapping is similar to the composite object XML mapping (see "XML Composite Object Mapping") except that the reference object may be of any type (including String). This type doesn't need to be related to any other particular type through inheritance or a common interface.

The corresponding object attribute value can be an instance of any object with a Descriptor, a java.lang.Object, a java.lang.String, a primitive object (such as java.lang.Integer), or a user defined type generic enough for all possible application values.

This mapping is useful with the following XML schema constructs:

Each of the referenced objects (except String) must specify a default root element on their descriptor (see "Default Root Element").

Given the XML schema in Example 65-51, Figure 65-28 illustrates the Java classes used in this example. A single XML any object mapping is used to map Customer attribute contactMethod. This attribute must be generic enough to reference all possible values: in this example, instances of Address, PhoneNumber, and String.

Example 65-51 Schema for XML Any Object Mapping

<?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-method" 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>

Figure 65-28 Java Classes for XML Any Object Mapping

This illustration is described in the preceeding paragraph.

Figure 65-29, Figure 65-30, and Figure 65-31 illustrate how the XML any object mapping maps to an Address, PhoneNumber, and String (respectively) in XML documents that conform to the schema in Example 65-51.

Figure 65-29 XML Any Object Mapping to Address Type

This illustration is described in the preceeding paragraph.

Figure 65-30 XML Any Object Mapping to PhoneNumber Type

This illustration is described in the preceeding paragraph.

Figure 65-31 XML Any Object Mapping to String Type

This illustration is described in the preceeding paragraph.

Example 65-49 shows how to configure this mapping in Java.

Example 65-52 Java for XML Any Object Mapping

XMLAnyObjectMapping contactMethodMapping = new XMLAnyObjectMapping();
contactMethodMapping.setAttributeName("contactMethod");
contactMethodMapping.setXPath("contact-method");

For more information about TopLink XML mapping support for xs:any and xs:anyType, see "xs:any and xs:anyType Support".

See Chapter 71, "Configuring an XML Any Object Mapping" for more information.