Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Examples/SDO/MetadataXMLSchema"
Line 2: | Line 2: | ||
The following example will demonstrate how to use EclipseLink's SDO functionality to: | The following example will demonstrate how to use EclipseLink's SDO functionality to: | ||
− | * Define SDO Types from an XML Schema | + | * Define SDO Types and Properties from an XML Schema |
* Lookup Metadata | * Lookup Metadata | ||
− | ==Define SDO Types from XML Schema== | + | ==Define SDO Types and Properties 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. | 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. | ||
<source lang="java"> | <source lang="java"> | ||
Line 62: | Line 62: | ||
Type phoneNumberType = phoneNumberProperty.getType(); | Type phoneNumberType = phoneNumberProperty.getType(); | ||
</source> | </source> | ||
+ | |||
+ | ==Get XML Schema Information about SDO Types and Properties== |
Revision as of 16:03, 24 February 2009
Contents
Overview
The following example will demonstrate how to use EclipseLink's SDO functionality to:
- Define SDO Types and Properties from an XML Schema
- Lookup Metadata
Define SDO Types and Properties 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);
Look up Metadata
Get an SDO Open Context Property corresponding to a Global Attribute/Element
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);
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");
Get an SDO Type corresponding to a Global Attribute/Element
When the SDO Type corresponds to a global element like the following:
<xs:element name="phone-number"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="number-type" type="xs:string"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element>
Then the corresponding SDO Type can be looked up as follows:
Property phoneNumberProperty = TypeHelper.INSTANCE.getOpenContentProperty("http://www.example.org/customer-example", "phone-number"); Type phoneNumberType = phoneNumberProperty.getType();