diff options
Diffstat (limited to 'sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic')
6 files changed, 702 insertions, 0 deletions
diff --git a/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessDataObjectPropertiesByName.java b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessDataObjectPropertiesByName.java new file mode 100644 index 0000000000..2030f35017 --- /dev/null +++ b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessDataObjectPropertiesByName.java @@ -0,0 +1,99 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.samples.sdo.basic; + +import java.util.List; + +import org.apache.tuscany.samples.sdo.SampleBase; +import org.apache.tuscany.samples.sdo.internal.SampleInfrastructure; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +/** + * Demonstrates accessing a DataObject's Property values by name. + * <p> + * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html" + * target="_top">the main overview</A> for instructions on how to run this + * sample. + */ +public class AccessDataObjectPropertiesByName extends SampleBase { + + public AccessDataObjectPropertiesByName(Integer commentaryLevel) { + super(commentaryLevel, SAMPLE_LEVEL_BASIC); + } + + + public static void main(String[] args) { + AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(COMMENTARY_FOR_NOVICE); + sample.run(); + + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.GET_PROPERTIES_OF_DATAOBJECT_BY_NAME + }; + + public void runSample () throws Exception { + + banner("This sample will access a DataObject's properties by name\n"+ + "Take a look at the sample code to see all the uses of dataObject.get(String)\n"+ + "dataObject.getList(String) and dataObject.getDataObject(String)"); + + // setting up the type system for the example, see the utility methods for details of these operations + HelperContext scope = createScopeForTypes(); + loadTypesFromXMLSchemaFile(scope, SampleInfrastructure.PO_XSD_RESOURCE); + + DataObject purchaseOrder = getDataObjectFromFile(scope, SampleInfrastructure.PO_XML_RESOURCE); + + System.out.println("Accessing properties of purchaseOrder by name"); + System.out.println("Purchase Order: "); + System.out.println(" purchaseOrder.get(\"orderDate\"): " + purchaseOrder.get("orderDate")); + System.out.println(" purchaseOrder.get(\"comment\"): " + purchaseOrder.get("comment")); + + System.out.println(" DataObject shipTo = purchaseOrder.getDataObject(\"shipTo\");"); + DataObject shipTo = purchaseOrder.getDataObject("shipTo"); + System.out.println(" shipTo.get(\"name\"): " + shipTo.get("name")); + + System.out.println(" DataObject billTo = purchaseOrder.getDataObject(\"billTo\");"); + DataObject billTo = purchaseOrder.getDataObject("billTo"); + System.out.println(" billTo.get(\"name\"): " + billTo.get("name")); + + System.out.println(" DataObject items = purchaseOrder.getDataObject(\"items\");\n" + + " List itemList = items.getList(\"item\");\n" + + " DataObject item = (DataObject) itemList.get(i);"); + DataObject items = purchaseOrder.getDataObject("items"); + List itemList = items.getList("item"); + + System.out.println(" Items:"); + for (int i = 0; i < itemList.size(); i++) { + DataObject item = (DataObject) itemList.get(i); + System.out.println(" item[" + i + "]"); + System.out.println(" item.get(\"partNum\"): " + item.get("partNum")); + System.out.println(" item.get(\"productName\"): " + item.get("productName")); + } + + } + +} diff --git a/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessingTheContentsOfASequence.java b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessingTheContentsOfASequence.java new file mode 100644 index 0000000000..e24a837ccc --- /dev/null +++ b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessingTheContentsOfASequence.java @@ -0,0 +1,115 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.samples.sdo.basic; + + +import org.apache.tuscany.samples.sdo.SampleBase; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.helper.HelperContext; + +/** + * Demonstrates accessing the sequence from a DataObject containing mixed content. + * <p> + * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html" + * target="_top">the main overview</A> for instructions on how to run this + * sample. + */ + +public class AccessingTheContentsOfASequence extends SampleBase { + + HelperContext scope; + + public AccessingTheContentsOfASequence(Integer userLevel) { + super(userLevel, SAMPLE_LEVEL_BASIC); + } + + + /** + * previously created XSD file used + */ + public static final String LETTER_XSD = "letter.xsd"; + + /** + * previously created XML file used + */ + public static final String LETTER_XML = "letter.xml"; + + /** + * Execute this method in order to run the sample. + * + * @param args + */ + public static void main(String[] args) { + + AccessingTheContentsOfASequence sample = + new AccessingTheContentsOfASequence(COMMENTARY_FOR_NOVICE); + + sample.run(); + + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.ACCESSING_VALUES_IN_A_SEQUENCE + }; + + public void runSample () throws Exception { + + commentary("Demonstrates accessing the sequence from a DataObject containing mixed content."); + + scope = createScopeForTypes(); + loadTypesFromXMLSchemaFile(scope, LETTER_XSD); + DataObject letter = getDataObjectFromFile(scope, LETTER_XML); + + // print letter sequence + commentary("We've loaded a document from an XML file that contains mixed content.\n" + + "Here's how the XML looks ...\n"); + System.out.println(scope.getXMLHelper().save(letter, "letter.xsd", "letter")); + + commentary("We can iterate over the sequence, getting the Property / Value pairs\n" + + "using the Sequence.getProperty(int) and Sequence.getValue(int) methods.\n" + + "The model for this document is \"mixed\", i.e.\n" + + "letter.getType().isMixed() returns \"true\".\n" + + "Let's take a look at the Properties in this sequence."); + + Sequence letterSequence = letter.getSequence(); + + for (int i = 0; i < letterSequence.size(); i++) { + Property prop = letterSequence.getProperty(i); + if (prop == null) { + String text = (String) letterSequence.getValue(i); + System.out.println("Unstructured text (" + text + ")"); + } else { + System.out.println("Property: " + prop.getName() + " Value : " + letterSequence.getValue(i)); + } + } + + commentary("The values of the modeled Properties are still accessible through the DataObject\n" + + "getter and setter methods, but only through the Sequence API can we get to the unstructured\n" + + "text and see the ordering of the instance document"); + + } +} diff --git a/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/CreateCompany.java b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/CreateCompany.java new file mode 100644 index 0000000000..38bafca539 --- /dev/null +++ b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/CreateCompany.java @@ -0,0 +1,151 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.samples.sdo.basic; + +import java.io.FileOutputStream; + +import org.apache.tuscany.samples.sdo.SampleBase; +import org.apache.tuscany.samples.sdo.internal.SampleInfrastructure; + + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +/** + * This sample uses the scenario of building a description of a company to demonstrate + * primarily the setting of data using strings to name Properties. + * <p> + * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html" + * target="_top">the main overview</A> for instructions on how to run this + * sample. + */ +public class CreateCompany extends SampleBase { + + public CreateCompany(Integer commentaryLevel) { + this(commentaryLevel, SAMPLE_LEVEL_BASIC); + } + + public CreateCompany(Integer commentaryLevel, Integer sampleLevel) { + super(commentaryLevel, sampleLevel); + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.SET_PROPERTIES_OF_DATAOBJECT_BY_NAME + }; + + /** + * XML file generated for the company DataObject + */ + private static final String COMPANY_GENERATED_XML = "companyGenerated.xml"; + + /** + * Main method. Execute this method in order to run sample + * @param args + * @throws Exception + */ + public static void main(String[] args) { + /* + * this sample is suitable for a novice to SDO. + * Change the experience level constructor argument to one of + * COMMENTARY_FOR_NOVICE, COMMENTARY_FOR_INTERMEDIATE, COMMENTARY_FOR_ADVANCED, change + * the level of commentary output. + */ + CreateCompany sample = new CreateCompany(COMMENTARY_FOR_NOVICE); + + sample.run(); + + } + + public void runSample () throws Exception { + + banner('*', + "Demonstrates how to create a data graph using a model loaded\n"+ + "from an XML Schema contained in a file on the file system"); + + HelperContext scope = createScopeForTypes(); + loadTypesFromXMLSchemaFile(scope, SampleInfrastructure.COMPANY_XSD); + + commentary( + "Now that our type system has been loaded and made available through the scope\n"+ + "DataObjects can be created by a DataFactory that has access to the required types.\n\n"+ + "DataObject company = scope.getDataFactory().create(SampleInfrastructure.COMPANY_NAMESPACE, \"CompanyType\");"); + + DataObject company = scope.getDataFactory().create(SampleInfrastructure.COMPANY_NAMESPACE, "CompanyType"); + + populateGraph(scope, company); + + FileOutputStream fos = new FileOutputStream(COMPANY_GENERATED_XML); + + commentary( + "The XMLHelper can be used to write an XML serialized version of the data graph\n\n"+ + "scope.getXMLHelper().save(company, SampleInfrastructure.COMPANY_NAMESPACE, \"company\", fos);"); + + scope.getXMLHelper().save(company, SampleInfrastructure.COMPANY_NAMESPACE, "company", fos); + + commentary( + "Similarly we can serialize the graph to an XML String using the XMLHelper\n\n"+ + "String xml = scope.getXMLHelper().save(company, SampleInfrastructure.COMPANY_NAMESPACE, \"company\");\n"); + + String xml = scope.getXMLHelper().save(company, SampleInfrastructure.COMPANY_NAMESPACE, "company"); + + System.out.println(xml); + + } + + public void populateGraph(HelperContext scope, DataObject company) + { + + System.out.println("Populating the company DataObject"); + company.setString("name", "ACME"); + company.setString("employeeOfTheMonth", "E0001"); + + System.out.println("Creating a Department"); + + DataObject depts = company.createDataObject("departments"); + + depts.setString("name", "Advanced Technologies"); + depts.setString("location", "NY"); + depts.setString("number", "123"); + + System.out.println("Creating an employee: John Jones"); + DataObject johnJones = depts.createDataObject("employees"); + johnJones.setString("name", "John Jones"); + + johnJones.setString("SN", "E0001"); + + System.out.println("Creating an employee: Jane Doe"); + DataObject janeDoe = depts.createDataObject("employees"); + janeDoe.setString("name", "Jane Doe"); + janeDoe.setString("SN", "E0003"); + + System.out.println("Creating a manager: Fred Bloggs"); + DataObject fVarone = depts.createDataObject("employees"); + fVarone.setString("name", "Fred Bloggs"); + fVarone.setString("SN", "E0004"); + fVarone.setString("manager", "true"); + System.out.println("DataObject creation completed"); + System.out.println(); + } + +} diff --git a/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/CreatePurchaseOrder.java b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/CreatePurchaseOrder.java new file mode 100644 index 0000000000..c41aa37397 --- /dev/null +++ b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/CreatePurchaseOrder.java @@ -0,0 +1,159 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.samples.sdo.basic; + +import java.io.FileOutputStream; +import java.io.OutputStream; + +import org.apache.tuscany.samples.sdo.SampleBase; +import org.apache.tuscany.samples.sdo.internal.SampleInfrastructure; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * Demonstrates creating a purchaseOrder DataObject from an existing XSD and then + * persisting to disk. This + * sample was used to generate valid XML for Fuhwei Lwo's paper <A + * HREF="http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/"> + * Create and read an XML document based on XML Schema</A> + * <p> + * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html" + * target="_top">the main overview</A> for instructions on how to run this + * sample. + */ + +public class CreatePurchaseOrder extends SampleBase { + + public CreatePurchaseOrder(Integer commentaryLevel) { + super(commentaryLevel, SAMPLE_LEVEL_BASIC); + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.LOADING_DATA_FROM_XML, + SDOFacets.SAVING_DATA_TO_XML + }; + + + + public static void main(String[] args) { + + CreatePurchaseOrder sample = new CreatePurchaseOrder(COMMENTARY_FOR_NOVICE); + + sample.run(); + + } + + public void runSample() throws Exception { + + commentary(COMMENTARY_ALWAYS, + "This sample is based upon Fuhwei Lwo's paper\n" + + "http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/\n" + + "and demonstrates creating a purchaseOrder DataObject from an\n" + + "existing XSD and then persisting to disk."); + + HelperContext scope = createScopeForTypes(); + + loadTypesFromXMLSchemaFile(scope, SampleInfrastructure.PO_XSD_RESOURCE); + + + commentary ( + "We are creating a DataObject using a DataFactory by specifying the URI and name of\n"+ + "the Type that we want to use for the DataObject.\n\n"+ + "DataFactory factory = scope.getDataFactory();\n"+ + "DataObject purchaseOrder = factory.create(SampleInfrastructure.PO_NAMESPACE, \"PurchaseOrderType\");"); + + DataFactory factory = scope.getDataFactory(); + DataObject purchaseOrder = factory.create(SampleInfrastructure.PO_NAMESPACE, "PurchaseOrderType"); + + + commentary( + "Now we build on the graph using the DataObject's set() and createDataObject() methods.\n"+ + "Take a look inside the program code for the full detail of these steps"); + + purchaseOrder.setString("orderDate", "1999-10-20"); + DataObject shipTo = purchaseOrder.createDataObject("shipTo"); + shipTo.set("country", "US"); + shipTo.set("name", "Alice Smith"); + shipTo.set("street", "123 Maple Street"); + shipTo.set("city", "Mill Valley"); + shipTo.set("state", "CA"); + shipTo.setString("zip", "90952"); + DataObject billTo = purchaseOrder.createDataObject("billTo"); + billTo.set("country", "US"); + billTo.set("name", "Robert Smith"); + billTo.set("street", "8 Oak Avenue"); + billTo.set("city", "Mill Valley"); + billTo.set("state", "PA"); + billTo.setString("zip", "95819"); + purchaseOrder.set("comment", "Hurry, my lawn is going wild!"); + + DataObject items = purchaseOrder.createDataObject("items"); + + DataObject item1 = items.createDataObject("item"); + item1.set("partNum", "872-AA"); + item1.set("productName", "Lawnmower"); + item1.setInt("quantity", 1); + item1.setString("price", "148.95"); + + item1.set("comment", "Confirm this is electric"); + + DataObject item2 = items.createDataObject("item"); + item2.set("partNum", "926-AA"); + item2.set("productName", "Baby Monitor"); + item2.setInt("quantity", 1); + item2.setString("price", "39.98"); + item2.setString("shipDate", "1999-05-21"); + System.out.println("Created 2 items"); + + commentary( + "Now we use the XMLHelper to write an XML document representing the data graph\n"+ + "to a file. We must supply a namespace and a name for the root element of the graph, since it is\n"+ + "not contained in the DataObject\n\n"+ + "OutputStream stream = new FileOutputStream(SampleInfrastructure.PO_XML_GENERATED);\n"+ + "scope.getXMLHelper().save(purchaseOrder, SampleInfrastructure.PO_NAMESPACE, \"purchaseOrder\", stream);" + ); + + + OutputStream stream = new FileOutputStream(SampleInfrastructure.PO_XML_GENERATED); + scope.getXMLHelper().save(purchaseOrder, SampleInfrastructure.PO_NAMESPACE, "purchaseOrder", stream); + stream.close(); + + commentary( + "We could instead have created an XMLDocument instance to wrap the DataObject\n"+ + "This has the advantage that the namespace URI and root element name are preserved in the Object\n"+ + "This interface was introduced after Fuhwei's paper, and has particular advantage\n"+ + "when loading an XML document from a file\n\n"+ + "scope.getXMLHelper().createDocument(purchaseOrder, SampleInfrastructure.PO_NAMESPACE, \"purchaseOrder\");\n"+ + "scope.getXMLHelper().save(doc, System.out, null);"); + + + XMLDocument doc = scope.getXMLHelper().createDocument(purchaseOrder, SampleInfrastructure.PO_NAMESPACE, "purchaseOrder"); + scope.getXMLHelper().save(doc, System.out, null); + System.out.println(); + } + +} diff --git a/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/ReadPurchaseOrder.java b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/ReadPurchaseOrder.java new file mode 100644 index 0000000000..e1b0dce3e6 --- /dev/null +++ b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/ReadPurchaseOrder.java @@ -0,0 +1,147 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.samples.sdo.basic; + +import java.util.List; + +import org.apache.tuscany.samples.sdo.SampleBase; +import org.apache.tuscany.samples.sdo.internal.SampleInfrastructure; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * Reads purchase order DataObject from XML, based upon Fuhwei Lwo's paper <A + * HREF="http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/"> + * Create and read an XML document based on XML Schema</A>. + * <p> + * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html" + * target="_top">the main overview</A> for instructions on how to run this + * sample. + * + */ +public class ReadPurchaseOrder extends SampleBase { + + + public static String purchaseOrderDoc = + "<?xml version=\"1.0\" encoding=\"ASCII\"?>\n"+ + " <po:purchaseOrder xmlns:po=\"http://www.example.com/PO\" orderDate=\"1999-10-20\">\n"+ + " <shipTo country=\"US\">\n"+ + " <name>Alice Smith</name>\n"+ + " <street>123 Maple Street</street>\n"+ + " <city>Mill Valley</city>\n"+ + " <state>CA</state>\n"+ + " <zip>90952</zip>\n"+ + " </shipTo>\n"+ + " <billTo country=\"US\">\n"+ + " <name>Robert Smith</name>\n"+ + " <street>8 Oak Avenue</street>\n"+ + " <city>Mill Valley</city>\n"+ + " <state>PA</state>\n"+ + " <zip>95819</zip>\n"+ + " </billTo>\n"+ + " <po:comment>Hurry, my lawn is going wild!</po:comment>\n"+ + " <items>\n"+ + " <item partNum=\"872-AA\">\n"+ + " <productName>Lawnmower</productName>\n"+ + " <price>148.95</price>\n"+ + " <quantity>1</quantity>\n"+ + " <po:comment>Confirm this is electric</po:comment>\n"+ + " </item>\n"+ + " <item partNum=\"926-AA\">\n"+ + " <productName>Baby Monitor</productName>\n"+ + " <price>39.98</price>\n"+ + " <quantity>1</quantity>\n"+ + " <shipDate>1999-05-21</shipDate>\n"+ + " </item>\n"+ + " </items>\n"+ + " </po:purchaseOrder>\n"; + + public ReadPurchaseOrder(Integer commentaryLevel) { + super(commentaryLevel, SampleInfrastructure.SAMPLE_LEVEL_BASIC); + } + + public static void main(String[] args) { + ReadPurchaseOrder sample = new ReadPurchaseOrder(COMMENTARY_FOR_NOVICE); + sample.run(); + + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.LOADING_DATA_FROM_XML, + SDOFacets.SAVING_DATA_TO_XML + }; + public static int [] SIGNIFICANT_FUNCTION = { + SDOFacets.GET_PROPERTIES_OF_DATAOBJECT_BY_NAME + }; + + + + public void runSample () throws Exception { + commentary(COMMENTARY_ALWAYS, + "This sample is based upon Fuhwei Lwo's paper \n"+ + "http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/\n"); + + HelperContext scope = createScopeForTypes(); + + loadTypesFromXMLSchemaFile(scope, SampleInfrastructure.PO_XSD_RESOURCE); + + commentary( + "We load the purchase order document into an instance of XMLDocument\n\n"+ + "XMLDocument xmlDoc = getXMLDocumentFromString(scope, purchaseOrderDoc);\n"); + + XMLDocument xmlDoc = getXMLDocumentFromString(scope, purchaseOrderDoc); + + commentary( + "We then retrieve the root DataObject from the XMLDocument\n"+ + "then print out some of the details\n\n"+ + "DataObject purchaseOrder = xmlDoc.getRootObject();"); + + DataObject purchaseOrder = xmlDoc.getRootObject(); + + System.out.println("Order date: " + purchaseOrder.get("orderDate")); + System.out.println("Comment: " + purchaseOrder.get("comment")); + + DataObject shipTo = purchaseOrder.getDataObject("shipTo"); + System.out.println("Ship to name: " + shipTo.get("name")); + + DataObject billTo = purchaseOrder.getDataObject("billTo"); + System.out.println("Bill to name: " + billTo.get("name")); + System.out.println(); + + DataObject items = purchaseOrder.getDataObject("items"); + List itemList = items.getList("item"); + for (int i = 0; i < itemList.size(); i++) { + + DataObject item = (DataObject) itemList.get(i); + + System.out.println("Part num: " + item.get("partNum")); + System.out.println("Product name: " + item.get("productName")); + } + + } + + +} diff --git a/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/package.html b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/package.html new file mode 100644 index 0000000000..d926bdbf5c --- /dev/null +++ b/sdo-java/trunk/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/package.html @@ -0,0 +1,31 @@ +<html>
+<!--
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * -->
+<head>
+ <title>Basic SDO Samples</title>
+</head>
+<BODY>
+<h1>Simple Service Data Object (SDO) Sample Programs</h1>
+
+<h3>Running the Samples</h3> See <A HREF="../../../../../../index.html"
+target="_top">the main overview</A> for instructions on how to run these
+samples.
+</BODY>
+</HTML>
|