You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ro...@apache.org on 2006/08/16 15:56:32 UTC

svn commit: r431902 [2/3] - in /incubator/tuscany/java/samples/sdo: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/samples/ src/main/java/org/apache/tusca...

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,151 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specCodeSnippets;
+
+import java.util.List;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+
+/**
+ * Demonstrates accessing a created DataObject's properties by name.
+ * 
+ * This sample is from the <a href="http://incubator.apache.org/tuscany"
+ * target="_blank"> Apache Tuscany</a> project. It was written to help users
+ * understand and experiement with SDO. It is based upon code snippets contained
+ * within, and is meant for use with, and reference to the <a
+ * href="http://www.osoa.org/download/attachments/791/SDO_Specification_Java_V2.01.pdf?version=1"
+ * target="_bank">SDO Specification</a>.
+ * 
+ * <br>
+ * <br>
+ * <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.specCodeSnippets.AccessDataObjectPropertiesByName</LI>
+ * </UL>
+ * 
+ * @author Robbie Minshall
+ */
+public class AccessDataObjectPropertiesByName {
+
+    /**
+     * Prints a subset of PurchaseOrder properties to System.out
+     * 
+     * @param purchaseOrder.
+     *            DataObject defined by Types in
+     *            {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE}
+     */
+    public static void printPurchaseOrderSummary(DataObject purchaseOrder) {
+
+        // example accessing properties via property names
+        System.out.println("Purchase Order: ");
+        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"));
+
+        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("            Part num: " + item.get("partNum"));
+            System.out.println("            Product name: " + item.get("productName"));
+        }
+    }
+
+    /**
+     * Prints properties of a purchase order DataObject( properties are defined in
+     * the xsd
+     * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE} and
+     * populated by xml
+     * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XML_RESOURCE} )
+     * 
+     * @param args.
+     *            No parameters required.
+     */
+    public static void main(String[] args) {
+
+        // information
+        System.out.println("***************************************");
+        System.out.println("SDO Sample AccessDataObjectPropertiesByName");
+        System.out.println("***************************************");
+        System.out.println("This sample will access a DataObject properties by name");
+        System.out.println("***************************************");
+
+        // create a DataObejct
+        DataObject purchaseOrder = null;
+        try {
+            XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);           
+            purchaseOrder = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
+            System.out.println("DataObject created");
+        } catch (Exception e) {
+            System.out.println("Error creating DataObject " + e.toString());
+            e.printStackTrace();
+            return;
+        }
+
+        // start of sample
+        try {
+            System.out.println("Accessing properties by name");
+            printPurchaseOrderSummary(purchaseOrder);
+        } catch (Exception e) {
+            System.out.println("Sorry there was an error accessing properties by name " + e.toString());
+            e.printStackTrace();
+        }
+        System.out.println("GoodBye");
+        // end of sample
+    }
+
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,116 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specCodeSnippets;
+
+import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * Demonstrats accessing a created DataObject's properties using xPath.
+ * 
+ * This sample is from the <a href="http://incubator.apache.org/tuscany"
+ * target="_blank"> Apache Tuscany</a> project. It was written to help users
+ * understand and experiement with SDO. It is based upon code snipets contained
+ * within, and is meant for use with, and reference to the <a
+ * href="http://download.boulder.ibm.com/ibmdl/pub/software/dw/specs/ws-sdo/SDO_Specification_Java_V2.01.pdf"
+ * target="_bank">SDO Specification</a>. <br>
+ * <br>
+ * It is worth noting that the Examples section of the specification, and the
+ * {@link org.apache.tuscany.samples.sdo.specExampleSection.AccessingDataObjectsUsingXPath}
+ * use unpure xpath expression. This sample attempts to demonstrate a more appropiate
+ * subset of xPath operations.<br>
+ * <br>
+ * <b>Usage:</b> <br>
+ * Include the following on your classpath :
+ * codegen-2.2.0-SNAPSHOT.jar,codegen-ecore-2.2.0-SNAPSHOT.jar,common-2.2.0-SNAPSHOT.jar,ecore-2.2.0-SNAPSHOT.jar,ecore-change-2.2.0-SNAPSHOT.jar,ecore-xmi-2.2.0-SNAPSHOT.jar,sdo-api-SNAPSHOT.jar,tuscany-sdo-impl-SNAPSHOT.jar,xsd-2.2.0-SNAPSHOT.jar,sdo-samples-standAlone-1.0-SNAPSHOT.jar
+ * <br>
+ * Execute: java
+ * org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectUsingValidXPath
+ * 
+ * @author Robbie Minshall
+ */
+public class AccessDataObjectUsingValidXPath {
+
+    /**
+     * Prints a subset of item properties to System.out where the individual item was
+     * accessed using an xPath expression
+     * 
+     * @param purchaseOrder.
+     *            DataObject defined by Types in
+     *            {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE}
+     */
+    public static void accessDataObjectUsingXPath(DataObject purchaseOrder) {
+
+        System.out.println("Accessing individual item from list using xpath");
+        // TODO: use variety of xpath expressions such as items/item[1]
+        // TODO: add to junit test cases for test cases above
+        DataObject item = purchaseOrder.getDataObject("items/item[1]");
+        System.out.println("Item toString : " + item.toString());
+
+        System.out.println("Item name:" + item.get("productName"));
+        System.out.println("Part num: " + item.get("partNum"));
+
+    }
+
+    /**
+     * Accesses and modifies properties of a purchase order DataObject using xPath(
+     * properties are defined in the xsd
+     * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE} and
+     * populated by xml
+     * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XML_RESOURCE} )
+     * 
+     * @param args.
+     *            No parameters required.
+     */
+    public static void main(String[] args) {
+
+        // information
+        System.out.println("***************************************");
+        System.out.println("SDO Sample AccessDataObjectUsingValidXPath");
+        System.out.println("***************************************");
+        System.out.println("Demonstrats accessing a created DataObject's properties using xPath.");
+        System.out.println("***************************************");
+
+        // create a DataObejct
+        DataObject purchaseOrder = null;
+        try {
+            XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+            purchaseOrder = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
+            System.out.println("DataObject created");
+        } catch (Exception e) {
+            System.out.println("Error creating DataObject " + e.toString());
+            e.printStackTrace();
+            return;
+        }
+
+        // start of sample
+        try {
+
+            accessDataObjectUsingXPath(purchaseOrder);
+        } catch (Exception e) {
+            System.out.println("Sorry there was an error accessing properties by name " + e.toString());
+            e.printStackTrace();
+        }
+        System.out.println("GoodBye");
+        // end of sample
+    }
+
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,161 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specCodeSnippets;
+
+import java.util.List;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.XMLHelper;
+
+/**
+ * Demonstrates creating a DataObject from a String of XML.
+ * 
+ * The following sample is from the <a href="http://incubator.apache.org/tuscany"
+ * target="_blank"> Apache Tuscany</a> project. It was written to help users
+ * understand and experiement with SDO. It is based upon code snippets contained
+ * within, and is meant for use with, and reference to the <a
+ * href="http://www.osoa.org/download/attachments/791/SDO_Specification_Java_V2.01.pdf?version=1"
+ * target="_bank">SDO Specification</a>. Specifically this sample is based upon section titled "Creating DataObjects from XML documents" <br>
+ * <br>
+ * <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.specCodeSnippets.CreateDataObjectFromXmlString</LI>
+ * </UL>
+ * 
+ * @author Robbie Minshall
+ */
+public class CreateDataObjectFromXmlString {
+
+    /**
+     * String representing a PurchaseOrder in XML format
+     */
+    public static final String XML_STRING = "<purchaseOrder orderDate='1999-10-20'>" + " <shipTo country='US'>" + " <name>Alice Smith</name>"
+            + " <street>123 Maple Street</street>" + " <city>Mill Valley</city>" + " <state>PA</state>" + " <zip>90952</zip>" + "</shipTo>"
+            + "</purchaseOrder>";
+
+    /**
+     * Creates a DataObject from an Xml String
+     * 
+     * @return
+     */
+    public static DataObject createDataObjectFromXmlString() {
+
+        // TODO: do this with and without defining the schema
+        DataObject po = XMLHelper.INSTANCE.load(XML_STRING).getRootObject();
+        System.out.println("DataObject has been created : " + po.toString());
+        return po;
+    }
+
+    /**
+     * @param args
+     *            None required
+     */
+    public static void main(String[] args) {
+
+        // information
+        System.out.println("***************************************");
+        System.out.println("SDO Sample CreateDataObjectFromXmlString");
+        System.out.println("***************************************");
+        System.out.println("Demonstrats creating a DataObject from a String of XML, based upon section titled 'Creating DataObjects from XML documents'");
+        System.out.println("***************************************");
+
+        // sample
+        try {
+
+            System.out.println("Use the following XML String: " + XML_STRING);
+            System.out.println("Creating DataObject");
+            DataObject po = createDataObjectFromXmlString();
+            System.out.println("The following DataObject sucessfully created from XML String");
+
+            System.out.println(XMLHelper.INSTANCE.save(po, "http://example.com/purchaseOrder", "purchaseOrder"));
+
+            /*
+             * Without a Type definition accessing a DataObject is slightly more
+             * difficult. This is because without a Type definition SDO does not know
+             * the intended multiplicity of properties. Currently the Tuscany
+             * implementation assumes that elements and attributes are lists. There
+             * is some discussion (SDO-3, also mentioned in SDO-22) about adding
+             * annotations to the XML (sdo:many="false") to control the indended
+             * multiplicity of DataObjects created without a model.
+             * 
+             * The following code will not work when a model/schema is not defined
+             * shipTo = purchaseOrder.getDataObject("shipTo"); assertEquals("testing
+             * ship to name", shipTo.getString("name"), "Alice Smith");
+             * assertEquals("testing ship to zip", shipTo.getString("zip"), "90952");
+             */
+
+            System.out.println("Programatically access content of DataObject - getting name of the person this is getting shipped to");
+            // access the shipTo DataObject
+            List shipToList = po.getList("shipTo");
+            DataObject shipTo = (DataObject) shipToList.get(0);
+            // access the name DataObject
+
+            /*
+             * This is currently quite cumbersome. In future specifications accessing
+             * the name element will be simplier and the user could simply execute:
+             * List nameList = shipTo.getList("name"); String actualName = (String)
+             * nameList.get(0);
+             * 
+             * Or if name is an attribute ("<shipTo country='US' name='Alice
+             * Smith'>") simply: String actualName = shipTo.getString("name");
+             * 
+             * There are currently more elegant means to perform this task using the xPath support
+             */
+            List nameList = shipTo.getList("name");
+            DataObject name = (DataObject) nameList.get(0);
+            // access the contents of the name DataObject
+            List textList = name.getList("text");
+            String actualName = (String) textList.get(0);
+            System.out.println("Name being shipped to: " + actualName);
+
+        } catch (Exception e) {
+            System.out.println("Sorry, exception caught when creating DataObject : " + e.toString());
+            e.printStackTrace();
+        }
+        // end of sample
+        System.out.println("GoodBye");
+    }
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,193 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specCodeSnippets;
+
+import java.io.InputStream;
+
+import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+
+/**
+ * Demonstrates defining Types by using a predefined xsd resource, and populating a DataObject by using a previously created xml file.
+ * 
+ * The following sample is from the <a href="http://incubator.apache.org/tuscany"
+ * target="_blank"> Apache Tuscany</a> project. It was written to help users
+ * understand and experiement with SDO. It is based upon code snippets contained
+ * within, and is meant for use with, and reference to the <a
+ * href="http://www.osoa.org/download/attachments/791/SDO_Specification_Java_V2.01.pdf?version=1"
+ * target="_bank">SDO Specification</a>. <br>
+ * <br> 
+ * <br>Uses {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE} and {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XML_RESOURCE} in order to define purcahseOrder DataObjects
+ * <br><br>
+ * <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.specCodeSnippets.CreateDataObjectFromXsdAndXmlFiles</LI>
+ * </UL>
+ * 
+ * @author Robbie Minshall
+ */
+public class CreateDataObjectFromXsdAndXmlFiles {
+
+	public static boolean typesDefined = false;
+
+    
+  	/**
+	 * Loads the {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE} resource in order to define PurchaseOrder
+	 * Types 
+	 */
+	public static void definePurchaseOrderTypeUsingXsdResource()
+			throws Exception {
+
+		InputStream is = null;
+		try {
+			System.out.println("Attempting to define types using resource "
+					+ SdoSampleConstants.PO_XSD_RESOURCE);
+			is = ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE);
+			if (is == null) {
+				System.out.println("InputStream is null, you may need to add the resources directory is on the classpath");
+                throw new Exception("InputStream for " + SdoSampleConstants.PO_XSD_RESOURCE + " was null, ensure that it is located on the classpath");
+			} else {
+				System.out.println("Obtained Input Stream from resoruce");
+			}
+			XSDHelper.INSTANCE.define(is, null);
+
+		} catch (Exception e) {
+			System.out
+					.println("Exception caught defining Types from resoruce stream to "
+							+ SdoSampleConstants.PO_XSD_RESOURCE);
+			throw e;
+		} finally {
+			// try to close the input stream
+			if (is != null) {
+				try {
+					is.close();
+					System.out.println("Closed input stream");
+				} catch (Exception e) {	
+					System.out.println("could not close input stream " + e.toString());
+				}
+			}
+		}
+	}
+
+	/**
+	 * Uses resource {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XML_RESOURCE} to populate DataObject
+	 * @return populated purchase order DataObject
+	 */
+	public static DataObject createPurchaseOrderDataObjectUsingXmlResource()
+			throws Exception {
+
+		if (! typesDefined){
+			definePurchaseOrderTypeUsingXsdResource();
+		}
+		DataObject purchaseOrder = null;
+		InputStream is = null;
+		
+		try {
+			
+			System.out
+					.println("Using resource as stream to access xml to populate DataObjects");
+			// FileInputStream fis = new FileInputStream(xmlFileName);
+			is = ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE);
+			if (is == null) {
+				System.out.println("InputStream is null");
+			} else {
+				System.out
+						.println("Successfully obtained InputStream from resource");
+			}
+			XMLDocument xmlDoc = XMLHelper.INSTANCE.load(is);
+			purchaseOrder = xmlDoc.getRootObject();
+			
+		} catch (Exception e) {
+			System.out.println("Could not use resourceAsStream "
+					+ e.toString());
+			e.printStackTrace();
+			throw e;
+		}finally {
+			// try to close the input stream
+			if (is != null) {
+				try {
+					is.close();
+					System.out.println("Closed input stream");
+				} catch (Exception e) {
+					System.out.println("Could not close input stream " + e.toString());
+				}
+			}
+		}
+
+		return purchaseOrder;
+	}
+
+	/**
+	 * @param args.  No arguments required
+	 */
+	public static void main(String[] args) {
+		// information
+		System.out.println("***************************************");
+		System.out.println("SDO Sample CreateDataObjectFromXsdAndXmlFiles");
+		System.out.println("***************************************");
+		System.out.println("Demonstrates defining Types by using a predefined xsd resource, and populating a DataObject by using a previously created xml file");
+		System.out.println("***************************************");
+	
+
+		try {
+			// define the types
+			definePurchaseOrderTypeUsingXsdResource();
+
+			// create a dataObject
+			DataObject purchaseOrder = createPurchaseOrderDataObjectUsingXmlResource();
+			System.out.println("DataObject sucessfully created");
+				
+		} catch (Exception e) {
+			System.out.println("Sorry there was an error encountered " + e.toString());			
+		}
+                System.out.println("GoodBye");
+	}
+
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,189 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specCodeSnippets;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.TypeHelper;
+import java.util.List;
+
+/**
+ * Demonstrates creating and using Types dynamically. This sample is from the <a
+ * href="http://incubator.apache.org/tuscany" target="_blank"> Apache Tuscany</a>
+ * project. It was written to help users understand and experiement with SDO. It is
+ * based upon code snippets contained within, and is meant for use with, and reference
+ * to the <a
+ * href="http://www.osoa.org/download/attachments/791/SDO_Specification_Java_V2.01.pdf?version=1"
+ * target="_bank">SDO Specification</a>. Specifically, this sample is based upon the
+ * section titled "Defining SDO Types Dynamically" <br>
+ * <br> * <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.specCodeSnippets.DynamicCustomerTypeSample</LI>
+ * </UL>
+ * 
+ * @author Robbie Minshall
+ */
+public class DynamicCustomerTypeSample {
+
+    /**
+     * XSD file used to define the model and Types for Customer Dataobject
+     */
+    public static final String CUSTOMER_MODEL = "customer.xsd";
+
+    /**
+     * Default file name to use when generated customer XSD files.
+     * 
+     * @see org.apache.tuscany.samples.sdo.specCodeSnippets.CreateXmlAndXsdFromDataObject
+     */
+    public static final String CUSTOMER_MODEL_GENERATED = "generatedCustomer.xsd";
+
+    /**
+     * Fake namespace used for Customer
+     */
+    public static final String CUSTOMER_NAMESPACE = "http://www.example.com/customer";
+
+    /**
+     * XML file used to populate Customer DataObjects
+     */
+    public static final String CUSTOMER_XML = "customer.xml";
+
+    /**
+     * Default file name to use when generated customer XML files.
+     * 
+     * @see org.apache.tuscany.samples.sdo.specCodeSnippets.CreateXmlAndXsdFromDataObject
+     */
+    public static final String CUSTOMER_XML_GENERATED = "generatedCustomer.xml";
+
+    /**
+     * Method dynamically defines customer types
+     */
+    public static void defineCustomerTypes() {
+        // get an instance of the type helper
+        TypeHelper types = TypeHelper.INSTANCE;
+        Type intType = types.getType("commonj.sdo", "Int");
+        Type stringType = types.getType("commonj.sdo", "String");
+
+        // create a new Type for Customers
+        DataObject customerType = DataFactory.INSTANCE.create("commonj.sdo", "Type");
+        customerType.set("uri", "http://example.com/customer");
+        customerType.set("name", "Customer");
+
+        // create a customer number property
+        DataObject custNumProperty = customerType.createDataObject("property");
+        custNumProperty.set("name", "custNum");
+        custNumProperty.set("type", intType);
+
+        // create a last name property
+        DataObject lastNameProperty = customerType.createDataObject("property");
+        lastNameProperty.set("name", "lastName");
+        lastNameProperty.set("type", stringType);
+
+        // create a first name property
+        DataObject firstNameProperty = customerType.createDataObject("property");
+        firstNameProperty.set("name", "firstName");
+        firstNameProperty.set("type", stringType);
+
+        // now define the Customer type so that customers can be made
+        types.define(customerType);
+
+        Type testType = TypeHelper.INSTANCE.getType("http://example.com/customer", "Customer");
+        List props = testType.getProperties();
+        for (int i = 0; i < props.size(); i++) {
+            System.out.println(props.get(i));
+        }
+    }
+
+    /**
+     * Creates a new Customer using dynamically defined Customer Type
+     * 
+     * @param custNum
+     * @param firstName
+     * @param lastName
+     * @return
+     */
+    private static DataObject createCustomer(int custNum, String firstName, String lastName) {
+        DataFactory factory = DataFactory.INSTANCE;
+        DataObject customer1 = factory.create("http://example.com/customer", "Customer");
+        customer1.setInt("custNum", custNum);
+        customer1.set("firstName", firstName);
+        customer1.set("lastName", lastName);
+        return customer1;
+    }
+
+    /**
+     * Drives sample methods
+     * 
+     * @param args
+     *            no arguments required
+     */
+    public static void main(String args[]) {
+        System.out.println("***************************************");
+        System.out.println("SDO Sample DynamicCustomerTypeSample");
+        System.out.println("***************************************");
+        System.out.println("Demonstrats creating and using Types dynamically");
+        System.out.println("***************************************");
+        try {
+            System.out.println("Dynamically defining Customer Type");
+            defineCustomerTypes();
+
+            System.out.println("Creating new customer DataObject");
+            DataObject customer1 = createCustomer(1, "John", "Adams");
+            System.out.println("Customer Created");
+
+            System.out.println("converting to xml");
+            String xmlDocString = XMLHelper.INSTANCE.save(customer1, CUSTOMER_NAMESPACE, "customer");
+            System.out.println(xmlDocString);
+
+        } catch (Exception e) {
+            System.out.println("Sorry unexpected exception caught during sample execution : " + e.toString());
+            e.printStackTrace();
+        }
+        System.out.println("GoodBye");
+    }
+
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,186 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specCodeSnippets;
+
+import java.io.InputStream;
+
+import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import commonj.sdo.DataObject;
+import commonj.sdo.DataGraph;
+import commonj.sdo.Sequence;
+
+/**
+ * Demonstrates a vareity of methods available to obtain the root DataObject
+ *  contained within an xml representation of a DataGraph. This is currently a grey
+ * area of the specification and this samples demonstrates spec complant means, as
+ * well as utility methods that have been added to Tuscany to address issues within
+ * the specification.
+ * 
+ * The following sample is from the <a href="http://incubator.apache.org/tuscany"
+ * target="_blank"> Apache Tuscany</a> project. It was written to help users
+ * understand and experiement with SDO. It is based upon example code contained
+ * within, and is meant for use with, and reference to the <a
+ * href="http://www.osoa.org/download/attachments/791/SDO_Specification_Java_V2.01.pdf?version=1"
+ * target="_bank">SDO Specification</a>. This sample addresses confusing aspects of
+ * the the AccessDataObjectsUsingXPath example from the Examples section of the SDO
+ * specification.<br>
+ * <br>
+ * To define the correct Types for each DataObject ( CompanyType, DepartmentType etc )
+ * this sample relies upon
+ * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#COMPANY_XSD} which is
+ * provided in the resources directory of these samples. The xml file
+ * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#COMPANY_DATAGRAPH_XML} is
+ * used to load the DataGraph and is also located in this resources directory. <br>
+ * <br>
+ * <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.specCodeSnippets.ObtainingDataGraphFromXml</LI>
+ * </UL>
+ * 
+ * @see org.apache.tuscany.samples.sdo.specExampleSection.AccessDataObjectsUsingXPath
+ * @author Robbie Minshall
+ */
+
+public class ObtainingDataGraphFromXml {
+
+    /**
+     * Execute this method in order to run the sample.
+     * 
+     * @param args
+     */
+    public static void main(String[] args) {
+        System.out.println("***************************************");
+        System.out.println("SDO Sample ObtainingDataGraphFromXml");
+        System.out.println("***************************************");
+        System.out.println("Demonstrates a vareity of methods available to obtain the root DataObject"
+                + "contained within an xml representation of a DataGraph.");
+        System.out.println("***************************************");
+        
+
+        // define Types
+        try {
+            System.out.println("Defining Types using XSD");
+            InputStream is = null;
+            is = ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD);
+            XSDHelper.INSTANCE.define(is, null);
+            is.close();
+            System.out.println("Type definition completed");
+        } catch (Exception e) {
+            System.out.println("Exception caught defining types " + e.toString());
+            e.printStackTrace();
+        }
+
+        try {
+
+            /**
+             * A DataGraph is an optional envelope for a graph of DataObjects and an
+             * associated ChangeSummary.
+             * 
+             * The specification group is currently investigating options regarding
+             * obtaining a DataGraph from an xml file as well as the role of the
+             * DataGraph within the SDO specification.
+             * 
+             * In order to obtain the rootObject contained within the specification
+             * the specification demonstrates reading in an XML file and obtaining a
+             * DataObject that represents the datagraph contained within the file.
+             * Note, that the specification does not obtain a DataGraph - there are
+             * not mechanisms within the specification for obtaining a DataGraph from
+             * xml. Obtaining the root DataObject from this datagraph representation
+             * is quite cumbersome and is demonstrated below.
+             * 
+             * In order to address this current limitation within the specification
+             * Tuscany has added a utility method to SDOUtil that allows a user to
+             * obtain an actual DataGraph from xml.
+             */
+
+            DataObject company = null;
+
+            /**
+             * Use specification mechanism for obtaining a DataObject that represents
+             */
+            // the a datagraph
+            System.out.println("Using specification methods to obtain DataObject represeenting a datagraph from xml");
+
+            // When the xml file represents a DataGraph the root Object
+            // of the XMLDocument is a DataGraph
+            DataObject dataObjectRepresentingDataGraph = XMLHelper.INSTANCE.load(
+                    ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_DATAGRAPH_XML)).getRootObject();
+                                              
+            // Obtain the company DataObject from the DataObject representing the datagraph
+            Sequence mySeq = (Sequence) dataObjectRepresentingDataGraph.getSequence("any");
+            company = (DataObject) mySeq.getValue(0);
+
+            System.out.println("Obtained DataObject representing datagraph");
+            System.out.println(dataObjectRepresentingDataGraph);
+            System.out.println("Obtained root DataObject from datagraph");
+            System.out.println(company);            
+            System.out.println();
+            
+            
+            /**
+             * Use utility method to obtain an actual DataGraph from the xml
+             */                        
+            DataGraph datagraph = SDOUtil.loadDataGraph(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_DATAGRAPH_XML), null);
+            // Obtain the company DataObject from the actual DataGraph
+            company = datagraph.getRootObject();
+            System.out.println("Obtained actual DataGraph:");
+            System.out.println(datagraph);
+            System.out.println("Obtained root DataObject from DataGraph:");
+            System.out.println(company);            
+            System.out.println();
+                      
+        } catch (Exception e) {
+            System.out.println("Sorry there was an error encountered " + e.toString());
+            e.printStackTrace();
+        }
+        System.out.println("GoodBye");
+
+    }
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,174 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specCodeSnippets;
+
+import java.util.List;
+
+import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * Demonstrates iterating through, and inspecting properites of a DataObject. This
+ * sample shows listing properties of a dataObject, determining if the properties are
+ * set, are simple properties or represent DataObjects <br>
+ * <br>
+ * This sample is from the <a href="http://incubator.apache.org/tuscany"
+ * target="_blank"> Apache Tuscany</a> project. It was written to help users
+ * understand and experiement with SDO. It is based upon code snippets contained
+ * within, and is meant for use with, and reference to the <a
+ * href="http://www.osoa.org/download/attachments/791/SDO_Specification_Java_V2.01.pdf?version=1"
+ * target="_bank">SDO Specification</a>. This specific examples was based upon code
+ * snippets in the section titled 'Property Indexes'. <br>
+ * <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.specCodeSnippets.PrintPropertiesOfDataObject</LI>
+ * </UL>
+ * 
+ * @author Robbie Minshall
+ */
+
+public class PrintPropertiesOfDataObject {
+
+    /**
+     * Calls recursive method to inspect and print properties of a DataObject.
+     * 
+     * @param DataObject.
+     *            The DataObject to print the properties of
+     */
+    public static void printDataObjectProperties(DataObject myDo) throws Exception {
+        System.out.println("Recursivly inspecting and printing properties of DataObject");
+        printAndInspectDataObject("   ", myDo);
+    }
+
+    /**
+     * Recursivly inspects and prints DataObject. This method will list all set
+     * properties
+     * 
+     * @param buffer.
+     *            Blank string to help with formating
+     * @param myDo.
+     *            DataObject to recursivly inspect and print the properties of.
+     * @throws Exception
+     */
+    private static void printAndInspectDataObject(String buffer, DataObject myDo) throws Exception {
+
+        for (int i = 0; i < myDo.getInstanceProperties().size(); i++) {
+            Property p = (Property) myDo.getInstanceProperties().get(i);
+            // just print out the name, type and string value of the property
+            Type type = p.getType();
+            System.out.print(buffer + "  " + p.getName() + ",type=" + type.getName());
+            if (myDo.isSet(p)) {
+                // see if this represents a simple property or if the type is also a
+                // datatype
+                if (type.isDataType()) {
+                    System.out.println(", simple type :  " + myDo.get(i));
+                } else {
+
+                    // check to see if the property has many values
+                    if (p.isMany()) {
+                        System.out.println(buffer + ", many valued with list of DataObjects : ");
+                        List dataObjects = myDo.getList(p);
+                        for (int x = 0; x < dataObjects.size(); x++) {
+                            printAndInspectDataObject(buffer + "    ", (DataObject) dataObjects.get(x));
+                            System.out.println();
+                        }
+
+                    } else {
+
+                        System.out.println(buffer + ", data object : ");
+                        DataObject newDataObject = myDo.getDataObject(p);
+                        printAndInspectDataObject(buffer + "    ", newDataObject);
+                        System.out.println("");
+                    }
+                }
+            } else {
+                System.out.println(buffer + ", is not set");
+            }
+        }
+
+    }
+
+    /**
+     * @param args.
+     *            none required.
+     */
+    public static void main(String[] args) {
+        // information
+        System.out.println("***************************************");
+        System.out.println("SDO Sample InspectAndPrintPropertiesOfDataObject");
+        System.out.println("***************************************");
+        System.out.println("Demonstrates a common pattern of looping through and inspecting the META-DATA for all instance properties."
+                + "This example uses recursion to iterate through properties which themselves are DataObjects.");
+        System.out.println("***************************************");
+
+        // create a DataObejct
+        DataObject purchaseOrder = null;
+        try {
+            XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+            purchaseOrder = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
+            System.out.println("DataObject created");
+        } catch (Exception e) {
+            System.out.println("Error creating DataObject " + e.toString());
+            e.printStackTrace();
+            return;
+        }
+        
+        //print and inspect properties of the DataObject
+        try {
+            System.out.println("Will iterate and inspect the properties of the following data object " + purchaseOrder.toString());
+            printDataObjectProperties(purchaseOrder);
+
+        } catch (Exception e) {
+            System.out.println("Sorry, an error was encountered inspecting DataObject " + e.toString());
+        }
+        System.out.println("GoodBye");
+    }
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,145 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specCodeSnippets;
+
+import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * Demonstrates accessing a created DataObject's properties using xPath.
+ * 
+ * This sample is from the <a href="http://incubator.apache.org/tuscany" target="_blank"> Apache Tuscany</a> project. It was written to help users
+ * understand and experiement with SDO. It is based upon code snippets contained within, and is meant for use with, and reference to the <a
+ * href="http://www.osoa.org/download/attachments/791/SDO_Specification_Java_V2.01.pdf?version=1" target="_bank">SDO Specification</a>.
+ * <br>
+ * <br>
+ * It is worth noting that the Examples section of the specification, and the
+ * {@link org.apache.tuscany.samples.sdo.specExampleSection.AccessingDataObjectsUsingXPath} use unpure xpath expression. This sample attempts to
+ * demonstrate a more appropiate subset of xPath operations.<br>
+ * <br>
+ * <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.specCodeSnippets.UsingXPath</LI>
+ * </UL>
+ * 
+ * @author Robbie Minshall
+ */
+public class UsingXPath {
+
+    /**
+     * Prints a subset of item properties to System.out where the individual item was accessed using an xPath expression
+     * 
+     * @param purchaseOrder.
+     *            DataObject defined by Types in {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE}
+     */
+    public static void accessDataObjectUsingXPath(DataObject purchaseOrder) {
+        // TODO: use variety of xpath expressions such as items/item[1]
+        // TODO: add to junit test cases for test cases above
+
+        // xpath expressions for obtaining various items
+        String[] xPathExpressions = { "items/item[1]","items/item[productName=Baby Monitor]" };
+
+        for (int i = 0; i < xPathExpressions.length; i++) {
+            try {
+                System.out.println("Accessing individual item from list using xpath expression" + xPathExpressions[i]);
+
+                DataObject item = purchaseOrder.getDataObject(xPathExpressions[i]);
+                System.out.println("    DataObject toString : " + item.toString());
+
+                System.out.println("    Item name:" + item.get("productName"));
+                System.out.println("    Part num: " + item.get("partNum"));
+            } catch (Exception e) {
+                System.out.println("    Sorry there was an error executing expression " + xPathExpressions[i]);
+            }
+        }
+        
+        //TODO:  select various lists of properties from DataObjects using xPath.
+    }
+
+    /**
+     * Accesses and modifies properties of a purchase order DataObject using xPath( properties are defined in the xsd
+     * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE} and populated by xml
+     * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XML_RESOURCE} )
+     * 
+     * @param args.
+     *            No parameters required.
+     */
+    public static void main(String[] args) {
+
+        // information
+        System.out.println("***************************************");
+        System.out.println("SDO Sample UsingXPath");
+        System.out.println("***************************************");
+        System.out.println("Demonstrats accessing a created DataObject's properties using xPath.");
+        System.out.println("***************************************");
+
+        // create a DataObejct
+        DataObject purchaseOrder = null;
+        try {
+            XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+            purchaseOrder = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
+            System.out.println("DataObject created");
+        } catch (Exception e) {
+            System.out.println("Error creating DataObject " + e.toString());
+            e.printStackTrace();
+            return;
+        }
+
+        // start of sample
+        try {
+
+            accessDataObjectUsingXPath(purchaseOrder);
+        } catch (Exception e) {
+            System.out.println("Sorry there was an error accessing properties by name " + e.toString());
+            e.printStackTrace();
+        }
+        System.out.println("GoodBye");
+        // end of sample
+    }
+
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/package.html
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/package.html?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/package.html (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/package.html Wed Aug 16 06:56:30 2006
@@ -0,0 +1,23 @@
+<html>
+<head>
+	<title>package information</title>
+</head>
+<body>
+
+Provides examples containing code snipets located throughout the SDO Specification.  In general these samples attempt to use the
+code and comments contained within the specification but allow a certain degree of flexability extend or improve 
+upon the code snipets where desireable.
+	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>	  
+</ul>
+
+</body>
+</html>
\ No newline at end of file

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java?rev=431902&view=auto
==============================================================================
--- incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java (added)
+++ incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java Wed Aug 16 06:56:30 2006
@@ -0,0 +1,248 @@
+/**
+ *
+ *  Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.specExampleSection;
+
+import java.util.List;
+
+import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import commonj.sdo.DataObject;
+
+/**
+ * Demonstrates accessing the properties of a DataObject using XPath queries.
+ * 
+ * The following sample is from the <a href="http://incubator.apache.org/tuscany"
+ * target="_blank"> Apache Tuscany</a> project. It was written to help users
+ * understand and experiement with SDO. It is based upon example code contained
+ * within, and is meant for use with, and reference to the <a
+ * href="http://www.osoa.org/download/attachments/791/SDO_Specification_Java_V2.01.pdf?version=1"
+ * target="_bank">SDO Specification</a>. In general this sample attempts to use the
+ * code and comments contained within the specification, exceptions to this are noted
+ * in comments.<br>
+ * <br>
+ * This specific sample is based upon the AccessDataObjectsUsingXPath example from
+ * the Examples section of the SDO specification. It shows the use of DataObjects and
+ * the XMLHelper and demonstrates accessing the properties of a DataObject using
+ * XPath queries. <br>
+ * <br>
+ * This sample reads an xml file representing a DataObject of a company. A
+ * DataAccessService (DAS) is simply a component which creates a DataGraph or
+ * DataObject, it can also be responcible for creating SDO Types for created
+ * DataObjects. In order to create a DataObject or DataGraph this sample relies upon
+ * XMLHelper class which is essentially an example of a XML DAS. The code shown here
+ * would work just as well against an equivalent DataGraph or DataObject that was
+ * provided by any DAS that creates an identical DataObject/DataGraph of the same
+ * Type used here. <br>
+ * <br>
+ * To define the correct Types for each DataObject ( CompanyType, DepartmentType etc )
+ * this sample relies upon
+ * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#COMPANY_XSD} which is
+ * provided in the resources directory of these samples. The xml file
+ * {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#COMPANY_DATAOBJECT_XML}
+ * used to load the DataObject is also located in this resources directory. The xsd
+ * the xml was generated by
+ * {@link org.apache.tuscany.samples.sdo.otherSources.CreateCompany} which is a good
+ * resource for how to populate or create DataObjects or DataGraphs dynamically. <br>
+ * <br>
+ * The following example has the same effect as
+ * {@link org.apache.tuscany.samples.sdo.specExampleSection.AccessDataObjectsViaPropertyIndex}.
+ * <br><br>
+ * <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.specExampleSection.AccessDataObjectsUsingXPath </LI>
+ * </UL>
+ * 
+ * @author Robbie Minshall
+ * @see org.apache.tuscany.samples.sdo.specCodeSnippets.ObtainingDataGraphFromXml
+ */
+
+public class AccessDataObjectsUsingXPath {
+
+    /**
+     * Execute this method in order to run the sample.
+     * 
+     * @param args
+     */
+    public static void main(String[] args) {
+        System.out.println("***************************************");
+        System.out.println("SDO Sample AccessDataObjectsUsingXPath");
+        System.out.println("***************************************");
+        System.out.println("Demonstrates accessing the properties of a DataObject using XPath queries");
+        System.out.println("***************************************");
+        
+        /**
+         * In order to associate the correct Type, to the DataObjects represented in
+         * the xml Read in the model/schema which is declared within the xsd so that
+         * it can be associated. If the Types were not defined in this manner you can
+         * still populate, access and use a DataObject or DataGraph but would not
+         * have the protection and use of use afforded by the relationships declared
+         * within the model.
+         */
+        try {
+            System.out.println("Defining Types using XSD");
+            XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD), null);
+            System.out.println("Type definition completed");
+        } catch (Exception e) {
+            System.out.println("Exception caught defining types " + e.toString());
+            e.printStackTrace();
+        }
+
+        try {
+
+            /**
+             * The specification Example demonstrates using both a DataObject and
+             * DataGraph representation of a compony model. This example simply uses
+             * a DataObject representation.
+             *
+             * Obtain the RootObject from the XMLDocument obtained from the XMLHelper
+             * instance. In this case the root object is a DataObject representing a
+             * company
+             */
+            
+            DataObject company = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_DATAOBJECT_XML)).getRootObject();
+
+            // print out some information to show the user what the objects
+            // look like
+            System.out.println("Company DataObject:");
+            System.out.println(company);
+
+            String generatedXml = XMLHelper.INSTANCE.save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
+            System.out.println("Company data object xml representation: ");
+            System.out.println(generatedXml);
+
+            /*
+             * If we wish to change the name of the company DataObject from "ACME" to
+             * "MEGACORP" , we could use the following:
+             */
+
+            // Set the "name" property for the company
+            System.out.println("Setting 'name' property for the company DataObject to 'MEGACORP'");
+            company.setString("name", " MegaCorp");
+            System.out.println();
+
+            /*
+             * Now, suppose we wish to access the employee whose serial number is
+             * "E0002" If we know that this employee is located at index 1 within the
+             * department that is located at index 0 within the company object one
+             * way to do this is by traversing each reference in the data graph and
+             * locating each DataObject in the many-valued department property using
+             * it's index in the list. For example, from the company, we can get a
+             * list of departments, from that list we can get the department at index
+             * 0, from there we can get a list of employees, and from that list we
+             * can get the employee at index 1.
+             */
+
+            System.out
+                    .println("Obtain employee whose serial number is 'E0002' by acessing list of departments via index, and then accessing specific employee by index.  This requies that we know the indices of both the department and employee");
+            // Get the list of departments
+            List departments = company.getList("departments");
+            // Get the department at index 0 on the list
+            DataObject department = (DataObject) departments.get(0);
+            // Get the list of employees for the department
+            List employees = department.getList("employees");
+            // Get the employee at index 2 on the list
+            DataObject employeeFromList = (DataObject) employees.get(2);
+
+            /*
+             * Alternatively, we can write a single XPath expression that directly
+             * accesses the employee from the root company. Please note that the
+             * specification's use of . indexing starting at index 0 is not true
+             * xPath. Please see the
+             * org.apache.tuscany.samples.sdo.specCodeSnippets.UsingXPath
+             * example for more examples of using xPath. A more appropiate use of
+             * xPath might be
+             * 
+             * employeeFromXPath =
+             * company.getDataObject("departments[1]/employees[3]");
+             * 
+             */
+
+            System.out.println("Obtain employee using xPath expression");
+            DataObject employeeFromXPath = company.getDataObject("departments.0/employees.2");
+
+            /*
+             * In order to remove that employee from the data graph, we could
+             */
+
+            // remove the employee from the list of employees
+            System.out.println("Removing employee " + employeeFromXPath.getString("name") + " from list of employees");
+            employeeFromXPath.detach();
+
+            /*
+             * And, finally, to create a new employee:
+             */
+            // create a new employee
+            System.out.println("Creating new employee (manager) Al Smith and adding to list");
+            DataObject newEmployee = department.createDataObject("employees");
+
+            newEmployee.set("name", "Al Smith");
+            newEmployee.set("SN", "E0005");
+            newEmployee.setBoolean("manager", true);
+
+            // Reset employeeOfTheMonth to be the new employee
+            System.out.println("Setting employee of the month to new employee");
+            company.set("employeeOfTheMonth", newEmployee.getString("SN"));
+
+            // print out some information to show the user what the objects
+            // look like
+            System.out.println("The modified company DataObject: ");
+            System.out.println(company);
+            System.out.println();
+
+            generatedXml = XMLHelper.INSTANCE.save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
+            System.out.println("Company data object xml representation: ");
+            System.out.println(generatedXml);
+            System.out.println();
+
+        } catch (Exception e) {
+            System.out.println("Sorry there was an error encountered " + e.toString());
+            e.printStackTrace();
+        }
+        System.out.println("GoodBye");
+    }
+}

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/samples/sdo/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org