Jump to: navigation, search


Initialize the Types (Metadata)

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.

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

Unmarshal the XML Document

SDO is often used to manipulate XML data. The following code demonstrates how to unmarshal an XML document using the statically generated classes see Generating Java Source from an XML Schema.

Code Example
FileInputStream xmlInputStream = new FileInputStream("input.xml");
XMLDocument xmlDocument = XMLHelper.INSTANCE.load(xmlInputStream);
CustomerType customer = (CustomerType) xmlDocument.getRootObject();

Modify the Data Objects

Below is an example of manipulating the Data Objects using the static classes. Note that there are JavaBean type accessors on the static interfaces.

Code Example
PhoneNumber phoneNumber = (PhoneNumber) DataFactory.INSTANCE.create("urn:customer-
example", "phone-number");
phoneNumber.setValue("(613) 555-3333");

Marshal the Data Objects

The following code segment demonstrates how to marshal DataObjects wrapped in a commonj.sdo.helper.XMLDocument back to XML.

Code Example
XMLHelper.INSTANCE.save(xmlDocument, System.out, null);