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

From Eclipsepedia

Jump to: navigation, search
(Introspect Metadata - Types)
m
 
(12 intermediate revisions by one user not shown)
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 a set of SDO Types from an XML Schema
+
* Define SDO Types and Properties from an XML Schema
 
+
* Lookup SDO Types and Properties
==Initializing the Types from XML Schema==
+
* Get XML Schema Information about SDO Types and Properties
 
+
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.
+
  
 +
==Define SDO Types and Properties from XML Schema==
 +
The first thing that needs to be done in a 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">
 
FileInputStream xsdInputStream = new FileInputStream("Customer.xsd");
 
FileInputStream xsdInputStream = new FileInputStream("Customer.xsd");
Line 13: Line 13:
 
</source>
 
</source>
  
==Introspect Metadata - Types==
+
==Lookup SDO Types and Properties==
Once the XML schema has been processed the types are available from TypeHelper.
+
 
 +
===Get a SDO Open Content 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.
 +
<source lang="java">
 +
Property phoneNumberProperty =
 +
    TypeHelper.INSTANCE.getOpenContentProperty("http://www.example.org/customer-example", "phone-number");
 +
</source>
 +
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.
 +
<source lang="java">
 +
Property phoneNumberProperty =
 +
    XSDHelper.INSTANCE.getGlobalProperty("http://www.example.org/customer-example", "phone-number", true);
 +
</source>
 +
 
 +
===Get a SDO Type corresponding to a Global Complex Type===
 +
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");
 +
</source>
 +
 +
===Get a SDO Type corresponding to a Global Attribute/Element===
 +
When the SDO Type corresponds to a global element like the following:
 +
<source lang="xml">
 +
<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>
 +
</source>
 +
Then the corresponding SDO Type can be looked up as follows:
 +
<source lang="java">
 +
Property phoneNumberProperty =
 +
    TypeHelper.INSTANCE.getOpenContentProperty("http://www.example.org/customer-example", "phone-number");
 +
Type phoneNumberType = phoneNumberProperty.getType();
 +
</source>
 +
 +
==Get XML Schema Information about SDO Types and Properties==
 +
===SDO Property XML Schema Info===
 +
You can determine if the SDO property corresponds to an XML attribute or XML element:
 +
<source lang="java">
 +
XSDHelper.INSTANCE.isAttribute(phoneNumberProperty);
 +
XSDHelper.INSTANCE.isElement(phoneNumberProperty);
 +
</source>
 +
You can get XML name/URI information:
 +
<source lang="java">
 +
XSDHelper.INSTANCE.getLocalName(phoneNumberProperty);
 +
XSDHelper.INSTANCE.getNamespaceURI(phoneNumberProperty);
 +
</source>
 +
===SDO Type XML Schema Info===
 +
You can get the XML name information:
 +
<source lang="java">
 +
XSDHelper.INSTANCE.getLocalName(addressType);
 +
</source>
 +
You can determine if the corresponding XML type is mixed:
 +
<source lang="java">
 +
XSDHelper.INSTANCE.isMixed(addressType);
 
</source>
 
</source>

Latest revision as of 16:24, 24 February 2009

Contents

[edit] Overview

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

  • Define SDO Types and Properties from an XML Schema
  • Lookup SDO Types and Properties
  • Get XML Schema Information about SDO Types and Properties

[edit] Define SDO Types and Properties from XML Schema

The first thing that needs to be done in a 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);

[edit] Lookup SDO Types and Properties

[edit] Get a SDO Open Content 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);

[edit] Get a 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");

[edit] Get a 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();

[edit] Get XML Schema Information about SDO Types and Properties

[edit] SDO Property XML Schema Info

You can determine if the SDO property corresponds to an XML attribute or XML element:

XSDHelper.INSTANCE.isAttribute(phoneNumberProperty);
XSDHelper.INSTANCE.isElement(phoneNumberProperty);

You can get XML name/URI information:

XSDHelper.INSTANCE.getLocalName(phoneNumberProperty);
XSDHelper.INSTANCE.getNamespaceURI(phoneNumberProperty);

[edit] SDO Type XML Schema Info

You can get the XML name information:

XSDHelper.INSTANCE.getLocalName(addressType);

You can determine if the corresponding XML type is mixed:

XSDHelper.INSTANCE.isMixed(addressType);