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/SdoStatic"
m |
|||
Line 1: | Line 1: | ||
− | == Initialize | + | == Initialize the Types (Metadata) == |
− | FileInputStream xsdInputStream = new FileInputStream(" | + | 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("Example.xsd"); | ||
<br>XSDHelper.INSTANCE.define(xsdInputStream, null); | <br>XSDHelper.INSTANCE.define(xsdInputStream, null); | ||
== Unmarshal the XML document == | == 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 blah. | ||
+ | |||
FileInputStream xmlInputStream = new FileInputStream("../Resource/bin/Customer-data.xml"); | FileInputStream xmlInputStream = new FileInputStream("../Resource/bin/Customer-data.xml"); | ||
<br>XMLDocument xmlDocument = XMLHelper.INSTANCE.load(xmlInputStream); | <br>XMLDocument xmlDocument = XMLHelper.INSTANCE.load(xmlInputStream); | ||
Line 9: | Line 13: | ||
== Modify the Data Objects == | == 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. | ||
+ | |||
PhoneNumber phoneNumber = (PhoneNumber) DataFactory.INSTANCE.create("urn:customer-<br>example", "phone-number"); | PhoneNumber phoneNumber = (PhoneNumber) DataFactory.INSTANCE.create("urn:customer-<br>example", "phone-number"); | ||
<br>phoneNumber.setNumberType("home"); | <br>phoneNumber.setNumberType("home"); | ||
Line 15: | Line 21: | ||
== Marshal the Data Objects == | == Marshal the Data Objects == | ||
+ | The following code segment demonstrates how to marshal DataObjects wrapped in a commonj.sdo.helper.XML document back to XML. | ||
+ | |||
XMLHelper.INSTANCE.save(xmlDocument, System.out, null); | XMLHelper.INSTANCE.save(xmlDocument, System.out, null); |
Revision as of 13:51, 22 October 2007
Contents
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.
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 blah.
FileInputStream xmlInputStream = new FileInputStream("../Resource/bin/Customer-data.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.
PhoneNumber phoneNumber = (PhoneNumber) DataFactory.INSTANCE.create("urn:customer-
example", "phone-number");
phoneNumber.setNumberType("home");
phoneNumber.setValue("(613) 555-3333");
customer.getContactInfo().getPhoneNumber().add(phoneNumber);
Marshal the Data Objects
The following code segment demonstrates how to marshal DataObjects wrapped in a commonj.sdo.helper.XML document back to XML.
XMLHelper.INSTANCE.save(xmlDocument, System.out, null);