You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2007/06/12 14:35:41 UTC
svn commit: r546467 - in
/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo:
./ otherSources/ specCodeSnippets/ specExampleSection/
Author: kelvingoodson
Date: Tue Jun 12 05:35:30 2007
New Revision: 546467
URL: http://svn.apache.org/viewvc?view=rev&rev=546467
Log:
TUSCANY-1127 remove reference to Helper INSTANCES (all the references to Sequence s = datoobject.get(*) had already been removed)
Modified:
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleBase.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleInfrastructure.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreateCompany.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreatePurchaseOrder.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderControl.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/ReadPurchaseOrder.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingDataObjectsViaPropertyIndex.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingTheContentsOfASequence.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingDataObjectTreesFromXMLDocuments.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingXmlFromDataObjects.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/SerializingDesearializingADataObject.java
incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/UsingTypeAndPropertyWithDataObjects.java
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleBase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleBase.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleBase.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleBase.java Tue Jun 12 05:35:30 2007
@@ -24,7 +24,9 @@
import org.apache.tuscany.sdo.api.SDOUtil;
+import commonj.sdo.DataObject;
import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
import commonj.sdo.helper.XSDHelper;
import commonj.sdo.impl.HelperProvider;
@@ -32,6 +34,10 @@
protected HelperContext scope;
+ public SampleBase()
+ {
+ super(NOVICE);
+ }
public SampleBase(int userLevel) {
super(userLevel);
@@ -78,7 +84,7 @@
}
- protected void loadXMLSchemaFromFile(HelperContext scope, String fileName) {
+ protected void loadXMLSchemaFromFile(String fileName) {
commentary(NOVICE,
"If you want to create types dynamically by loading an XML schema you\n" +
"use an instance of XSDHelper. You get that helper from a HelperContext.\n" +
@@ -91,14 +97,45 @@
XSDHelper xsdHelper = scope.getXSDHelper();
+ InputStream is = null;
try {
- InputStream is = null;
+
is = ClassLoader.getSystemResourceAsStream(fileName);
xsdHelper.define(is, null);
- is.close();
} catch (Exception e) {
somethingUnexpectedHasHappened(e);
+ } finally {
+ try {
+ is.close();
+ } catch (Exception e) {
+ somethingUnexpectedHasHappened(e);
+ }
+ }
+ }
+
+ public DataObject loadXMLFromFile(String filename)
+ throws Exception {
+
+ DataObject result = null;
+ InputStream is = null;
+
+ try {
+ is = ClassLoader
+ .getSystemResourceAsStream(filename);
+ XMLDocument xmlDoc = scope.getXMLHelper().load(is);
+ result = xmlDoc.getRootObject();
+
+ } catch (Exception e) {
+ somethingUnexpectedHasHappened(e);
+ } finally {
+ try {
+ is.close();
+ } catch (Exception e) {
+ somethingUnexpectedHasHappened(e);
+ }
}
+
+ return result;
}
}
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleInfrastructure.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleInfrastructure.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleInfrastructure.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/SampleInfrastructure.java Tue Jun 12 05:35:30 2007
@@ -107,7 +107,7 @@
}
}
- protected void somethingUnexpectedHasHappened(Exception e) {
+ public void somethingUnexpectedHasHappened(Exception e) {
banner('!',
"Something unexpected has gone wrong with the execution of this sample program\n" +
"Please take a look at the exception and see if its something wrong with your environment\n" +
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreateCompany.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreateCompany.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreateCompany.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreateCompany.java Tue Jun 12 05:35:30 2007
@@ -35,6 +35,7 @@
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.helper.XSDHelper;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
import org.apache.tuscany.sdo.util.SDOUtil;
@@ -74,7 +75,11 @@
* java org.apache.tuscany.samples.sdo.otherSources.CreateCompany</LI>
* </UL>
*/
-public class CreateCompany {
+public class CreateCompany extends SampleBase {
+
+ public CreateCompany(int userLevel) {
+ super(userLevel);
+ }
/**
* XML file generated for the company DataObject
@@ -92,8 +97,22 @@
* @param args
* @throws Exception
*/
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ CreateCompany sample = new CreateCompany(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+ public void run () throws Exception {
+
+
System.out.println("***************************************");
System.out.println("SDO Sample CreateCompany");
System.out.println("***************************************");
@@ -102,6 +121,7 @@
/**
* Use xsd to define model
*/
+ scope = useDefaultScopeForTypes();
defineCompanyTypes();
/**
@@ -133,10 +153,10 @@
/*
* The following creates a DataObject without a DataGraph
*/
- Type companyType = TypeHelper.INSTANCE.getType(SdoSampleConstants.COMPANY_NAMESPACE, "CompanyType");
+ Type companyType = scope.getTypeHelper().getType(SdoSampleConstants.COMPANY_NAMESPACE, "CompanyType");
// this is equivilent to
// DataObject company = DataFactory.INSTANCE.create(SdoSampleConstants.COMPANY_NAMESPACE, "CompanyType");
- company = DataFactory.INSTANCE.create(companyType);
+ company = scope.getDataFactory().create(companyType);
}
System.out.println("Populating company DataObject");
@@ -187,10 +207,10 @@
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);
+ scope.getXMLHelper().save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company", fos);
// print the company DataObject to System.out
- String generatedXml = XMLHelper.INSTANCE.save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
+ String generatedXml = scope.getXMLHelper().save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
System.out.println("The generated xml for the DataObject would look like : " );
System.out.println(generatedXml);
}
@@ -201,14 +221,14 @@
* Defines company types using XSD.
* @throws Exception
*/
- private static void defineCompanyTypes() throws Exception {
+ private 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);
+ List types = scope.getXSDHelper().define(is, null);
is.close();
System.out.println("Type definition completed");
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreatePurchaseOrder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreatePurchaseOrder.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreatePurchaseOrder.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/CreatePurchaseOrder.java Tue Jun 12 05:35:30 2007
@@ -21,6 +21,7 @@
package org.apache.tuscany.samples.sdo.otherSources;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -29,6 +30,7 @@
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.helper.XSDHelper;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
/**
@@ -76,7 +78,11 @@
* @see org.apache.tuscany.samples.sdo.specExampleSection.CreatingXmlFromDataObjects
*/
-public class CreatePurchaseOrder {
+public class CreatePurchaseOrder extends SampleBase {
+
+ public CreatePurchaseOrder(int userLevel) {
+ super(userLevel);
+ }
/**
* Defines purchase order types using
@@ -84,7 +90,7 @@
*
* @throws Exception
*/
- private static void definePOTypes() throws Exception {
+ private void definePOTypes() throws Exception {
InputStream is = ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE);
if (is == null) {
@@ -92,7 +98,7 @@
} else {
System.out.println("Obtained Input Stream from resoruce");
}
- XSDHelper.INSTANCE.define(is, null);
+ scope.getXSDHelper().define(is, null);
is.close();
}
@@ -103,6 +109,19 @@
* none required.
*/
public static void main(String[] args) {
+
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ CreatePurchaseOrder sample = new CreatePurchaseOrder(INTERMEDIATE);
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run() throws Exception {
try {
System.out.println("***************************************");
@@ -115,9 +134,11 @@
System.out.println("***************************************");
+ scope = createScopeForTypes();
+
definePOTypes();
System.out.println("Defined Types using xsd");
- DataObject purchaseOrder = DataFactory.INSTANCE.create(SdoSampleConstants.PO_NAMESPACE, "PurchaseOrderType");
+ DataObject purchaseOrder = scope.getDataFactory().create(SdoSampleConstants.PO_NAMESPACE, "PurchaseOrderType");
System.out.println("Created DataObject using DataFactory");
purchaseOrder.setString("orderDate", "1999-10-20");
@@ -158,7 +179,7 @@
System.out.println("Created 2 items");
OutputStream stream = new FileOutputStream(SdoSampleConstants.PO_XML_GENERATED);
- XMLHelper.INSTANCE.save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder", stream);
+ scope.getXMLHelper().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());
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderControl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderControl.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderControl.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/PurchaseOrderControl.java Tue Jun 12 05:35:30 2007
@@ -32,6 +32,7 @@
import commonj.sdo.helper.XSDHelper;
import commonj.sdo.helper.CopyHelper;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
import org.apache.tuscany.samples.sdo.specCodeSnippets.*;
@@ -43,7 +44,7 @@
* @see org.apache.tuscany.samples.sdo.otherSources.PurchaseOrderCmdLine
*
*/
-public class PurchaseOrderControl {
+public class PurchaseOrderControl extends SampleBase {
// there are a number of ways to set properties
// these constants define which mechanism the user
@@ -75,6 +76,7 @@
*/
public PurchaseOrderControl() throws Exception {
this(null, null);
+ scope = createScopeForTypes();
}
/**
@@ -91,6 +93,8 @@
this.xsdFileName = xsdFileName;
this.xmlFileName = xmlFileName;
+ scope = createScopeForTypes();
+
// define purchase order types for SDO
definePurchaseOrderTypes();
// read in existing xml and populate DataObjects
@@ -107,13 +111,13 @@
if ((xsdFileName == null) || (xsdFileName.equals("")) || (xsdFileName.equalsIgnoreCase("null"))) {
// use simple example to define type from resource
- CreateDataObjectFromXsdAndXmlFiles.definePurchaseOrderTypeUsingXsdResource();
+ loadXMLSchemaFromFile(SdoSampleConstants.PO_XSD_RESOURCE);
} 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);
+ scope.getXSDHelper().define(fis, null);
fis.close();
System.out.println("Sucessfully used " + xsdFileName + " to define types");
@@ -136,13 +140,13 @@
if ((xmlFileName == null) || (xmlFileName.equals("")) || (xmlFileName.equalsIgnoreCase("null"))) {
- purchaseOrder = CreateDataObjectFromXsdAndXmlFiles.createPurchaseOrderDataObjectUsingXmlResource();
+ purchaseOrder = loadXMLFromFile(SdoSampleConstants.PO_XML_RESOURCE);
} else {
try {
System.out.println("Using file to access xml to populate DataObjects");
FileInputStream fis = new FileInputStream(xmlFileName);
- XMLDocument xmlDoc = XMLHelper.INSTANCE.load(fis);
+ XMLDocument xmlDoc = scope.getXMLHelper().load(fis);
purchaseOrder = xmlDoc.getRootObject();
System.out.println("Sucessfully used file to populate DataObjects");
fis.close();
@@ -304,7 +308,7 @@
*/
public void saveAs(String fileName) throws IOException {
OutputStream stream = new FileOutputStream(fileName);
- XMLHelper.INSTANCE.save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder", stream);
+ scope.getXMLHelper().save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder", stream);
System.out.println("Saved to " + fileName);
}
@@ -413,7 +417,7 @@
* @return deep copy of the purchase order DataObject
*/
public DataObject getDeepCopyPurchaseOrder() {
- return CopyHelper.INSTANCE.copy(purchaseOrder);
+ return scope.getCopyHelper().copy(purchaseOrder);
}
@@ -422,7 +426,7 @@
* @return shallow copy of the purchase order DataObject
*/
public DataObject getShallowCopyPurchaseOrder() {
- return CopyHelper.INSTANCE.copyShallow(purchaseOrder);
+ return scope.getCopyHelper().copyShallow(purchaseOrder);
}
/**
@@ -441,7 +445,7 @@
* @return XMLDocument that represents current purchase order DataObject
*/
public XMLDocument getXMLDocuement() {
- return XMLHelper.INSTANCE.createDocument(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder");
+ return scope.getXMLHelper().createDocument(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder");
}
/**
@@ -450,9 +454,9 @@
*/
public String getXMLString() {
// alternativly could use the following
- // return XMLHelper.INSTANCE.createDocument(purchaseOrder, PO_NAMESPACE,
+ // return scope.getXMLHelper().createDocument(purchaseOrder, PO_NAMESPACE,
// "purchaseOrder").toString();
- return XMLHelper.INSTANCE.save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder");
+ return scope.getXMLHelper().save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder");
}
// PRIVATE HELPER METHODS
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/ReadPurchaseOrder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/ReadPurchaseOrder.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/ReadPurchaseOrder.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/otherSources/ReadPurchaseOrder.java Tue Jun 12 05:35:30 2007
@@ -29,6 +29,7 @@
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.helper.XSDHelper;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
/**
@@ -72,20 +73,38 @@
* </UL>
*
*/
-public class ReadPurchaseOrder {
+public class ReadPurchaseOrder extends SampleBase {
- private static void definePOTypes() throws Exception {
+
+ public ReadPurchaseOrder(int userLevel) {
+ super(userLevel);
+ }
+
+ private 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);
+ scope.getXSDHelper().define(is, null);
is.close();
}
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ ReadPurchaseOrder sample = new ReadPurchaseOrder(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
System.out.println("***************************************");
System.out.println("SDO Sample ReadPurchaseOrder");
System.out.println("***************************************");
@@ -95,6 +114,9 @@
System.out.println("***************************************");
try {
+
+ scope = createScopeForTypes();
+
definePOTypes();
FileInputStream fis = null;
@@ -107,7 +129,7 @@
return;
}
- XMLDocument xmlDoc = XMLHelper.INSTANCE.load(fis);
+ XMLDocument xmlDoc = scope.getXMLHelper().load(fis);
DataObject purchaseOrder = xmlDoc.getRootObject();
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectPropertiesByName.java Tue Jun 12 05:35:30 2007
@@ -22,11 +22,11 @@
import java.util.List;
-import commonj.sdo.DataObject;
-import commonj.sdo.helper.XMLHelper;
-import commonj.sdo.helper.XSDHelper;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+import commonj.sdo.DataObject;
+
/**
* Demonstrates accessing a created DataObject's properties by name.
*
@@ -70,7 +70,11 @@
* java org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectPropertiesByName</LI>
* </UL>
*/
-public class AccessDataObjectPropertiesByName {
+public class AccessDataObjectPropertiesByName extends SampleBase {
+
+ public AccessDataObjectPropertiesByName(int userLevel) {
+ super(userLevel);
+ }
/**
* Prints a subset of PurchaseOrder properties to System.out
@@ -115,6 +119,19 @@
* No parameters required.
*/
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
// information
System.out.println("***************************************");
@@ -124,10 +141,12 @@
System.out.println("***************************************");
// create a DataObejct
+ scope = createScopeForTypes();
+
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();
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+ purchaseOrder = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
System.out.println("DataObject created");
} catch (Exception e) {
System.out.println("Error creating DataObject " + e.toString());
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/AccessDataObjectUsingValidXPath.java Tue Jun 12 05:35:30 2007
@@ -20,6 +20,7 @@
package org.apache.tuscany.samples.sdo.specCodeSnippets;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
import commonj.sdo.DataObject;
@@ -66,7 +67,12 @@
* <LI>Execute: java
* org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectUsingValidXPath</LI>
*/
-public class AccessDataObjectUsingValidXPath {
+public class AccessDataObjectUsingValidXPath extends SampleBase {
+
+ public AccessDataObjectUsingValidXPath(int userLevel) {
+ super(userLevel);
+ }
+
/**
* Prints a subset of item properties to System.out where the individual item was
@@ -100,6 +106,19 @@
* No parameters required.
*/
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
// information
System.out.println("***************************************");
@@ -110,9 +129,10 @@
// create a DataObejct
DataObject purchaseOrder = null;
+ scope = createScopeForTypes();
try {
- XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
- purchaseOrder = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+ purchaseOrder = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
System.out.println("DataObject created");
} catch (Exception e) {
System.out.println("Error creating DataObject " + e.toString());
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXmlString.java Tue Jun 12 05:35:30 2007
@@ -21,6 +21,8 @@
import java.util.List;
+import org.apache.tuscany.samples.sdo.SampleBase;
+
import commonj.sdo.DataObject;
import commonj.sdo.Sequence;
import commonj.sdo.helper.XMLHelper;
@@ -66,7 +68,12 @@
* java org.apache.tuscany.samples.sdo.specCodeSnippets.CreateDataObjectFromXmlString</LI>
* </UL>
*/
-public class CreateDataObjectFromXmlString {
+public class CreateDataObjectFromXmlString extends SampleBase {
+
+ public CreateDataObjectFromXmlString(int userLevel) {
+ super(userLevel);
+ }
+
/**
* String representing a PurchaseOrder in XML format
@@ -80,10 +87,10 @@
*
* @return
*/
- public static DataObject createDataObjectFromXmlString() {
+ public DataObject createDataObjectFromXmlString() {
// TODO: do this with and without defining the schema
- DataObject po = XMLHelper.INSTANCE.load(XML_STRING).getRootObject();
+ DataObject po = scope.getXMLHelper().load(XML_STRING).getRootObject();
System.out.println("DataObject has been created : " + po.toString());
return po;
}
@@ -93,6 +100,19 @@
* None required
*/
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
// information
System.out.println("***************************************");
@@ -103,13 +123,14 @@
// sample
try {
+ scope = createScopeForTypes();
System.out.println("Use the following XML String: " + XML_STRING);
System.out.println("Creating DataObject");
DataObject po = createDataObjectFromXmlString();
System.out.println("The following DataObject was sucessfully created from the XML String");
- System.out.println(XMLHelper.INSTANCE.save(po, "http://example.com/purchaseOrder", "purchaseOrder"));
+ System.out.println(scope.getXMLHelper().save(po, "http://example.com/purchaseOrder", "purchaseOrder"));
/*
* Without a Type definition accessing a DataObject is slightly more
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/CreateDataObjectFromXsdAndXmlFiles.java Tue Jun 12 05:35:30 2007
@@ -22,6 +22,7 @@
import java.io.InputStream;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
import commonj.sdo.DataObject;
import commonj.sdo.helper.XMLDocument;
@@ -72,7 +73,12 @@
* java org.apache.tuscany.samples.sdo.specCodeSnippets.CreateDataObjectFromXsdAndXmlFiles</LI>
* </UL>
*/
-public class CreateDataObjectFromXsdAndXmlFiles {
+public class CreateDataObjectFromXsdAndXmlFiles extends SampleBase {
+
+ public CreateDataObjectFromXsdAndXmlFiles(int userLevel) {
+ super(userLevel);
+ }
+
public static boolean typesDefined = false;
@@ -81,7 +87,7 @@
* Loads the {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XSD_RESOURCE} resource in order to define PurchaseOrder
* Types
*/
- public static void definePurchaseOrderTypeUsingXsdResource()
+ public void definePurchaseOrderTypeUsingXsdResource()
throws Exception {
InputStream is = null;
@@ -95,7 +101,7 @@
} else {
System.out.println("Obtained Input Stream from resoruce");
}
- XSDHelper.INSTANCE.define(is, null);
+ scope.getXSDHelper().define(is, null);
} catch (Exception e) {
System.out
@@ -119,7 +125,7 @@
* Uses resource {@link org.apache.tuscany.samples.sdo.SdoSampleConstants#PO_XML_RESOURCE} to populate DataObject
* @return populated purchase order DataObject
*/
- public static DataObject createPurchaseOrderDataObjectUsingXmlResource()
+ public DataObject createPurchaseOrderDataObjectUsingXmlResource()
throws Exception {
if (! typesDefined){
@@ -140,7 +146,7 @@
System.out
.println("Successfully obtained InputStream from resource");
}
- XMLDocument xmlDoc = XMLHelper.INSTANCE.load(is);
+ XMLDocument xmlDoc = scope.getXMLHelper().load(is);
purchaseOrder = xmlDoc.getRootObject();
} catch (Exception e) {
@@ -166,7 +172,20 @@
/**
* @param args. No arguments required
*/
- public static void main(String[] args) {
+ public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
// information
System.out.println("***************************************");
System.out.println("SDO Sample CreateDataObjectFromXsdAndXmlFiles");
@@ -177,6 +196,8 @@
try {
// define the types
+ scope = createScopeForTypes();
+
definePurchaseOrderTypeUsingXsdResource();
// create a dataObject
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/DynamicCustomerTypeSample.java Tue Jun 12 05:35:30 2007
@@ -27,6 +27,8 @@
import commonj.sdo.helper.TypeHelper;
import java.util.List;
+import org.apache.tuscany.samples.sdo.SampleBase;
+
/**
* Demonstrates creating and using Types dynamically. This sample is from the <a
* href="http://incubator.apache.org/tuscany" target="_blank"> Apache Tuscany</a>
@@ -67,7 +69,12 @@
* java org.apache.tuscany.samples.sdo.specCodeSnippets.DynamicCustomerTypeSample</LI>
* </UL>
*/
-public class DynamicCustomerTypeSample {
+public class DynamicCustomerTypeSample extends SampleBase {
+
+ public DynamicCustomerTypeSample(int userLevel) {
+ super(userLevel);
+ }
+
/**
* XSD file used to define the model and Types for Customer Dataobject
@@ -101,14 +108,14 @@
/**
* Method dynamically defines customer types
*/
- public static void defineCustomerTypes() {
+ public void defineCustomerTypes() {
// get an instance of the type helper
- TypeHelper types = TypeHelper.INSTANCE;
+ TypeHelper types = scope.getTypeHelper();
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");
+ DataObject customerType = scope.getDataFactory().create("commonj.sdo", "Type");
customerType.set("uri", "http://example.com/customer");
customerType.set("name", "Customer");
@@ -130,7 +137,7 @@
// now define the Customer type so that customers can be made
types.define(customerType);
- Type testType = TypeHelper.INSTANCE.getType("http://example.com/customer", "Customer");
+ Type testType = scope.getTypeHelper().getType("http://example.com/customer", "Customer");
List props = testType.getProperties();
for (int i = 0; i < props.size(); i++) {
System.out.println(props.get(i));
@@ -145,8 +152,8 @@
* @param lastName
* @return
*/
- private static DataObject createCustomer(int custNum, String firstName, String lastName) {
- DataFactory factory = DataFactory.INSTANCE;
+ private DataObject createCustomer(int custNum, String firstName, String lastName) {
+ DataFactory factory = scope.getDataFactory();
DataObject customer1 = factory.create("http://example.com/customer", "Customer");
customer1.setInt("custNum", custNum);
customer1.set("firstName", firstName);
@@ -160,13 +167,29 @@
* @param args
* no arguments required
*/
- public static void main(String args[]) {
+ public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
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 {
+ scope = createScopeForTypes();
+
+
System.out.println("Dynamically defining Customer Type");
defineCustomerTypes();
@@ -175,7 +198,7 @@
System.out.println("Customer Created");
System.out.println("converting to xml");
- String xmlDocString = XMLHelper.INSTANCE.save(customer1, CUSTOMER_NAMESPACE, "customer");
+ String xmlDocString = scope.getXMLHelper().save(customer1, CUSTOMER_NAMESPACE, "customer");
System.out.println(xmlDocString);
} catch (Exception e) {
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/ObtainingDataGraphFromXml.java Tue Jun 12 05:35:30 2007
@@ -135,7 +135,7 @@
);
scope = useDefaultScopeForTypes();
- loadXMLSchemaFromFile(scope, SdoSampleConstants.COMPANY_XSD);
+ loadXMLSchemaFromFile(SdoSampleConstants.COMPANY_XSD);
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/PrintPropertiesOfDataObject.java Tue Jun 12 05:35:30 2007
@@ -22,6 +22,7 @@
import java.util.List;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
import commonj.sdo.DataObject;
@@ -74,7 +75,11 @@
* </UL>
*/
-public class PrintPropertiesOfDataObject {
+public class PrintPropertiesOfDataObject extends SampleBase {
+
+ public PrintPropertiesOfDataObject(int userLevel) {
+ super(userLevel);
+ }
/**
* Calls recursive method to inspect and print properties of a DataObject.
@@ -140,6 +145,19 @@
* none required.
*/
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
// information
System.out.println("***************************************");
System.out.println("SDO Sample InspectAndPrintPropertiesOfDataObject");
@@ -151,8 +169,10 @@
// 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();
+ scope = createScopeForTypes();
+
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+ purchaseOrder = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
System.out.println("DataObject created");
} catch (Exception e) {
System.out.println("Error creating DataObject " + e.toString());
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specCodeSnippets/UsingXPath.java Tue Jun 12 05:35:30 2007
@@ -20,6 +20,7 @@
package org.apache.tuscany.samples.sdo.specCodeSnippets;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
import commonj.sdo.DataObject;
@@ -63,7 +64,11 @@
* java org.apache.tuscany.samples.sdo.specCodeSnippets.UsingXPath</LI>
* </UL>
*/
-public class UsingXPath {
+public class UsingXPath extends SampleBase {
+ public UsingXPath(int userLevel) {
+ super(userLevel);
+ }
+
/**
* Prints a subset of item properties to System.out where the individual item was accessed using an xPath expression
@@ -105,6 +110,19 @@
* No parameters required.
*/
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
// information
System.out.println("***************************************");
@@ -116,8 +134,9 @@
// 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();
+ scope = createScopeForTypes();
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+ purchaseOrder = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE)).getRootObject();
System.out.println("DataObject created");
} catch (Exception e) {
System.out.println("Error creating DataObject " + e.toString());
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessDataObjectsUsingXPath.java Tue Jun 12 05:35:30 2007
@@ -22,7 +22,9 @@
import java.util.List;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+import org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectPropertiesByName;
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.helper.XSDHelper;
@@ -102,20 +104,40 @@
* @see org.apache.tuscany.samples.sdo.specCodeSnippets.ObtainingDataGraphFromXml
*/
-public class AccessDataObjectsUsingXPath {
+public class AccessDataObjectsUsingXPath extends SampleBase {
+
+ public AccessDataObjectsUsingXPath(int userLevel) {
+ super(userLevel);
+ }
+
/**
* Execute this method in order to run the sample.
*
* @param args
*/
- public static void main(String[] args) {
+ public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
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("***************************************");
+ scope = createScopeForTypes();
+
/**
* 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
@@ -126,7 +148,7 @@
*/
try {
System.out.println("Defining Types using XSD");
- XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD), null);
+ scope.getXSDHelper().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());
@@ -145,14 +167,14 @@
* company
*/
- DataObject company = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_DATAOBJECT_XML)).getRootObject();
+ DataObject company = scope.getXMLHelper().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");
+ String generatedXml = scope.getXMLHelper().save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
System.out.println("Company data object xml representation: ");
System.out.println(generatedXml);
@@ -235,7 +257,7 @@
System.out.println(company);
System.out.println();
- generatedXml = XMLHelper.INSTANCE.save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
+ generatedXml = scope.getXMLHelper().save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
System.out.println("Company data object xml representation: ");
System.out.println(generatedXml);
System.out.println();
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingDataObjectsViaPropertyIndex.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingDataObjectsViaPropertyIndex.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingDataObjectsViaPropertyIndex.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingDataObjectsViaPropertyIndex.java Tue Jun 12 05:35:30 2007
@@ -23,7 +23,9 @@
import java.io.InputStream;
import java.util.List;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+import org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectPropertiesByName;
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.helper.XSDHelper;
@@ -112,7 +114,12 @@
* @author Robbie Minshall
*/
-public class AccessingDataObjectsViaPropertyIndex {
+public class AccessingDataObjectsViaPropertyIndex extends SampleBase {
+
+ public AccessingDataObjectsViaPropertyIndex(int userLevel) {
+ super(userLevel);
+ }
+
/**
* Predefine the property indexes.
@@ -139,18 +146,33 @@
* @param args
*/
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
System.out.println("***************************************");
System.out.println("SDO Sample AccessingDataObjectsViaPropertyIndex");
System.out.println("***************************************");
System.out.println("Demonstrates accessing the properties of a DataObject using property indices.");
System.out.println("***************************************");
+ scope = createScopeForTypes();
+
// TODO: what happens if not type is defined
try {
System.out.println("Defining Types using XSD");
InputStream is = null;
is = ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD);
- XSDHelper.INSTANCE.define(is, null);
+ scope.getXSDHelper().define(is, null);
is.close();
System.out.println("Type definition completed");
} catch (Exception e) {
@@ -168,14 +190,14 @@
// 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))
+ DataObject company = scope.getXMLHelper().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");
+ String generatedXml = scope.getXMLHelper().save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
System.out.println("Company data object xml representation: ");
System.out.println(generatedXml);
@@ -216,7 +238,7 @@
System.out.println("The modified company DataObject :");
System.out.println(company);
- generatedXml = XMLHelper.INSTANCE.save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
+ generatedXml = scope.getXMLHelper().save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company");
System.out.println("Company data object xml representation: ");
System.out.println(generatedXml);
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingTheContentsOfASequence.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingTheContentsOfASequence.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingTheContentsOfASequence.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/AccessingTheContentsOfASequence.java Tue Jun 12 05:35:30 2007
@@ -21,6 +21,9 @@
package org.apache.tuscany.samples.sdo.specExampleSection;
+import org.apache.tuscany.samples.sdo.SampleBase;
+import org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectPropertiesByName;
+
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.helper.XSDHelper;
import commonj.sdo.DataObject;
@@ -85,7 +88,12 @@
* @author Robbie Minshall
*/
-public class AccessingTheContentsOfASequence {
+public class AccessingTheContentsOfASequence extends SampleBase {
+
+ public AccessingTheContentsOfASequence(int userLevel) {
+ super(userLevel);
+ }
+
/**
* previously created XSD file used
@@ -103,24 +111,39 @@
* @param args
*/
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
System.out.println("***************************************");
System.out.println("SDO Sample AccessingTheContentsOfASequence");
System.out.println("***************************************");
System.out.println("Demonstrates accessing the sequence from a DataObject containing mixed content.");
System.out.println("***************************************");
+ scope = createScopeForTypes();
+
try {
// define model
System.out.println("Defining Types using XSD");
- XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(LETTER_XSD), null);
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(LETTER_XSD), null);
// define letter data object
System.out.println("Loading Letter DataObject from XML");
- DataObject letter = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(LETTER_XML)).getRootObject();
+ DataObject letter = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(LETTER_XML)).getRootObject();
// print letter sequence
System.out.println("Printing sequence for " + letter);
- System.out.println(XMLHelper.INSTANCE.save(letter, "letter.xsd", "letter"));
+ System.out.println(scope.getXMLHelper().save(letter, "letter.xsd", "letter"));
printSequence(letter);
} catch (Exception e) {
@@ -138,9 +161,9 @@
*
* @param letter. Letter DataObject conforming to {@link #LETTER_XSD}
*/
- public static void printSequence(DataObject letter) {
+ public void printSequence(DataObject letter) {
// Access the Sequence of the FormLetter
- System.out.println("The type is for letter dataObject is mixed " + XSDHelper.INSTANCE.isMixed(letter.getType()));
+ System.out.println("The type is for letter dataObject is mixed " + scope.getXSDHelper().isMixed(letter.getType()));
Sequence letterSequence = letter.getSequence();
// Print out all the settings that contain unstructured text
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingDataObjectTreesFromXMLDocuments.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingDataObjectTreesFromXMLDocuments.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingDataObjectTreesFromXMLDocuments.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingDataObjectTreesFromXMLDocuments.java Tue Jun 12 05:35:30 2007
@@ -24,7 +24,9 @@
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.helper.XSDHelper;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+import org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectPropertiesByName;
/**
* Demonstrates creating a DataObject from an XML String.
@@ -84,7 +86,12 @@
* @see {@link org.apache.tuscany.samples.sdo.otherSources.CreatePurchaseOrder}
*/
-public class CreatingDataObjectTreesFromXMLDocuments {
+public class CreatingDataObjectTreesFromXMLDocuments extends SampleBase {
+
+ public CreatingDataObjectTreesFromXMLDocuments(int userLevel) {
+ super(userLevel);
+ }
+
/**
* Drives sample
@@ -92,26 +99,41 @@
* @param args.
* none required.
*/
- public static void main(String[] args) {
+ public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
try {
System.out.println("***************************************");
System.out.println("SDO Sample CreatingDataObjectTreesFromXMLDocuments");
System.out.println("***************************************");
+
+ scope = createScopeForTypes();
// use xsd to define purchase order types
System.out.println("Definging purchase order types using " + SdoSampleConstants.PO_XSD_RESOURCE);
- XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
System.out.println("Defined Types using xsd");
System.out.println("Creating purchase order DataObject using previously created " + SdoSampleConstants.PO_XML_RESOURCE);
- DataObject purchaseOrder = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE))
+ DataObject purchaseOrder = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE))
.getRootObject();
// To create the shipTo DataObject from XML:
String shipToXML = "<shipTo country='US'>" + " <name>Alice Smith</name>" + " <street>123 Maple Street</street>"
+ " <city>Mill Valley</city>" + " <state>PA</state>" + " <zip>90952</zip>" + "</shipTo>";
- DataObject shipTo = XMLHelper.INSTANCE.load(shipToXML).getRootObject();
+ DataObject shipTo = scope.getXMLHelper().load(shipToXML).getRootObject();
// Modify shipTo DataObject on purchaseOrder to value created from a
// String
@@ -121,7 +143,7 @@
// Obtain and convert the billTo DataObject to XML
System.out.println("Obtaining billTo dataObject from purchase order and converting to XML");
DataObject billTo = purchaseOrder.getDataObject("billTo");
- String billToXML = XMLHelper.INSTANCE.save(billTo, null, "billTo");
+ String billToXML = scope.getXMLHelper().save(billTo, null, "billTo");
System.out.println("billTo DataObject:");
System.out.println(billToXML);
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingXmlFromDataObjects.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingXmlFromDataObjects.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingXmlFromDataObjects.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/CreatingXmlFromDataObjects.java Tue Jun 12 05:35:30 2007
@@ -28,7 +28,9 @@
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.helper.XSDHelper;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+import org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectPropertiesByName;
/**
* Demonstrates programmatically creating a DataObject and generating an XML String.
@@ -85,7 +87,12 @@
* @see {@link org.apache.tuscany.samples.sdo.otherSources.CreatePurchaseOrder}
*/
-public class CreatingXmlFromDataObjects {
+public class CreatingXmlFromDataObjects extends SampleBase {
+
+ public CreatingXmlFromDataObjects(int userLevel) {
+ super(userLevel);
+ }
+
/**
* Drives sample
@@ -93,7 +100,20 @@
* @param args.
* none required.
*/
- public static void main(String[] args) {
+ public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
try {
System.out.println("***************************************");
@@ -102,9 +122,11 @@
System.out.println("Demonstrates programmatically creating a DataObject and generating an XML String");
System.out.println("***************************************");
- XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+ scope = createScopeForTypes();
+
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
System.out.println("Defined Types using xsd");
- DataObject purchaseOrder = DataFactory.INSTANCE.create(SdoSampleConstants.PO_NAMESPACE, "PurchaseOrderType");
+ DataObject purchaseOrder = scope.getDataFactory().create(SdoSampleConstants.PO_NAMESPACE, "PurchaseOrderType");
System.out.println("Created DataObject using DataFactory");
System.out.println("Populating purchase order data object");
@@ -145,10 +167,10 @@
item2.setString("shipDate", "1999-05-21");
OutputStream stream = new FileOutputStream(SdoSampleConstants.PO_XML_GENERATED);
- XMLHelper.INSTANCE.save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder", stream);
+ scope.getXMLHelper().save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder", stream);
System.out.println("Created file " + SdoSampleConstants.PO_XML_GENERATED);
System.out.println("Populated with :");
- System.out.println(XMLHelper.INSTANCE.save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder"));
+ System.out.println(scope.getXMLHelper().save(purchaseOrder, SdoSampleConstants.PO_NAMESPACE, "purchaseOrder"));
} catch (Exception e) {
System.out.println("Sorry an error occured " + e.toString());
e.printStackTrace();
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/SerializingDesearializingADataObject.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/SerializingDesearializingADataObject.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/SerializingDesearializingADataObject.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/SerializingDesearializingADataObject.java Tue Jun 12 05:35:30 2007
@@ -34,7 +34,9 @@
import java.io.IOException;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+import org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectPropertiesByName;
/**
* Demonstrates serializing and deserializing a DataObject to disk.
@@ -89,7 +91,12 @@
* @author Robbie Minshall
*/
-public class SerializingDesearializingADataObject {
+public class SerializingDesearializingADataObject extends SampleBase {
+
+ public SerializingDesearializingADataObject(int userLevel) {
+ super(userLevel);
+ }
+
/**
* Default fileName to serialize DataObject to
@@ -110,6 +117,19 @@
* @param args
*/
public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
System.out.println("***************************************");
System.out.println("SDO Sample AccessingTheContentsOfASequence");
System.out.println("***************************************");
@@ -118,14 +138,16 @@
try {
+ scope = createScopeForTypes();
+
// define Types using XSDHelper and predefined xsd file
System.out.println("Defining Types using XSD");
- XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD), null);
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD), null);
System.out.println("Type definition completed");
// create company DataObject using XMLHelper which is an example of a XML DAS
System.out.println("Creating company DataObject");
- DataObject company = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_DATAOBJECT_XML))
+ DataObject company = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_DATAOBJECT_XML))
.getRootObject();
// prompt user for a fileName
@@ -156,19 +178,19 @@
System.out.println("Comparing original and deserialized DataObject");
//determine if two graphs of DataObjects are equal
- System.out.println("DataObjects are equal: " + EqualityHelper.INSTANCE.equal(company, newDataObject));
+ System.out.println("DataObjects are equal: " + scope.getEqualityHelper().equal(company, newDataObject));
//determine if two DataObjects have the same values for their datatype properties
- System.out.println("DataObjects have same values for their datatype properties : " + EqualityHelper.INSTANCE.equalShallow(company, newDataObject));
+ System.out.println("DataObjects have same values for their datatype properties : " + scope.getEqualityHelper().equalShallow(company, newDataObject));
//print out xml representation
System.out.println();
System.out.println("Original company DataObject:");
- System.out.println(XMLHelper.INSTANCE.save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company"));
+ System.out.println(scope.getXMLHelper().save(company, SdoSampleConstants.COMPANY_NAMESPACE, "company"));
System.out.println();
System.out.println("Deserialized company DataObject:");
- System.out.println(XMLHelper.INSTANCE.save(newDataObject, SdoSampleConstants.COMPANY_NAMESPACE, "company"));
+ System.out.println(scope.getXMLHelper().save(newDataObject, SdoSampleConstants.COMPANY_NAMESPACE, "company"));
} catch (Exception e) {
System.out.println("Sorry there was an error encountered " + e.toString());
Modified: incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/UsingTypeAndPropertyWithDataObjects.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/UsingTypeAndPropertyWithDataObjects.java?view=diff&rev=546467&r1=546466&r2=546467
==============================================================================
--- incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/UsingTypeAndPropertyWithDataObjects.java (original)
+++ incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/specExampleSection/UsingTypeAndPropertyWithDataObjects.java Tue Jun 12 05:35:30 2007
@@ -28,7 +28,9 @@
import java.util.List;
+import org.apache.tuscany.samples.sdo.SampleBase;
import org.apache.tuscany.samples.sdo.SdoSampleConstants;
+import org.apache.tuscany.samples.sdo.specCodeSnippets.AccessDataObjectPropertiesByName;
/**
* Demonstrates the use of Type and Property to display and the META-DATA for and access Properties of a DataObject.
@@ -83,14 +85,32 @@
* @see org.apache.tuscany.samples.sdo.specCodeSnippets.PrintPropertiesOfDataObject
*/
-public class UsingTypeAndPropertyWithDataObjects {
+public class UsingTypeAndPropertyWithDataObjects extends SampleBase {
+
+ public UsingTypeAndPropertyWithDataObjects(int userLevel) {
+ super(userLevel);
+ }
+
/**
* Execute this method in order to run the sample.
*
* @param args
*/
- public static void main(String[] args) {
+ public static void main(String[] args) {
+ // TODO make the default level NOVICE, once the rest of the sample has been
+ // converted to using commentary()
+ AccessDataObjectPropertiesByName sample = new AccessDataObjectPropertiesByName(INTERMEDIATE);
+
+ try {
+ sample.run();
+ }
+ catch (Exception e) {
+ sample.somethingUnexpectedHasHappened(e);
+ }
+ }
+
+ public void run () throws Exception {
System.out.println("***************************************");
System.out.println("SDO Sample UsingTypeAndPropertyWithDataObjects");
System.out.println("***************************************");
@@ -98,34 +118,32 @@
System.out.println("***************************************");
try {
+ scope = createScopeForTypes();
+
+
// define Types using XSDHelper and predefined xsd file
System.out.println("Defining company Types using XSD");
- XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD), null);
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_XSD), null);
System.out.println("Type definition completed");
// create company DataObject using XMLHelper which is an example of a XML DAS
System.out.println("Creating company DataObject");
- DataObject company = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_DATAOBJECT_XML))
+ DataObject company = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.COMPANY_DATAOBJECT_XML))
.getRootObject();
printDataObject(company, 0);
System.out.println("Defining purchase order types");
- XSDHelper.INSTANCE.define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
+ scope.getXSDHelper().define(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XSD_RESOURCE), null);
System.out.println("Type definition completed");
// create company DataObject using XMLHelper which is an example of a XML DAS
System.out.println("Creating purchase order DataObject");
- DataObject po = XMLHelper.INSTANCE.load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE))
+ DataObject po = scope.getXMLHelper().load(ClassLoader.getSystemResourceAsStream(SdoSampleConstants.PO_XML_RESOURCE))
.getRootObject();
printDataObject(po, 0);
-
-
-
-
-
} catch (Exception e) {
System.out.println("Sorry there was an error encountered " + e.toString());
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org