Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/SDO/MetadataXMLSchema"

(Introspect Metadata - Types)
Line 13: Line 13:
 
</source>
 
</source>
  
==Introspect Metadata - Types==
+
==Get an SDO Type corresponding to a Global Complex Type==
Once the XML schema has been processed the types are available from TypeHelper.
+
When the SDO Type corresponds to a global complex type like the following:
 +
<source lang="xml">
 +
<xs:complexType name="address-type">
 +
    <xs:sequence>
 +
        <xs:element name="street" type="xs:string" maxOccurs="2"/>
 +
        <xs:element name="city" type="xs:string"/>
 +
        <xs:element name="state" type="xs:string"/>
 +
        <xs:element name="zip-code" type="xs:string"/>
 +
    </xs:sequence>
 +
</xs:complexType>
 +
</source>
 +
Then the corresponding SDO Type can be looked up as follows:
 
<source lang="java">
 
<source lang="java">
 
Type addressType = TypeHelper.INSTANCE.getType("http://www.example.org/customer-example", "address-type");
 
Type addressType = TypeHelper.INSTANCE.getType("http://www.example.org/customer-example", "address-type");

Revision as of 14:50, 24 February 2009

Overview

The following example will demonstrate how to use EclipseLink's SDO functionality to:

  • Define a set of SDO Types from an XML Schema

Initializing the Types from XML Schema

The first thing that needs to be done in an SDO application is to set up the metadata for the Types and Properties. This is most commonly done by loading an XML schema, although it may also be done programmatically.

FileInputStream xsdInputStream = new FileInputStream("Customer.xsd");
XSDHelper.INSTANCE.define(xsdInputStream, null);

Get an SDO Type corresponding to a Global Complex Type

When the SDO Type corresponds to a global complex type like the following:

<xs:complexType name="address-type">
    <xs:sequence>
        <xs:element name="street" type="xs:string" maxOccurs="2"/>
        <xs:element name="city" type="xs:string"/>
        <xs:element name="state" type="xs:string"/>
        <xs:element name="zip-code" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

Then the corresponding SDO Type can be looked up as follows:

Type addressType = TypeHelper.INSTANCE.getType("http://www.example.org/customer-example", "address-type");

Introspect Metadata - Properties

Once the XML schema has been processed the global attributes and elements are available as open content properties.

Property phoneNumberProperty = 
     TypeHelper.INSTANCE.getOpenContentProperty("http://www.example.org/customer-example", "phone-number");

You can also use XSDHelper to get the open content properties using XML information. This is useful when you have a global element and attribute in the same namspace with the same name.

Property phoneNumberProperty = 
     XSDHelper.INSTANCE.getGlobalProperty("http://www.example.org/customer-example", "phone-number", true);