diff options
Diffstat (limited to 'sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources')
6 files changed, 1500 insertions, 0 deletions
diff --git a/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreateCompany.java b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreateCompany.java new file mode 100644 index 0000000000..c4eddabb6b --- /dev/null +++ b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreateCompany.java @@ -0,0 +1,249 @@ +/** + * + * 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.otherSources; + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; + +import java.util.List; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.DataGraph; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +import org.apache.tuscany.samples.sdo.SdoSampleConstants; +import org.apache.tuscany.sdo.util.SDOUtil; + +/** + * Demonstrates creating a DataObject using the Types defined in a previously generated xsd {@link SdoSampleConstants#COMPANY_XSD} then persisting to a XML file + * This example is useful as a reference for creating valid xml documents that conform to an existing XSD and has been used to create valid XML files for use + * with specification code samples. + * + * <b>Usage:</b> <br> + * This sample can easily be run from within Eclipse as a Java Application if tuscany or + * the sample-sdo project is imported into Eclipse as an existing project. + * <br><br> + * If executing as a standalone application please do the following: + * <br> + * <UL> + * <LI>Include the following jar files on your classpath : + * <UL> + * <LI>SDO API and Tuscany Implementation + * <UL> + * <LI>sdo-api-{version}.jar - SDO API + * <LI>tuscany-sdo-impl-{version}.jar - Tuscany SDO implementation + * </UL> + * </LI> + * <LI>EMF dependencies. + * <UL> + * <LI>emf-common-{version}.jar - some common framework utility and base classes + * <LI>emf-ecore-{version}.jar - the EMF core runtime implementation classes (the Ecore metamodel) + * <LI>emf-ecore-change-{version}.jar - the EMF change recorder and framework + * <LI>emf-ecore-xmi-{version}.jar - EMF's default XML (and XMI) serializer and loader + * <LI>xsd-{version}.jar - the XML Schema model + * </UL> + * </LI> + * </UL> + * + * These jar files can be obtained from directly from Tuscany and EMF projects or from <a + * href="http://wiki.apache.org/ws-data/attachments/Tuscany(2f)TuscanyJava(2f)SDO_Java_Overview/attachments/SDO%20Execution%20Dependencies" + * target="_bank">SDO Execution Dependancies </a> </LI> + * <LI>Execute: <br> + * java org.apache.tuscany.samples.sdo.otherSources.CreateCompany</LI> + * </UL> + * + * @author Robbie Minshall + * + */ +public class CreateCompany { + + /** + * XML file generated for the company DataObject + */ + public static final String COMPANY_GENERATED_XML = "companyGenerated.xml"; + + /** + * XML file generated for the company DataGraph + */ + public static final String COMPANY_DATAGRAPH_GENERATED_XML = "companyDataGraphGenerated.xml"; + + + /** + * Main method. Execute this method in order to run sample + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + + System.out.println("***************************************"); + System.out.println("SDO Sample CreateCompany"); + System.out.println("***************************************"); + System.out.println("Demonstrates creating a DataObject using the Types defined in a previously generated xsd {@link SdoSampleConstants#COMPANY_XSD} then persisting to a XML file"); + System.out.println("***************************************"); + /** + * Use xsd to define model + */ + defineCompanyTypes(); + + /** + * DataObjects can exist on there own or can be associated with a DataGraph. This sample allows you to create and then generate xml for a + * company DataObject That is either associated with a DataGraph or independant + */ + boolean useDataGraph = shouldUseDataGraph(); + + // define these so that they will be scoped appropiately. + DataGraph dataGraph = null; + DataObject company = null; + + if (useDataGraph) { + + /** + * The SDO specification says the following about creating a DataGraph A DataGraph is created by a DAS, which returns either an empty + * DataGraph, or a DataGraph filled with DataObjects. An empty DataGraph can have a root assigned by the createRootObject() methods. + * However, if a previous root DataObject exists then an IllegalStateException is thrown. + * + * In order to create a simply sample which creates a DataGraph without the use of a DAS this sample will use the + * {@link org.apache.tuscany.sdo.util.SDOUtil} class to create a DataObject + */ + + dataGraph = SDOUtil.createDataGraph(); + company = dataGraph.createRootObject(SdoSampleConstants.COMPANY_NAMESPACE, "CompanyType"); + + } else { + + /* + * The following creates a DataObject without a DataGraph + */ + Type companyType = TypeHelper.INSTANCE.getType(SdoSampleConstants.COMPANY_NAMESPACE, "CompanyType"); + // this is equivilent to + // DataObject company = DataFactory.INSTANCE.create(SdoSampleConstants.COMPANY_NAMESPACE, "CompanyType"); + company = DataFactory.INSTANCE.create(companyType); + } + + System.out.println("Populating company DataObject"); + company.setString("name", "ACME"); + company.setString("employeeOfTheMonth", "E0001"); + + System.out.println("Creating Deptartment"); + DataObject depts = company.createDataObject("departments",SdoSampleConstants.COMPANY_NAMESPACE,"DepartmentType"); + + depts.setString("name", "Advanced Technologies"); + depts.setString("location", "NY"); + depts.setString("number", "123"); + + System.out.println("Creating employee John Jones"); + DataObject johnJones = depts.createDataObject("employees",SdoSampleConstants.COMPANY_NAMESPACE, "EmployeeType"); + johnJones.setString("name", "John Jones"); + + johnJones.setString("SN", "E0001"); + + System.out.println("Creating employee Jane Doe"); + DataObject janeDoe = depts.createDataObject("employees",SdoSampleConstants.COMPANY_NAMESPACE, "EmployeeType"); + janeDoe.setString("name", "Jane Doe"); + janeDoe.setString("SN", "E0003"); + + System.out.println("Creating manager A Varone"); + DataObject fVarone = depts.createDataObject("employees",SdoSampleConstants.COMPANY_NAMESPACE, "EmployeeType"); + fVarone.setString("name", "A Varone"); + fVarone.setString("SN", "E0004"); + fVarone.setString("manager", "true"); + System.out.println("DataObject creation completed"); + System.out.println(); + + // print out the generated company DataObject or DataGraph according to user preferences + if (useDataGraph) { + //write the DataGraph to generated xml file + FileOutputStream fos = new FileOutputStream(COMPANY_DATAGRAPH_GENERATED_XML); + System.out.println("Writing company DataGraph to " + COMPANY_DATAGRAPH_GENERATED_XML); + // print the Company DataObject + SDOUtil.saveDataGraph(dataGraph, fos, null); + + // print the company DataGraph to System.out + System.out.println("The xml for the created DataGraph would like : "); + SDOUtil.saveDataGraph(dataGraph, System.out, null); + + } else { + + //write out to a generated xml file + FileOutputStream fos = new FileOutputStream(COMPANY_GENERATED_XML); + System.out.println("Writing company DataObject to " + COMPANY_GENERATED_XML); + // print the Company DataObject + XMLHelper.INSTANCE.save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company", fos); + + // print the company DataObject to System.out + String generatedXml = XMLHelper.INSTANCE.save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company"); + System.out.println("The generated xml for the DataObject would look like : " ); + System.out.println(generatedXml); + } + + } + + /** + * Defines company types using XSD. + * @throws Exception + */ + private static void defineCompanyTypes() throws Exception { + + System.out.println("Defining Types using XSD"); + InputStream is = null; + + System.out.println("Opening input stream to " + SdoSampleConstants.COMPANY_XSD); + is = ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD); + List types = XSDHelper.INSTANCE.define(is, null); + is.close(); + System.out.println("Type definition completed"); + + } + + /** + * Utility method to obtain information from the user about whether or not they would like to use a DataGraph or simply use a DataObject + * + * @return whether or not a DataGraph should be used + * @throws Exception + */ + private static boolean shouldUseDataGraph() throws Exception { + + System.out.print("Create company DataObject associated with a DataGraph {y,n} :"); + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String answer = in.readLine(); + while ((! answer.equalsIgnoreCase("n")) && (! answer.equalsIgnoreCase("y"))) { + + System.out.println(); + System.out.print("Sorry, please enter 'y' or 'n':"); + answer = in.readLine(); + } + System.out.println(); + + if (answer.equalsIgnoreCase("y")) { + return true; + } else { + return false; + } + } + + +} diff --git a/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreatePurchaseOrder.java b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreatePurchaseOrder.java new file mode 100644 index 0000000000..61dfd7eb9d --- /dev/null +++ b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreatePurchaseOrder.java @@ -0,0 +1,174 @@ +/** + * + * 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.otherSources; + +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +import org.apache.tuscany.samples.sdo.SdoSampleConstants; + +/** + * Demonstrates creating a purchaseOrder DataObject from an existing XSD and then + * persisting to disk. Uses previously defined model + * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE} to + * define types then generates a purchase order DataObject and persists to + * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XML_GENERATED}. This + * sample was used to generate valid XML for Fuhwei Lo's paper <A + * HREF="http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/" + * title="Me" onClick="checkLinks(this)">Create and read an XML document based on XML + * Schema</A> + * + * * <b>Usage:</b> <br> + * This sample can easily be run from within Eclipse as a Java Application if tuscany or + * the sample-sdo project is imported into Eclipse as an existing project. + * <br><br> + * If executing as a standalone application please do the following: + * <br> + * <UL> + * <LI>Include the following jar files on your classpath : + * <UL> + * <LI>SDO API and Tuscany Implementation + * <UL> + * <LI>sdo-api-{version}.jar - SDO API + * <LI>tuscany-sdo-impl-{version}.jar - Tuscany SDO implementation + * </UL> + * </LI> + * <LI>EMF dependencies. + * <UL> + * <LI>emf-common-{version}.jar - some common framework utility and base classes + * <LI>emf-ecore-{version}.jar - the EMF core runtime implementation classes (the Ecore metamodel) + * <LI>emf-ecore-change-{version}.jar - the EMF change recorder and framework + * <LI>emf-ecore-xmi-{version}.jar - EMF's default XML (and XMI) serializer and loader + * <LI>xsd-{version}.jar - the XML Schema model + * </UL> + * </LI> + * </UL> + * + * These jar files can be obtained from directly from Tuscany and EMF projects or from <a + * href="http://wiki.apache.org/ws-data/attachments/Tuscany(2f)TuscanyJava(2f)SDO_Java_Overview/attachments/SDO%20Execution%20Dependencies" + * target="_bank">SDO Execution Dependancies </a> </LI> + * <LI>Execute: <br> + * java org.apache.tuscany.samples.sdo.otherSources.CreatePurchaseOrder</LI> + * </UL> + * + * @author Fuhwei Lwo + * @author Robbie Minshall + * @see ReadPurchaseOrder + * @see org.apache.tuscany.samples.sdo.specExampleSection.CreatingXmlFromDataObjects + */ + +public class CreatePurchaseOrder { + + /** + * Defines purchase order types using + * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE} + * + * @throws Exception + */ + private static void definePOTypes() throws Exception { + + InputStream is = ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE); + if (is == null) { + System.out.println("InputStream is null"); + } else { + System.out.println("Obtained Input Stream from resoruce"); + } + XSDHelper.INSTANCE.define(is, null); + is.close(); + } + + /** + * Drives sample + * + * @param args. + * none required. + */ + public static void main(String[] args) { + try { + + System.out.println("***************************************"); + System.out.println("SDO Sample CreatePurchaseOrder"); + System.out.println("***************************************"); + System.out.println("This sample is based upon Fuhwei Lo's paper " + + "http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/" + + " and demonstrates creating a purchaseOrder DataObject from an " + + " existing XSD and then persisting to disk. Uses previously defined model"); + + System.out.println("***************************************"); + + definePOTypes(); + System.out.println("Defined Types using xsd"); + DataObject purchaseOrder = DataFactory.INSTANCE.create(SdoSampleConstants.PO_NAMESPACE, "PurchaseOrderType"); + System.out.println("Created DataObject using DataFactory"); + + 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!"); + System.out.println("Created orderDate, shipTo, billTo and comment properties"); + + 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"); + + OutputStream stream = new FileOutputStream(SdoSampleConstants.PO_XML_GENERATED); + XMLHelper.INSTANCE.save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder", stream); + System.out.println("Created file " + SdoSampleConstants.PO_XML_GENERATED); + } catch (Exception e) { + System.out.println("Sorry an error occured " + e.toString()); + e.printStackTrace(); + } + System.out.println("GoodBye"); + } +} diff --git a/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderCmdLine.java b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderCmdLine.java new file mode 100644 index 0000000000..148f677a5f --- /dev/null +++ b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderCmdLine.java @@ -0,0 +1,398 @@ +/** + * + * 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.otherSources; + +import java.io.*; +import org.apache.tuscany.samples.sdo.SdoSampleConstants; + +/** + * Provides interactive menu based command line interface to modify, save, view purchase order DataObject. + * + * <b>Usage:</b> <br> + * This sample can easily be run from within Eclipse as a Java Application if tuscany or + * the sample-sdo project is imported into Eclipse as an existing project. + * <br><br> + * If executing as a standalone application please do the following: + * <br> + * <UL> + * <LI>Include the following jar files on your classpath : + * <UL> + * <LI>SDO API and Tuscany Implementation + * <UL> + * <LI>sdo-api-{version}.jar - SDO API + * <LI>tuscany-sdo-impl-{version}.jar - Tuscany SDO implementation + * </UL> + * </LI> + * <LI>EMF dependencies. + * <UL> + * <LI>emf-common-{version}.jar - some common framework utility and base classes + * <LI>emf-ecore-{version}.jar - the EMF core runtime implementation classes (the Ecore metamodel) + * <LI>emf-ecore-change-{version}.jar - the EMF change recorder and framework + * <LI>emf-ecore-xmi-{version}.jar - EMF's default XML (and XMI) serializer and loader + * <LI>xsd-{version}.jar - the XML Schema model + * </UL> + * </LI> + * </UL> + * + * These jar files can be obtained from directly from Tuscany and EMF projects or from <a + * href="http://wiki.apache.org/ws-data/attachments/Tuscany(2f)TuscanyJava(2f)SDO_Java_Overview/attachments/SDO%20Execution%20Dependencies" + * target="_bank">SDO Execution Dependancies </a> </LI> + * <LI>Execute: <br> + * java org.apache.tuscany.samples.sdo.otherSources.PurchaseOrderCmdLine</LI> + * </UL> + * @author Robbie Minshall + * @see org.apache.tuscany.samples.sdo.SdoSampleConstants + * @see org.apache.tuscany.samples.sdo.otherSources.PurchaseOrderControl + */ + +public class PurchaseOrderCmdLine { + + private static final int MENU = 1; + + private static final int PRINT_SUMMARY = 2; + + private static final int PRINT_ALL_PROPERTIES = 3; + + private static final int PRINT_BILLTO = 4; + + private static final int PRINT_SHIPTO = 5; + + private static final int APPEND_COMMENT = 6; + + private static final int MODIFY_SHIP_TO = 7; + + private static final int MODIFY_BILL_TO = 8; + + private static final int ADD_ITEM = 9; + + private static final int REMOVE_ITEM = 10; + + private static final int SAVE = 11; + + private static final int SAVE_AS = 12; + + private static final int SHOW_CHANGE_SUMMARY = 13; + + private static final int SHOW_XML_DOCUMENT = 14; + + private static final int QUIT = 15; + + /** + * Drives sample program + * + * @param args. + * args[0] is optional xsdFilename, args[1] is optional xmlFileName + */ + public static void main(String[] args) { + + System.out.println("***************************************"); + System.out.println("SDO Purchase Order Sample Command Line Interface"); + System.out.println("***************************************"); + System.out.println("Provides an interactive menu to play with purchase order DataObjects"); + System.out.println("***************************************"); + + printUsage(); + + PurchaseOrderControl poc = null; + String xsdFileName = null; + String xmlFileName = null; + + // see if we should load an xsd file or if we should use a resource + if ((args.length >= 1)) { + xsdFileName = args[0]; + } + + // see if we should load an xml file or if we should use a resource + if ((args.length >= 2)) { + xmlFileName = args[1]; + } + try { + poc = new PurchaseOrderControl(xsdFileName, xmlFileName); + } catch (Exception e) { + System.out.println("Sorry could not initialize PurchaseOrderControl. Error: " + e.toString()); + e.printStackTrace(); + return; + } + boolean inOperation = true; + try { + + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + int command = QUIT; + + printMenu(); + while (inOperation) { + System.out.print(">>> "); + try { + command = Integer.valueOf(in.readLine()).intValue(); + } catch (Exception e) { + System.out.println("Invalid option, please try again."); + command = MENU; + + } + switch (command) { + case MENU: + printMenu(); + + break; + case PRINT_SUMMARY: + poc.printPurchaseOrderSummary(); + break; + case PRINT_ALL_PROPERTIES: + try { + poc.printPurchaseOrderProperties(); + } catch (Exception e) { + System.out.println("Sorry the following error was received when printing all properties " + e.toString()); + e.printStackTrace(); + } + break; + case PRINT_BILLTO: + poc.printBillTo(); + break; + case PRINT_SHIPTO: + poc.printShipTo(); + break; + case APPEND_COMMENT: + try { + + System.out.println("Append Comment: "); + poc.appendComment(in.readLine()); + } catch (Exception e) { + System.out.println("Sorry unexpected exception occured appending comment" + e.toString()); + e.printStackTrace(); + } + + break; + case MODIFY_SHIP_TO: + try { + + System.out.println("Modify Ship To ( press enter to leave unchanged )"); + poc.printShipTo(); + System.out.print("Name: "); + String name = in.readLine(); + System.out.println(); + + System.out.print("Street: "); + String street = in.readLine(); + System.out.println(); + + System.out.print("City: "); + String city = in.readLine(); + System.out.println(); + + System.out.print("State: "); + String state = in.readLine(); + System.out.println(); + + System.out.print("Zip: "); + String zip = in.readLine(); + if ((zip != null) && (!zip.equals(""))) { + selectSetDecimalOption(in, poc); + } + System.out.println(); + + poc.modifyShipTo(name, street, city, state, zip); + } catch (Exception e) { + System.out.println("Sorry unexpected exception occured modifying ShipTo address :" + e.toString()); + e.printStackTrace(); + } + + break; + case MODIFY_BILL_TO: + try { + + System.out.println("Modify Bill To ( press enter to leave unchanged )"); + poc.printBillTo(); + System.out.print("Name: "); + String name = in.readLine(); + System.out.println(); + + System.out.print("Street: "); + String street = in.readLine(); + System.out.println(); + + System.out.print("City: "); + String city = in.readLine(); + System.out.println(); + + System.out.print("State: "); + String state = in.readLine(); + System.out.println(); + + System.out.print("Zip: "); + String zip = in.readLine(); + if ((zip != null) && (!zip.equals(""))) { + selectSetDecimalOption(in, poc); + } + System.out.println(); + + poc.modifyBillTo(name, street, city, state, zip); + } catch (Exception e) { + System.out.println("Sorry unexpected exception occured when modifying address :" + e.toString()); + e.printStackTrace(); + } + + break; + + case ADD_ITEM: + + try { + System.out.println("Add item to Purchase Order"); + System.out.print("Product Number: "); + String productNumber = in.readLine(); + System.out.println(); + + System.out.print("Product Name: "); + String productName = in.readLine(); + System.out.println(); + + System.out.print("Quantity: "); + int quantity = Integer.valueOf(in.readLine()).intValue(); + System.out.println(); + + System.out.print("Price: "); + double price = Double.valueOf(in.readLine()).doubleValue(); + System.out.println(); + + System.out.print("Comment: "); + String comment = in.readLine(); + System.out.println(); + + poc.addItem(productNumber, productName, price, quantity, comment); + } catch (Exception e) { + System.out.println("Sorry unexpected exception occured when adding item :" + e.toString()); + e.printStackTrace(); + } + + break; + case REMOVE_ITEM: + try { + System.out.print("Please enter the index of the item you would like to remove :"); + String index = in.readLine(); + poc.removeItem(Integer.valueOf(index).intValue()); + + } catch (Exception e) { + System.out.println("Sorry there was an error when remove item : " + e.toString()); + e.printStackTrace(); + + } + break; + case SAVE: + try { + poc.save(); + } catch (IOException e) { + System.out.println("Sorry an error was received : " + e.toString()); + e.printStackTrace(); + } + break; + case SAVE_AS: + System.out.print("FileName:"); + String fileName = in.readLine(); + try { + poc.saveAs(fileName); + System.out.println("File saved to " + fileName); + } catch (IOException e) { + System.out.println("Sorry an error was received : " + e.toString()); + e.printStackTrace(); + } + break; + case SHOW_CHANGE_SUMMARY: + try { + + poc.printChangeSummary(); + } catch (Exception e) { + System.out.println("Sorry exception caught when accessing change summary : " + e.toString()); + e.printStackTrace(); + } + + break; + case SHOW_XML_DOCUMENT: + try { + System.out.println("XMLDocument representing purchase order: "); + System.out.println(poc.getXMLString()); + } catch (Exception e) { + System.out.println("Sorry there was an erorr when printing the XMLDocument :" + e.toString()); + e.printStackTrace(); + } + break; + case QUIT: + inOperation = false; + break; + default: + System.out.println("Sorry I did not understand the command"); + printMenu(); + } + } + System.out.println("Goodbye"); + + } catch (Exception e) { + System.out.println("Unexpected exception occured during execution: " + e.toString()); + e.printStackTrace(); + } + + } + + private static void selectSetDecimalOption(BufferedReader in, PurchaseOrderControl poc) { + try { + + System.out.println("SDO provides a number of methods to set properties on a DataObject"); + System.out.println("Please select the method that you would like to use in order to set decimal values"); + System.out.println("1. dataObject.set(. . . )"); + System.out.println("2. dataObject.setString(. . . )"); + System.out.println("3. dataObject.setDouble(. . . )"); + System.out.print(">>>"); + + poc.setDecimalPropertyMethod(Integer.valueOf(in.readLine()).intValue()); + } catch (Exception e) { + System.out.println("invalid option - oh well"); + } + + } + + private static void printUsage() { + System.out.println("***************************************"); + System.out.println("java org.apache.tuscany.samples.sdo.otherSources.PurchaseOrderCmdLine <xsdFileName> <xmlFileName>"); + System.out.println("If xsdFileName and xmlFileName are not specified " + SdoSampleConstants.PO_XSD_RESOURCE + " and " + + SdoSampleConstants.PO_XML_RESOURCE + " will be used as resources"); + System.out.println("Specify null if you wish to use the appropiate resource from the jar rather specifying a fileName"); + System.out.println("***************************************"); + } + + private static void printMenu() { + System.out.println("***************************************"); + System.out.println("Purchase Order Control Menu"); + System.out.println(MENU + ". MENU"); + System.out.println(PRINT_SUMMARY + ". PRINT_SUMMARY"); + System.out.println(PRINT_ALL_PROPERTIES + ". PRINT_ALL_PROPERTIES"); + System.out.println(PRINT_BILLTO + ". PRINT_BILLTO"); + System.out.println(PRINT_SHIPTO + ". PRINT_SHIPTO"); + System.out.println(APPEND_COMMENT + ". APPEND_COMMENT"); + System.out.println(MODIFY_SHIP_TO + ". MODIFY_SHIP_TO"); + System.out.println(MODIFY_BILL_TO + ". MODIFY_BILL_TO"); + System.out.println(ADD_ITEM + ". ADD_ITEM"); + System.out.println(REMOVE_ITEM + ". REMOVE_ITEM"); + System.out.println(SAVE + ". SAVE"); + System.out.println(SAVE_AS + ". SAVE_AS"); + System.out.println(SHOW_CHANGE_SUMMARY + ". SHOW_CHANGE_SUMMARY"); + System.out.println(SHOW_XML_DOCUMENT + ". SHOW_XML_DOCUMENT"); + System.out.println(QUIT + ". QUIT"); + System.out.println("***************************************"); + } +} diff --git a/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderControl.java b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderControl.java new file mode 100644 index 0000000000..9a5a3279f6 --- /dev/null +++ b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderControl.java @@ -0,0 +1,496 @@ +/** + * + * 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.otherSources; + +import java.io.*; + +import java.util.List; +import java.math.BigDecimal; + +import commonj.sdo.DataObject; +import commonj.sdo.ChangeSummary; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import commonj.sdo.helper.CopyHelper; + +import org.apache.tuscany.samples.sdo.SdoSampleConstants; + +import org.apache.tuscany.samples.sdo.specCodeSnippets.*; + +/** + * Provides operational API for purchase order sample for SDO. It is used by + * {@link PurchaseOrderCmdLine} for an interactive sample. Often relies upon + * methods that are located within the {@link org.apache.tuscany.samples.sdo.otherSources} package. + * + * @author Robbie Minshall + * @see org.apache.tuscany.samples.sdo.otherSources.PurchaseOrderCmdLine + * + */ +public class PurchaseOrderControl { + + // there are a number of ways to set properties + // these constants define which mechanism the user + // would like to use. + public static final int SET_DECIMAL_PROPERTY_VIA_SET = 1; + + public static final int SET_DECIMAL_PROPERTY_VIA_SET_STRING = 2; + + public static final int SET_DECIMAL_PROPERTY_VIA_SET_DOUBLE = 3; + + // local variable to determine which of the above mechanisms to use + private int decimalPropertyMethod = SET_DECIMAL_PROPERTY_VIA_SET_STRING; + + // these files can be optionally used to specify where to locate xsd and xml + // to define types and populate DataObject + // if these are null will use the resources above + private String xmlFileName; + + private String xsdFileName; + + // root DataObject + private DataObject purchaseOrder; + + /** + * Uses resources files included in jar file to define types (using xsd), and + * populate DataObjects (xml) + * + * @throws Exception + */ + public PurchaseOrderControl() throws Exception { + this(null, null); + } + + /** + * Uses files on the file system to define types (using xsd), and populate + * DataObjects (xml) + * + * @param xsdFileName + * location of po.xsd + * @param xmlFileName + * location of xml to populate DataObject (for example po.xml) + * @throws Exception + */ + public PurchaseOrderControl(String xsdFileName, String xmlFileName) throws Exception { + this.xsdFileName = xsdFileName; + this.xmlFileName = xmlFileName; + + // define purchase order types for SDO + definePurchaseOrderTypes(); + // read in existing xml and populate DataObjects + readPurchaseOrderXml(); + } + + /** + * Method to take XSD (w3c) to define SDO types. This is static so that it can be + * used as a helper method for some simpler examples Uses either fileName used to + * construct this class or will use resource ( po.xsd ) included within jar file + */ + private void definePurchaseOrderTypes() throws Exception { + + if ((xsdFileName == null) || (xsdFileName.equals("")) || (xsdFileName.equalsIgnoreCase("null"))) { + + // use simple example to define type from resource + CreateDataObjectFromXsdAndXmlFiles.definePurchaseOrderTypeUsingXsdResource(); + + } else { + System.out.println("Using file to access xsd in order to define types"); + try { + FileInputStream fis = new FileInputStream(xsdFileName); + XSDHelper.INSTANCE.define(fis, null); + fis.close(); + System.out.println("Sucessfully used " + xsdFileName + " to define types"); + + } catch (Exception e) { + System.out.println("Could not access file " + xsdFileName); + e.printStackTrace(); + throw e; + } + + } + } + + /** + * Reads in xml and populates DataGraph. + * + * Will set the purchaseOrder to the root object Uses either fileName used to + * construct this class or will use resource ( po.xml ) included within jar file + */ + public void readPurchaseOrderXml() throws Exception, FileNotFoundException { + + if ((xmlFileName == null) || (xmlFileName.equals("")) || (xmlFileName.equalsIgnoreCase("null"))) { + + purchaseOrder = CreateDataObjectFromXsdAndXmlFiles.createPurchaseOrderDataObjectUsingXmlResource(); + } else { + try { + + System.out.println("Using file to access xml to populate DataObjects"); + FileInputStream fis = new FileInputStream(xmlFileName); + XMLDocument xmlDoc = XMLHelper.INSTANCE.load(fis); + purchaseOrder = xmlDoc.getRootObject(); + System.out.println("Sucessfully used file to populate DataObjects"); + fis.close(); + } catch (Exception e) { + System.out.println("Could not open and use file " + xmlFileName); + e.printStackTrace(); + throw e; + } + } + + } + + /** + * Appends new comment to comment property of purchase order Accesses comment + * property by name + * + * @param newComment + */ + public void appendComment(String newComment) { + String oldComment = (String) purchaseOrder.get("comment"); + setComment(oldComment + "-" + newComment); + } + + /** + * Sets comment property on purchase order by accessing property by name + * + * @param comment + */ + public void setComment(String comment) { + // set using path info + purchaseOrder.set("comment", comment); + } + + /** + * Modifies complex address type for billTo. If any parameter is null it will not + * be modified + * + * @param name + * @param street + * @param city + * @param state + * @param zip + */ + public void modifyBillTo(String name, String street, String city, String state, String zip) { + + DataObject billTo = purchaseOrder.getDataObject("billTo"); + modifyAddress(billTo, name, street, city, state, zip); + } + + /** + * Modifies complex address type for shipTo. If any parameter is null it will not + * be modified + * + * @param name + * @param street + * @param city + * @param state + * @param zip + */ + public void modifyShipTo(String name, String street, String city, String state, String zip) { + + DataObject shipTo = purchaseOrder.getDataObject("shipTo"); + modifyAddress(shipTo, name, street, city, state, zip); + } + + /** + * Modifies complex address type ( used for either billTo or shipTo ) If any + * parameter is null it will not be modified + * + * @param name + * @param street + * @param city + * @param state + * @param zip + */ + private void modifyAddress(DataObject dataObject, String name, String street, String city, String state, String zip) { + if ((name != null) && (!name.equals(""))) { + dataObject.set("name", name); + } + if ((street != null) && (!street.equals(""))) { + dataObject.set("street", street); + } + if ((city != null) && (!city.equals(""))) { + dataObject.set("city", city); + } + if ((state != null) && (!state.equals(""))) { + dataObject.set("state", state); + } + if ((zip != null) && (!zip.equals(""))) { + // there are a number of ways to set a decimal property + // so in order to demonstrate the various output results + // the user can determine which manner to do so + setDecimalPropertyOnDataObject(dataObject, "zip", zip); + } + } + + /** + * Adds an additional item to the items list of the item property on purchase + * order DataObject + * + * @param partNumber + * @param productName + * @param price + * @param quantity + * @param comment + */ + public void addItem(String partNumber, String productName, double price, int quantity, String comment) { + // get items dataObject + DataObject items = purchaseOrder.getDataObject("items"); + + // create a new child data object + DataObject newItem = items.createDataObject("item"); + newItem.setString("partNum", partNumber); + newItem.setString("productName", productName); + newItem.setInt("quantity", quantity); + newItem.setDouble("price", price); + newItem.setString("comment", comment); + + } + + /** + * Removes a particular item from the items list. Obtains the List associated + * with the item property and removes by index + * + * @param index + */ + public void removeItem(int index) { + // TODO: this is not working due to java.lang.ClassCastException: + // org.eclipse.emf.ecore.util.EcoreEList$Dynamic incompatible with + // commonj.sdo.DataObject + // access a DataObject by the index and then remove it + DataObject items = purchaseOrder.getDataObject("items"); + List itemList = items.getList("item"); + itemList.remove(index); + } + + /** + * Saves modified purchase order DataObject to original xml used to populate it + * If resource packaged within jar is used will create a new file on file system + * + * @throws IOException + */ + public void save() throws IOException { + if (this.xmlFileName != null) { + saveAs(xmlFileName); + } else { + System.out.println("Sorry, can not save to resource within jar, will create file called " + SdoSampleConstants.PO_XML_RESOURCE + + " and save"); + saveAs(SdoSampleConstants.PO_XML_RESOURCE); + } + } + + /** + * Saves modified purchaseOrder DataObject to file + * + * @param fileName. + * Location to save file to save DataObject to + * @throws IOException + */ + public void saveAs(String fileName) throws IOException { + OutputStream stream = new FileOutputStream(fileName); + XMLHelper.INSTANCE.save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder", stream); + System.out.println("Saved to " + fileName); + } + + // PRINTING METHODS TO SYSTEM.OUT + + /** + * Prints purchase order summary to System.out + */ + + public void printChangeSummary() { + + // TODO: change summary is not currently working + ChangeSummary changeSummary = getChangeSummary(); + boolean logging = changeSummary.isLogging(); + if (!logging) { + System.out.println("Change logging is disabled"); + } else { + System.out.println("Change logging is enabled"); + } + // TODO: complete this method + + } + + /** + * Uses simple sample PrintPropertiesOfDataObject + */ + public void printPurchaseOrderProperties() throws Exception { + // use previously created method from simple sample + PrintPropertiesOfDataObject.printDataObjectProperties(purchaseOrder); + } + + /** + * Accesses key properties via name and prints to System.out + * + */ + public void printPurchaseOrderSummary() { + // use previously created method from simple sample + // for an example of accessing properties by name see + // AccessDataObjectPropertiesByName or + // the method below printAddressInfo + AccessDataObjectPropertiesByName.printPurchaseOrderSummary(purchaseOrder); + } + + /** + * Accesses properties of USAddress Type by name and prints to System.out + * + * @param dataObject. + * Either shipTo and billTo property of purchase order + */ + private void printAddressInfo(DataObject dataObject) { + System.out.println(" name: " + dataObject.get("name")); + System.out.println(" street: " + dataObject.get("street")); + System.out.println(" city: " + dataObject.get("city")); + System.out.println(" state: " + dataObject.get("state")); + System.out.println(" zip: " + dataObject.get("zip")); + } + + /** + * Prints properties of shipTo + * + */ + public void printBillTo() { + DataObject billTo = purchaseOrder.getDataObject("billTo"); + printAddressInfo(billTo); + } + + /** + * Prints properties of billTo + * + */ + public void printShipTo() { + DataObject shipTo = purchaseOrder.getDataObject("shipTo"); + printAddressInfo(shipTo); + } + + // GETTERS AND SETTERS + + /** + * Sets the mechanism to set decimal property for zip code Decimals can be set in + * a number of ways. This scenario controls how this class will set the zip code + * when modifying address + */ + public void setDecimalPropertyMethod(int i) { + decimalPropertyMethod = i; + } + + /** + * Gets the mechanism used to zip decimal property for the zip code of an address + * + * @return + */ + public int getDecimalPropertyMethod() { + return decimalPropertyMethod; + } + + // METHODS TO GET AND COPY DATAOBJECTS + /** + * @return purchaseOrder DataObject + */ + public DataObject getPurchaseOrder() { + return purchaseOrder; + } + + /** + * + * @return deep copy of the purchase order DataObject + */ + public DataObject getDeepCopyPurchaseOrder() { + return CopyHelper.INSTANCE.copy(purchaseOrder); + + } + + /** + * + * @return shallow copy of the purchase order DataObject + */ + public DataObject getShallowCopyPurchaseOrder() { + return CopyHelper.INSTANCE.copyShallow(purchaseOrder); + } + + /** + * Currently this does not work + * + * @return Change summary for purchaseOrder + * + */ + public ChangeSummary getChangeSummary() { + // TODO: why is the data graph null + return purchaseOrder.getDataGraph().getChangeSummary(); + } + + /** + * + * @return XMLDocument that represents current purchase order DataObject + */ + public XMLDocument getXMLDocuement() { + return XMLHelper.INSTANCE.createDocument(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder"); + } + + /** + * + * @return String xml representation of current purcahse order DataObject + */ + public String getXMLString() { + // alternativly could use the following + // return XMLHelper.INSTANCE.createDocument(purchaseOrder, PO_NAMESPACE, + // "purchaseOrder").toString(); + return XMLHelper.INSTANCE.save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder"); + } + + // PRIVATE HELPER METHODS + + /** + * Uses a variety of ways to set a decimal property on a DataObject + * + * @param dataObject + * @param propertyName + * @param propertyValue + */ + private void setDecimalPropertyOnDataObject(DataObject dataObject, String propertyName, String propertyValue) { + // since the type specified in the xsd is of type decimal when we + // wish to just use the set method one must construct a BigDecimal or + // else a ClassCastException will occur + // alternativly one could call dataObject.setString(zip) or + // dataObject.setDouble( Double.valueOf(zip)) + switch (decimalPropertyMethod) { + + case (SET_DECIMAL_PROPERTY_VIA_SET): { + dataObject.set(propertyName, new BigDecimal(propertyValue)); + break; + } + case (SET_DECIMAL_PROPERTY_VIA_SET_DOUBLE): { + dataObject.setDouble(propertyName, Double.valueOf(propertyValue).doubleValue()); + break; + } + case (SET_DECIMAL_PROPERTY_VIA_SET_STRING): { + dataObject.setString(propertyName, propertyValue); + break; + } + default: { + dataObject.setString(propertyName, propertyValue); + } + + }// end of switch + + } +} diff --git a/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/ReadPurchaseOrder.java b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/ReadPurchaseOrder.java new file mode 100644 index 0000000000..7f92b4acde --- /dev/null +++ b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/ReadPurchaseOrder.java @@ -0,0 +1,143 @@ +/** + * + * 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.otherSources; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.List; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +import org.apache.tuscany.samples.sdo.SdoSampleConstants; + +/** + * Reads purchase order DataObject from XML, based upon Fuhwei Lo's paper <A + * HREF="http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/" + * title="Me" onClick="checkLinks(this)">Create and read an XML document based on XML + * Schema</A>. Uses file + * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XML_GENERATED} + * previously generated by {@link CreatePurchaseOrder} to populate purchase order + * DataObject + * + * <b>Usage:</b> <br> + * This sample can easily be run from within Eclipse as a Java Application if tuscany or + * the sample-sdo project is imported into Eclipse as an existing project. + * <br><br> + * If executing as a standalone application please do the following: + * <br> + * <UL> + * <LI>Include the following jar files on your classpath : + * <UL> + * <LI>SDO API and Tuscany Implementation + * <UL> + * <LI>sdo-api-{version}.jar - SDO API + * <LI>tuscany-sdo-impl-{version}.jar - Tuscany SDO implementation + * </UL> + * </LI> + * <LI>EMF dependencies. + * <UL> + * <LI>emf-common-{version}.jar - some common framework utility and base classes + * <LI>emf-ecore-{version}.jar - the EMF core runtime implementation classes (the Ecore metamodel) + * <LI>emf-ecore-change-{version}.jar - the EMF change recorder and framework + * <LI>emf-ecore-xmi-{version}.jar - EMF's default XML (and XMI) serializer and loader + * <LI>xsd-{version}.jar - the XML Schema model + * </UL> + * </LI> + * </UL> + * + * These jar files can be obtained from directly from Tuscany and EMF projects or from <a + * href="http://wiki.apache.org/ws-data/attachments/Tuscany(2f)TuscanyJava(2f)SDO_Java_Overview/attachments/SDO%20Execution%20Dependencies" + * target="_bank">SDO Execution Dependancies </a> </LI> + * <LI>Execute: <br> + * java org.apache.tuscany.samples.sdo.otherSources.ReadPurchaseOrder</LI> + * </UL> + * + * @author Fuhwei Lwo + * @author Robbie Minshall + */ +public class ReadPurchaseOrder { + + private static void definePOTypes() throws Exception { + InputStream is = ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE); + if (is == null) { + System.out.println("InputStream is null"); + } else { + System.out.println("Obtained Input Stream from resource"); + } + XSDHelper.INSTANCE.define(is, null); + is.close(); + } + + public static void main(String[] args) { + System.out.println("***************************************"); + System.out.println("SDO Sample ReadPurchaseOrder"); + System.out.println("***************************************"); + System.out.println("This sample is based upon Fuhwei Lo's paper http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/"); + System.out.println("previously generated by CreatePurchaseOrder sample to populate purchase order DataObject"); + + System.out.println("***************************************"); + + try { + definePOTypes(); + + FileInputStream fis = null; + try { + fis = new FileInputStream(SdoSampleConstants.PO_XML_GENERATED); + } catch (Exception e) { + System.out.println("Sorry an error occcured, please run CreatePurchaseOrder sample first"); + System.out.println("Exception : " + e.toString()); + e.printStackTrace(); + return; + } + + XMLDocument xmlDoc = XMLHelper.INSTANCE.load(fis); + + 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")); + } // for + } catch (Exception e) { + System.out.println("Sorry an error was encountered " + e.toString()); + e.printStackTrace(); + } + System.out.println("GoodBye"); + } +} diff --git a/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/package.html b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/package.html new file mode 100644 index 0000000000..a1b1eb6dff --- /dev/null +++ b/sandbox/jboynes/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/package.html @@ -0,0 +1,40 @@ +<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>package information</title> +</head> +<body> + +Provides examples from sources other than the specification. These examples are from whitepapers, + or are custom examples designed to show SDO in a more elegant light than the specification. They + also include basic interactive examples, and usefull scnearios not outlined in the specification. + The user is encouraged to modify and execute these code examples. + +<h2>Related Documentation</h2> + +For overviews, tutorials, examples, guides, and tool documentation, please see: +<ul> + <li><a href="http://download.boulder.ibm.com/ibmdl/pub/software/dw/specs/ws-sdo/SDO_Specification_Java_V2.01.pdf">SDO Specification</a></li> + <li><a href="http://www-128.ibm.com/developerworks/webservices/library/ws-sdoxmlschema/">Create and read an XML document based on XML Schema</a></li> +</ul> + +</body> +</html>
\ No newline at end of file |