Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
The XML any collection mapping is similar to the composite collection XML mapping (see "XML Composite Collection Mapping"), except that the referenced objects may be of different types (including String
). These types need not be related to each other 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:
any
choice
substitution groups
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-53, Figure 65-32 illustrates the Java classes used in this example. A single XML any collection mapping is used to map Customer
attribute contactMethods
. This attribute must be generic enough to reference all possible values: in this example, instances of Address
, PhoneNumber
, and String
.
Example 65-53 Schema for XML Any Collection 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-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>
Figure 65-33 illustrate how the XML any collection mapping maps to a collection of Address
, PhoneNumber
, and String
objects in an XML document that conforms to the schema in Example 65-53.
Example 65-54 shows how to configure this mapping in Java.
Example 65-54 Java for XML Any Collection Mapping
XMLAnyCollectionMapping contactMethodsMapping = new XMLAnyCollectionMapping(); contactMethodsMapping.setAttributeName("contactMethods"); contactMethodsMapping.setXPath("contact-methods");
For more information about TopLink XML mapping support for xs:any
and xs:anyType
, see "xs:any and xs:anyType Support".
See Chapter 72, "Configuring an XML Any Collection Mapping" for more information.