Oracle® TopLink Developer's Guide 10g Release 3 (10.1.3.1.0) Part Number B28218-01 |
|
|
View PDF |
This chapter describes the various components that you must configure in order to use an XML descriptor.
For more information, see the following:
Table 29-1 lists the default configurable options for an XML descriptor.
Table 29-1 lists the default configurable options for an XML descriptor.
Table 29-1 Configuration Options for XML Descriptors
Option | Type | TopLink Workbench | Java |
---|---|---|---|
"Configuring XML Schema Namespace" |
Basic |
||
"Configuring XML Schema Reference" |
Basic |
||
"Configuring Schema Context for an XML Descriptor" |
Basic |
||
"Configuring for Complex Type of anyType" |
Advanced |
||
"Configuring Default Root Element" |
Basic |
||
"Configuring Document Preservation" |
Basic |
||
"Configuring Descriptor Comments" |
Advanced |
||
|
Basic |
||
"Configuring Inheritance for a Child (Branch or Leaf) Class Descriptor" |
Advanced |
|
|
"Configuring Inheritance for a Parent (Root) Descriptor" |
Advanced |
||
"Configuring Inherited Attribute Mapping in a Subclass" |
Advanced |
|
|
"Configuring Instantiation Policy" |
Advanced |
||
|
Advanced |
||
"Configuring Amendment Methods" |
Advanced |
||
|
Basic |
TopLink Workbench uses the schema context to associate the XML descriptor reference class with a simple or complex type in one of the schemas associated with the XML project (see "Configuring XML Schema Reference"). This allows TopLink Workbench to display the appropriate attributes available for mapping in that context.
You must configure the schema context for an XML descriptor regardless of whether or not you are using TopLink Workbench.
The TopLink runtime uses the schema context to validate XML fragments.
To associate an XML descriptor with a specific schema complex type, use this procedure:
Select an XML descriptor in the Navigator. Its properties appear in the Editor.
Click the Descriptor Info tab. The Descriptor Info tab appears.
Figure 29-1 Descriptor Info Tab, Schema Context Option
Click Browse to select the schema element to associate with this descriptor. For more information, see "Choosing a Schema Context".
Use the Choose Schema Context dialog box to select a specific schema element (such as when mapping an element).
Figure 29-2 Choose Schema Context Dialog Box
Select a schema element and click OK.
To configure an XML descriptor with a schema context using Java, create a descriptor amendment method (see "Configuring Amendment Methods") that uses XMLSchemaReference
method setSchemaContext
, as Example 29-1 shows.
This attribute applies only to TopLink Workbench. Use this option to solve "No schema context is specified" problems (see "Using the Problems Window") for an XML descriptor that does not represent an element in your XML schema.
In general, TopLink Workbench assumes that every XML descriptor must have a schema context (see "Configuring Schema Context for an XML Descriptor"). However, if a class in your project does not relate to an element in your schema, then it does not have a schema context.
For example, consider the schema that Example 29-2 shows.
Example 29-2 Schema Using xsd:anyType
<?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>
Because element contact-method
is of type xsd:anyType
, your project requires a class to represent that type, such as class AnyTypeImpl
shown in Figure 29-3. Because this class does not relate to any complex type in your schema, it has no schema context. In this example, you would select this option for the AnyTypeImpl
class.
Figure 29-3 Class Representing xsd:anyType
For more information, see "xs:any and xs:anyType Support".
Complex Type of anyType Option
To specify that the descriptor represents a complex type of anyType
, use this procedure:
Select a descriptor in the Navigator. Its properties appear in the Editor.
Click the Descriptor Info tab. The Descriptor Info tab appears.
Figure 29-4 Descriptor Info Tab, Complex Type "anyType" Option
Select the Descriptor Represents Complex Type "anyType" option to specify this descriptor as the root element.
The default root element is the name that TopLink uses for the root element when marshalling objects for this descriptor to, and unmarshalling from, an XML document. Descriptors used only in composite relationship mappings do not require a default root element.
For more information, see "Default Root Element".
To specify a schema element as the default root element for the descriptor, use this procedure:
Select a descriptor in the Navigator. Its properties appear in the Editor.
Click the Descriptor Info tab. The Descriptor Info tab appears.
Figure 29-5 Descriptor Info Tab, Default Root Option
Select the Default Root Element option to specify this descriptor as the root element.
Click Browse to select the schema element to identify as the root element for this descriptor. See "Choosing a Root Element" for more information.
Use the Choose Root Element dialog box to select a specific root element.
Figure 29-6 Choose Root Element Dialog Box
Select the root element and click OK.
TopLink lets you preserve any "extra" data in your XML source that is not required to map to an object model (such as comments, processing instructions, or unmapped elements).
This permits round-tripping from XML to objects and back to XML without losing any data.
To preserve the entire XML source document, use this procedure:
Select a descriptor in the Navigator. Its properties appear in the Editor.
Click the Descriptor Info tab. The Descriptor Info tab appears.
Figure 29-7 Descriptor Info Tab, Preserve Document Option
Select the Preserve Document option to maintain any extra information from the source XML document that TopLink does not require (such as comments).
To configure an XML descriptor to maintain any extra information from the source XML document that TopLink does not require (such as comments) using Java, create a descriptor amendment method (see "Configuring Amendment Methods") that configures the descriptor using XMLDescriptor
method setShouldPreserveDocument
.