diff options
Diffstat (limited to 'java/sdo/sample/src')
8 files changed, 1981 insertions, 1981 deletions
diff --git a/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/MedicalScenario.java b/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/MedicalScenario.java index 1e288ccc48..916fe9405c 100644 --- a/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/MedicalScenario.java +++ b/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/MedicalScenario.java @@ -1,424 +1,424 @@ -/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.samples.sdo.advanced;
-
-import java.io.FileNotFoundException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tuscany.samples.sdo.SampleBase;
-import org.apache.tuscany.sdo.api.SDOUtil;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.Property;
-import commonj.sdo.Type;
-import commonj.sdo.helper.DataFactory;
-import commonj.sdo.helper.HelperContext;
-import commonj.sdo.helper.TypeHelper;
-
-/**
- * This sample is based on a 2 part article by Kelvin Goodson and Geoffrey Winn.
- * See <A href="http://soa.sys-con.com/read/313547.htm">Part1</A> and <A
- * href="http://soa.sys-con.com/read/358059.htm">Part 2</A> of the article.
- * <p>
- * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html"
- * target="_top">the main overview</A> for instructions on how to run this
- * sample.
- */
-public class MedicalScenario extends SampleBase {
-
- private static final String sdoApiUri = "commonj.sdo";
-
- private static final String peopleURI = "www.example.org/people";
-
- private static final String medicalURI = "www.example.org/MedicalTest";
-
- boolean typesViaAPI = false;
-
- private static final String usage = " [-api |-xsd]\n"
- + " -api : define the types using the SDO API\n"
- + " -xsd : define the types using an XML schema file";
-
- public MedicalScenario(String[] args, Integer userLevel) {
-
- super(userLevel, SAMPLE_LEVEL_ADVANCED);
-
- if (args.length > 1) {
- printUsage(args);
- System.exit(-1);
- }
- if (args.length == 1) {
- if (args[0].equals("-xsd")) {
- typesViaAPI = false;
- } else if (args[0].equals("-api")) {
- typesViaAPI = true;
- } else {
- printUsage(args);
- System.exit(-1);
- }
- }
- }
-
- public MedicalScenario(Integer userLevel) {
- super(userLevel, SAMPLE_LEVEL_ADVANCED);
- }
-
-
- private void printUsage(String[] args) {
- System.out.println("Usage: " + this.getClass().getName() + usage);
- }
-
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
-
- MedicalScenario s = new MedicalScenario(args, COMMENTARY_FOR_NOVICE);
- s.run();
-
- }
-
- /*
- * metadata for the sample documenting the areas of SDO that are explored
- */
- public static int [] CORE_FUNCTION = {
- SDOFacets.CONTAINMENT,
- SDOFacets.CREATE_TYPES_USING_THE_SDO_API,
- SDOFacets.CREATE_TYPES_USING_XML_SCHEMA,
- SDOFacets.OPEN_CONTENT,
- SDOFacets.NON_CONTAINMENT
- };
-
- public static int [] SIGNIFICANT_FUNCTION = {
- SDOFacets.CREATE_DATAOBJECTS_BY_NAME,
- SDOFacets.ISMANY_PROPERTIES,
- SDOFacets.GENERIC_DATA_GRAPH_TRAVERSAL,
- SDOFacets.SAVING_DATA_TO_XML
- };
-
- public void runSample() throws Exception {
-
- HelperContext scope = SDOUtil.createHelperContext();
-
- if (typesViaAPI) {
-
- commentary("In this execution of the sample we use Types created\n"
- + "using the SDO API");
-
- createTypesViaAPI(scope);
-
- } else {
-
- commentary("In this execution of the sample we use Types created\n"
- + "by loading an XMLSchema");
-
- loadTypesFromXMLSchemaFile(scope, "MedicalTest.xsd");
-
- }
-
- commentary(
- COMMENTARY_FOR_NOVICE,
- "The DataFactory associated with the scope that the types were created within\n"
- + "can be used to create an instance of the Person Type\n\n"
- + "DataFactory dataFactory = scope.getDataFactory();\n"
- + "DataObject person1 = dataFactory.create(\"www.example.org/people\", \"Person\");");
-
- DataFactory dataFactory = scope.getDataFactory();
- DataObject person1 = dataFactory.create("www.example.org/people", "Person");
-
- commentary("The setString() of dataObject method is used to set the properties of the\n"
- + "new Person DataObject, including a unique identifier reference value\n"
- + "for the Person instance.\n\n"
- + "person1.setString(\"id\", \"1\");\n"
- + "person1.setString(\"name\", \"Joe Johnson Snr.\");\n"
- + "person1.setString(\"gender\", \"male\"););");
-
- person1.setString("id", "1");
- person1.setString("name", "Joe Johnson Snr.");
- person1.setString("gender", "male");
-
- commentary("An alternative approach to using the DataFactory directly to create\n"
- + "all DataObjects is to use a top-down approach, where we create the\n"
- + "root object for a data graph, and then use the createDataObject(String propertyName)\n"
- + "method to create the contained DataObjects. Here we create the overall\n"
- + "medical test DataObject, and then create the contained \"referrals\" DataObject\n\n"
- + "DataObject test = dataFactory.create(\"www.example.org/MedicalTest\", \"Test\");\n"
- + "DataObject referrals = test.createDataObject(\"referrals\");");
-
- DataObject test = dataFactory.create("www.example.org/MedicalTest", "Test");
- DataObject referrals = test.createDataObject("referrals");
-
- commentary("Now we can add the person we created earlier into the set of people who have\n"
- + "been referred for this medical test.\n\n"
- + "test.set(\"referrals\", referrals);\n"
- + "referrals.getList(\"person\").add(person1);");
-
- test.set("referrals", referrals);
- referrals.getList("person").add(person1);
-
- commentary("Let's take a look at how the current state of the data"
- + "graph is rendered in XML ...");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("The scenario unfolds and the Joe Johnson Snr. becomes a patient\n\n"
- + "DataObject patients = test.createDataObject(\"patients\");\n"
- + "patients.getList(\"person\").add(person1);");
-
- DataObject patients = test.createDataObject("patients");
-
- patients.getList("person").add(person1);
-
- commentary("Having added Joe Johnson Snr. to the set of patients we can see\n"
- + "the way that SDO preserves a single containment hierarchy within a\n"
- + "datagraph. If we look at the XML rendering of the graph again, we will\n"
- + "see that by adding him to the set of patients he has been removed from the\n"
- + "containment property associated with the referrals set ...");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("The 'Person' Type we are making use of here has been designed to be\n"
- + "multi-purpose, in that the type has been declared to be 'Open'.\n"
- + "That means that we can make use of 'Open Content' Properties\n"
- + "(If the type system has been defined using an XML schema\n"
- + "then these properties will derive from global elements)\n"
- + "We can look up open content Properties using the TypeHelper\n\n"
- + "Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(\n"
- + " \"www.example.org/MedicalTest\", \"condition\");");
-
- Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(
- "www.example.org/MedicalTest", "condition");
-
- commentary("We can create a value of the appropriate Type for this open\n"
- + "content Property\n\n"
- + "DataObject condition = dataFactory.create(conditionProperty.getType());\n"
- + "condition.setString(\"name\", \"Panar Syndrome\");");
-
- DataObject condition = dataFactory.create(conditionProperty.getType());
- condition.setString("name", "Panar Syndrome");
-
- commentary("If you ask a DataObject that has an 'Open' Type for its list of\n"
- + "values associated with an open content Property, and the DataObject\n"
- + "doesn't currently have any values for the Property, it will return\n"
- + "an empty list. We can use the list to add values for the Property\n\n"
- + "List conditions = person1.getList(conditionProperty);\n"
- + "conditions.add(condition);");
-
- List conditions = person1.getList(conditionProperty);
- conditions.add(condition);
-
- commentary("A further look at the data graph in XML form shows\n"
- + "the presence of the new condition Property's value ...");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("Having looked at the way SDO handles Open content\n"
- + "We now turn our attention to 'non-containment' relationships.\n"
- + "To do this we first create the set of people in the test that\n"
- + "constitute the blood relatives of patients -- 'relatives'\n"
- + "and define a new person to be Joe Johnson Snr's child.\n\n"
- + "DataObject relatives = test.createDataObject(\"relatives\");\n"
- + "DataObject person2 = relatives.createDataObject(\"person\");\n"
- + "person2.setString(\"id\", \"2\");\n"
- + "person2.setString(\"name\", \"Joe Johnson Jnr.\");\n"
- + "person2.setString(\"gender\", \"male\");");
-
- DataObject relatives = test.createDataObject("relatives");
- DataObject person2 = relatives.createDataObject("person");
-
- person2.setString("id", "2");
- person2.setString("name", "Joe Johnson Jnr.");
- person2.setString("gender", "male");
-
- commentary("Another quick look at the XML rendering of the graph confirms that\n"
- + "the set of relatives now includes Joe Johnson Jnr, but we haven't yet\n"
- + "defined who he is related to, or how.");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("The Person type has a Property 'relative'\n"
- + "so we create a relative for Joe Johnson Snr.\n\n"
- + "DataObject relation = person1.createDataObject(\"relative\");\n"
- + "relation.set(\"target\", person2);\n"
- + "relation.set(\"relationship\", \"child\");");
-
- DataObject relation = person1.createDataObject("relative");
- relation.set("target", person2);
- relation.set("relationship", "child");
-
- commentary("Now when we look at the XML rendering of the data graph\n"
- + "we can see that the action of setting the 'target' of the\n"
- + "relationship to Joe Johnson Jnr didn't displace him from the\n"
- + "set of 'relatives', because the 'target' Property is a\n"
- + "non-containment Property. This non-containment relationship\n"
- + "is reflected in the XML by a reference to the Person DataObject\n"
- + "describing Joe Johnson Jnr, \"2\" ...\n"
- + "If the Type system has been created from an XML schema then the\n"
- + "unique ID of the target can be used in the serialization.\n"
- + "If however the type system was defined dynamically, then the reference\n"
- + "will be represented as an XPath from the root of the data graph.");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("Now that the graph is complete we can use the PrintDataGraph sample utility\n" +
- "to reveal the full SDO nature of the final data graph\n\n" +
- "");
-
- PrintDataGraph printer = new PrintDataGraph(COMMENTARY_FOR_ADVANCED);
- printer.printDataObject(test);
- System.out.println(printer.getBuf());
- }
-
- /**
- * @throws Exception
- * @throws FileNotFoundException
- */
- private void createTypesViaAPI(HelperContext scope) throws Exception {
-
- List typeDeclarations = new ArrayList();
-
- TypeHelper typeHelper = scope.getTypeHelper();
-
- Type stringType = typeHelper.getType(sdoApiUri, "String");
- Type dateType = typeHelper.getType(sdoApiUri, "Date");
- Type booleanType = typeHelper.getType(sdoApiUri, "Boolean");
-
- // <complexType name="Person">
- // <sequence>
- // <element name="dob" type="date"/>
- // <element name="relative" maxOccurs="unbounded" type="tns:Relative"/>
- // <any namespace="##other" processContents="lax" maxOccurs="unbounded"/>
- // </sequence>
- // <attribute name="id" type="ID"/>
- // <attribute name="name" type="string"/>
- // <attribute name="gender" type = "tns:Gender"/>
- // </complexType>
-
- DataObject personTypeDesc = createTypeDescription(scope, peopleURI,
- "Person");
- typeDeclarations.add(personTypeDesc);
-
- addPropertyDescription(personTypeDesc, stringType, "name");
- addPropertyDescription(personTypeDesc, dateType, "dob");
- addPropertyDescription(personTypeDesc, stringType, "id"); // set to unique
- // identifier?
- addPropertyDescription(personTypeDesc, stringType, "gender"); // restrict?
-
- DataObject relativeType = createTypeDescription(scope, peopleURI,
- "Relative"); // forward declare the Relative type
- typeDeclarations.add(relativeType);
-
- DataObject rp = addPropertyDescription(personTypeDesc, relativeType,
- "relative");
- rp.setBoolean("many", true);
- personTypeDesc.set("open", Boolean.TRUE);
-
- // <complexType name="Relative">
- // <attribute name="target" type="IDREF" sdoxml:propertyType="tns:Person"
- // use="required"/>
- // <attribute name="relationship" type="string" />
- // <attribute name="genetic" use="optional" type="boolean"/>
- // </complexType>
-
- addPropertyDescription(relativeType, stringType, "relationship");
- addPropertyDescription(relativeType, booleanType, "genetic");
- DataObject targetPersonProp = addPropertyDescription(relativeType,
- personTypeDesc, "target");
- targetPersonProp.setBoolean("containment", false);
-
- // <complexType name="PersonSet">
- // <sequence>
- // <element name="person" type="tns:Person" maxOccurs="unbounded"/>
- // </sequence>
- // </complexType>
-
- DataObject pSet = createTypeDescription(scope, peopleURI, "PersonSet");
- typeDeclarations.add(pSet);
- DataObject pSetProperty = addPropertyDescription(pSet, personTypeDesc,
- "person");
- pSetProperty.setBoolean("many", true);
-
- // <complexType name="Condition">
- // <sequence>
- // <element name="diagnosed" type="date" />
- // </sequence>
- // <attribute name="name" type="tns:ConditionName" />
- // </complexType>
-
- DataObject condition = createTypeDescription(scope, medicalURI, "Condition");
- typeDeclarations.add(condition);
- addPropertyDescription(condition, booleanType, "diagnosed");
- addPropertyDescription(condition, stringType, "name"); // constrain?
-
- // <complexType name="Test">
- // <sequence>
- // <element name="referrals" type="people:PersonSet" />
- // <element name="patients" type="people:PersonSet" />
- // <element name="relatives" type="people:PersonSet" />
- // </sequence>
- // </complexType>
-
- DataObject testType = createTypeDescription(scope, medicalURI, "Test");
- typeDeclarations.add(testType);
- addPropertyDescription(testType, pSet, "referrals");
- addPropertyDescription(testType, pSet, "patients");
- addPropertyDescription(testType, pSet, "relatives");
-
- List types = typeHelper.define(typeDeclarations);
-
- DataObject p = scope.getDataFactory().create("commonj.sdo", "Property");
- p.set("type", typeHelper.getType(medicalURI, "Condition"));
- p.set("name", "condition");
- p.setBoolean("many", true);
- p.setBoolean("containment", true); // why is this not the default?
-
- typeHelper.defineOpenContentProperty(medicalURI, p);
-
- }
-
- /**
- * @param uri
- * @param name
- * @return
- */
- private DataObject createTypeDescription(HelperContext scope, String uri,
- String name) {
- DataObject typeDesc = scope.getDataFactory().create(sdoApiUri, "Type");
- typeDesc.set("name", name);
- typeDesc.set("uri", uri);
- return typeDesc;
- }
-
- private DataObject addPropertyDescription(
- DataObject containerTypeDescription, Object propertyType,
- String propertyName) {
- DataObject property = containerTypeDescription.createDataObject("property");
- property.set("type", propertyType);
- property.setString("name", propertyName);
- property.setBoolean("containment", true);
- return property;
- }
-
-}
+/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.samples.sdo.advanced; + +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.samples.sdo.SampleBase; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * This sample is based on a 2 part article by Kelvin Goodson and Geoffrey Winn. + * See <A href="http://soa.sys-con.com/read/313547.htm">Part1</A> and <A + * href="http://soa.sys-con.com/read/358059.htm">Part 2</A> of the article. + * <p> + * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html" + * target="_top">the main overview</A> for instructions on how to run this + * sample. + */ +public class MedicalScenario extends SampleBase { + + private static final String sdoApiUri = "commonj.sdo"; + + private static final String peopleURI = "www.example.org/people"; + + private static final String medicalURI = "www.example.org/MedicalTest"; + + boolean typesViaAPI = false; + + private static final String usage = " [-api |-xsd]\n" + + " -api : define the types using the SDO API\n" + + " -xsd : define the types using an XML schema file"; + + public MedicalScenario(String[] args, Integer userLevel) { + + super(userLevel, SAMPLE_LEVEL_ADVANCED); + + if (args.length > 1) { + printUsage(args); + System.exit(-1); + } + if (args.length == 1) { + if (args[0].equals("-xsd")) { + typesViaAPI = false; + } else if (args[0].equals("-api")) { + typesViaAPI = true; + } else { + printUsage(args); + System.exit(-1); + } + } + } + + public MedicalScenario(Integer userLevel) { + super(userLevel, SAMPLE_LEVEL_ADVANCED); + } + + + private void printUsage(String[] args) { + System.out.println("Usage: " + this.getClass().getName() + usage); + } + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + + MedicalScenario s = new MedicalScenario(args, COMMENTARY_FOR_NOVICE); + s.run(); + + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.CONTAINMENT, + SDOFacets.CREATE_TYPES_USING_THE_SDO_API, + SDOFacets.CREATE_TYPES_USING_XML_SCHEMA, + SDOFacets.OPEN_CONTENT, + SDOFacets.NON_CONTAINMENT + }; + + public static int [] SIGNIFICANT_FUNCTION = { + SDOFacets.CREATE_DATAOBJECTS_BY_NAME, + SDOFacets.ISMANY_PROPERTIES, + SDOFacets.GENERIC_DATA_GRAPH_TRAVERSAL, + SDOFacets.SAVING_DATA_TO_XML + }; + + public void runSample() throws Exception { + + HelperContext scope = SDOUtil.createHelperContext(); + + if (typesViaAPI) { + + commentary("In this execution of the sample we use Types created\n" + + "using the SDO API"); + + createTypesViaAPI(scope); + + } else { + + commentary("In this execution of the sample we use Types created\n" + + "by loading an XMLSchema"); + + loadTypesFromXMLSchemaFile(scope, "MedicalTest.xsd"); + + } + + commentary( + COMMENTARY_FOR_NOVICE, + "The DataFactory associated with the scope that the types were created within\n" + + "can be used to create an instance of the Person Type\n\n" + + "DataFactory dataFactory = scope.getDataFactory();\n" + + "DataObject person1 = dataFactory.create(\"www.example.org/people\", \"Person\");"); + + DataFactory dataFactory = scope.getDataFactory(); + DataObject person1 = dataFactory.create("www.example.org/people", "Person"); + + commentary("The setString() of dataObject method is used to set the properties of the\n" + + "new Person DataObject, including a unique identifier reference value\n" + + "for the Person instance.\n\n" + + "person1.setString(\"id\", \"1\");\n" + + "person1.setString(\"name\", \"Joe Johnson Snr.\");\n" + + "person1.setString(\"gender\", \"male\"););"); + + person1.setString("id", "1"); + person1.setString("name", "Joe Johnson Snr."); + person1.setString("gender", "male"); + + commentary("An alternative approach to using the DataFactory directly to create\n" + + "all DataObjects is to use a top-down approach, where we create the\n" + + "root object for a data graph, and then use the createDataObject(String propertyName)\n" + + "method to create the contained DataObjects. Here we create the overall\n" + + "medical test DataObject, and then create the contained \"referrals\" DataObject\n\n" + + "DataObject test = dataFactory.create(\"www.example.org/MedicalTest\", \"Test\");\n" + + "DataObject referrals = test.createDataObject(\"referrals\");"); + + DataObject test = dataFactory.create("www.example.org/MedicalTest", "Test"); + DataObject referrals = test.createDataObject("referrals"); + + commentary("Now we can add the person we created earlier into the set of people who have\n" + + "been referred for this medical test.\n\n" + + "test.set(\"referrals\", referrals);\n" + + "referrals.getList(\"person\").add(person1);"); + + test.set("referrals", referrals); + referrals.getList("person").add(person1); + + commentary("Let's take a look at how the current state of the data" + + "graph is rendered in XML ..."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("The scenario unfolds and the Joe Johnson Snr. becomes a patient\n\n" + + "DataObject patients = test.createDataObject(\"patients\");\n" + + "patients.getList(\"person\").add(person1);"); + + DataObject patients = test.createDataObject("patients"); + + patients.getList("person").add(person1); + + commentary("Having added Joe Johnson Snr. to the set of patients we can see\n" + + "the way that SDO preserves a single containment hierarchy within a\n" + + "datagraph. If we look at the XML rendering of the graph again, we will\n" + + "see that by adding him to the set of patients he has been removed from the\n" + + "containment property associated with the referrals set ..."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("The 'Person' Type we are making use of here has been designed to be\n" + + "multi-purpose, in that the type has been declared to be 'Open'.\n" + + "That means that we can make use of 'Open Content' Properties\n" + + "(If the type system has been defined using an XML schema\n" + + "then these properties will derive from global elements)\n" + + "We can look up open content Properties using the TypeHelper\n\n" + + "Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(\n" + + " \"www.example.org/MedicalTest\", \"condition\");"); + + Property conditionProperty = scope.getTypeHelper().getOpenContentProperty( + "www.example.org/MedicalTest", "condition"); + + commentary("We can create a value of the appropriate Type for this open\n" + + "content Property\n\n" + + "DataObject condition = dataFactory.create(conditionProperty.getType());\n" + + "condition.setString(\"name\", \"Panar Syndrome\");"); + + DataObject condition = dataFactory.create(conditionProperty.getType()); + condition.setString("name", "Panar Syndrome"); + + commentary("If you ask a DataObject that has an 'Open' Type for its list of\n" + + "values associated with an open content Property, and the DataObject\n" + + "doesn't currently have any values for the Property, it will return\n" + + "an empty list. We can use the list to add values for the Property\n\n" + + "List conditions = person1.getList(conditionProperty);\n" + + "conditions.add(condition);"); + + List conditions = person1.getList(conditionProperty); + conditions.add(condition); + + commentary("A further look at the data graph in XML form shows\n" + + "the presence of the new condition Property's value ..."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("Having looked at the way SDO handles Open content\n" + + "We now turn our attention to 'non-containment' relationships.\n" + + "To do this we first create the set of people in the test that\n" + + "constitute the blood relatives of patients -- 'relatives'\n" + + "and define a new person to be Joe Johnson Snr's child.\n\n" + + "DataObject relatives = test.createDataObject(\"relatives\");\n" + + "DataObject person2 = relatives.createDataObject(\"person\");\n" + + "person2.setString(\"id\", \"2\");\n" + + "person2.setString(\"name\", \"Joe Johnson Jnr.\");\n" + + "person2.setString(\"gender\", \"male\");"); + + DataObject relatives = test.createDataObject("relatives"); + DataObject person2 = relatives.createDataObject("person"); + + person2.setString("id", "2"); + person2.setString("name", "Joe Johnson Jnr."); + person2.setString("gender", "male"); + + commentary("Another quick look at the XML rendering of the graph confirms that\n" + + "the set of relatives now includes Joe Johnson Jnr, but we haven't yet\n" + + "defined who he is related to, or how."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("The Person type has a Property 'relative'\n" + + "so we create a relative for Joe Johnson Snr.\n\n" + + "DataObject relation = person1.createDataObject(\"relative\");\n" + + "relation.set(\"target\", person2);\n" + + "relation.set(\"relationship\", \"child\");"); + + DataObject relation = person1.createDataObject("relative"); + relation.set("target", person2); + relation.set("relationship", "child"); + + commentary("Now when we look at the XML rendering of the data graph\n" + + "we can see that the action of setting the 'target' of the\n" + + "relationship to Joe Johnson Jnr didn't displace him from the\n" + + "set of 'relatives', because the 'target' Property is a\n" + + "non-containment Property. This non-containment relationship\n" + + "is reflected in the XML by a reference to the Person DataObject\n" + + "describing Joe Johnson Jnr, \"2\" ...\n" + + "If the Type system has been created from an XML schema then the\n" + + "unique ID of the target can be used in the serialization.\n" + + "If however the type system was defined dynamically, then the reference\n" + + "will be represented as an XPath from the root of the data graph."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("Now that the graph is complete we can use the PrintDataGraph sample utility\n" + + "to reveal the full SDO nature of the final data graph\n\n" + + ""); + + PrintDataGraph printer = new PrintDataGraph(COMMENTARY_FOR_ADVANCED); + printer.printDataObject(test); + System.out.println(printer.getBuf()); + } + + /** + * @throws Exception + * @throws FileNotFoundException + */ + private void createTypesViaAPI(HelperContext scope) throws Exception { + + List typeDeclarations = new ArrayList(); + + TypeHelper typeHelper = scope.getTypeHelper(); + + Type stringType = typeHelper.getType(sdoApiUri, "String"); + Type dateType = typeHelper.getType(sdoApiUri, "Date"); + Type booleanType = typeHelper.getType(sdoApiUri, "Boolean"); + + // <complexType name="Person"> + // <sequence> + // <element name="dob" type="date"/> + // <element name="relative" maxOccurs="unbounded" type="tns:Relative"/> + // <any namespace="##other" processContents="lax" maxOccurs="unbounded"/> + // </sequence> + // <attribute name="id" type="ID"/> + // <attribute name="name" type="string"/> + // <attribute name="gender" type = "tns:Gender"/> + // </complexType> + + DataObject personTypeDesc = createTypeDescription(scope, peopleURI, + "Person"); + typeDeclarations.add(personTypeDesc); + + addPropertyDescription(personTypeDesc, stringType, "name"); + addPropertyDescription(personTypeDesc, dateType, "dob"); + addPropertyDescription(personTypeDesc, stringType, "id"); // set to unique + // identifier? + addPropertyDescription(personTypeDesc, stringType, "gender"); // restrict? + + DataObject relativeType = createTypeDescription(scope, peopleURI, + "Relative"); // forward declare the Relative type + typeDeclarations.add(relativeType); + + DataObject rp = addPropertyDescription(personTypeDesc, relativeType, + "relative"); + rp.setBoolean("many", true); + personTypeDesc.set("open", Boolean.TRUE); + + // <complexType name="Relative"> + // <attribute name="target" type="IDREF" sdoxml:propertyType="tns:Person" + // use="required"/> + // <attribute name="relationship" type="string" /> + // <attribute name="genetic" use="optional" type="boolean"/> + // </complexType> + + addPropertyDescription(relativeType, stringType, "relationship"); + addPropertyDescription(relativeType, booleanType, "genetic"); + DataObject targetPersonProp = addPropertyDescription(relativeType, + personTypeDesc, "target"); + targetPersonProp.setBoolean("containment", false); + + // <complexType name="PersonSet"> + // <sequence> + // <element name="person" type="tns:Person" maxOccurs="unbounded"/> + // </sequence> + // </complexType> + + DataObject pSet = createTypeDescription(scope, peopleURI, "PersonSet"); + typeDeclarations.add(pSet); + DataObject pSetProperty = addPropertyDescription(pSet, personTypeDesc, + "person"); + pSetProperty.setBoolean("many", true); + + // <complexType name="Condition"> + // <sequence> + // <element name="diagnosed" type="date" /> + // </sequence> + // <attribute name="name" type="tns:ConditionName" /> + // </complexType> + + DataObject condition = createTypeDescription(scope, medicalURI, "Condition"); + typeDeclarations.add(condition); + addPropertyDescription(condition, booleanType, "diagnosed"); + addPropertyDescription(condition, stringType, "name"); // constrain? + + // <complexType name="Test"> + // <sequence> + // <element name="referrals" type="people:PersonSet" /> + // <element name="patients" type="people:PersonSet" /> + // <element name="relatives" type="people:PersonSet" /> + // </sequence> + // </complexType> + + DataObject testType = createTypeDescription(scope, medicalURI, "Test"); + typeDeclarations.add(testType); + addPropertyDescription(testType, pSet, "referrals"); + addPropertyDescription(testType, pSet, "patients"); + addPropertyDescription(testType, pSet, "relatives"); + + List types = typeHelper.define(typeDeclarations); + + DataObject p = scope.getDataFactory().create("commonj.sdo", "Property"); + p.set("type", typeHelper.getType(medicalURI, "Condition")); + p.set("name", "condition"); + p.setBoolean("many", true); + p.setBoolean("containment", true); // why is this not the default? + + typeHelper.defineOpenContentProperty(medicalURI, p); + + } + + /** + * @param uri + * @param name + * @return + */ + private DataObject createTypeDescription(HelperContext scope, String uri, + String name) { + DataObject typeDesc = scope.getDataFactory().create(sdoApiUri, "Type"); + typeDesc.set("name", name); + typeDesc.set("uri", uri); + return typeDesc; + } + + private DataObject addPropertyDescription( + DataObject containerTypeDescription, Object propertyType, + String propertyName) { + DataObject property = containerTypeDescription.createDataObject("property"); + property.set("type", propertyType); + property.setString("name", propertyName); + property.setBoolean("containment", true); + return property; + } + +} diff --git a/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/MedicalScenarioWithChangeMonitoring.java b/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/MedicalScenarioWithChangeMonitoring.java index 0dc93b0008..32d63f4335 100644 --- a/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/MedicalScenarioWithChangeMonitoring.java +++ b/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/MedicalScenarioWithChangeMonitoring.java @@ -1,449 +1,449 @@ -/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.samples.sdo.advanced;
-
-import java.io.FileNotFoundException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tuscany.samples.sdo.SampleBase;
-import org.apache.tuscany.sdo.api.SDOUtil;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.Property;
-import commonj.sdo.Type;
-import commonj.sdo.helper.DataFactory;
-import commonj.sdo.helper.HelperContext;
-import commonj.sdo.helper.TypeHelper;
-
-/**
- * This sample is based on a 2 part article by Kelvin Goodson and Geoffrey Winn.
- * In this variant of the sample the model for the test includes change monitoring.
- * The facility for undoing changes on the basis of the change monitoring is
- * demonstrated.
- * See <A href="http://soa.sys-con.com/read/313547.htm">Part1</A> and <A
- * href="http://soa.sys-con.com/read/358059.htm">Part 2</A> of the article.
- * <p>
- * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html"
- * target="_top">the main overview</A> for instructions on how to run this
- * sample.
- */
-public class MedicalScenarioWithChangeMonitoring extends SampleBase {
-
- private static final String sdoApiUri = "commonj.sdo";
-
- private static final String peopleURI = "www.example.org/people";
-
- private static final String medicalURI = "www.example.org/MedicalTest";
-
- boolean typesViaAPI = false;
-
- private static final String usage = " [-api |-xsd]\n"
- + " -api : define the types using the SDO API\n"
- + " -xsd : define the types using an XML schema file";
-
- public MedicalScenarioWithChangeMonitoring(String[] args, Integer userLevel) {
-
- super(userLevel, SAMPLE_LEVEL_ADVANCED);
-
- if (args.length > 1) {
- printUsage(args);
- System.exit(-1);
- }
- if (args.length == 1) {
- if (args[0].equals("-xsd")) {
- typesViaAPI = false;
- } else if (args[0].equals("-api")) {
- typesViaAPI = true;
- } else {
- printUsage(args);
- System.exit(-1);
- }
- }
- }
-
- public MedicalScenarioWithChangeMonitoring(Integer userLevel) {
- super(userLevel, SAMPLE_LEVEL_ADVANCED);
- }
-
-
- private void printUsage(String[] args) {
- System.out.println("Usage: " + this.getClass().getName() + usage);
- }
-
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
-
- MedicalScenarioWithChangeMonitoring s = new MedicalScenarioWithChangeMonitoring(args, COMMENTARY_FOR_NOVICE);
- s.run();
-
- }
-
- /*
- * metadata for the sample documenting the areas of SDO that are explored
- */
- public static int [] CORE_FUNCTION = {
- SDOFacets.CONTAINMENT,
- SDOFacets.CREATE_TYPES_USING_THE_SDO_API,
- SDOFacets.CREATE_TYPES_USING_XML_SCHEMA,
- SDOFacets.OPEN_CONTENT,
- SDOFacets.NON_CONTAINMENT,
- SDOFacets.CHANGE_MONITORING_USING_A_CHANGESUMMARY_PROPERTY_ON_A_DATAOBJECT
- };
-
- public static int [] SIGNIFICANT_FUNCTION = {
- SDOFacets.CREATE_DATAOBJECTS_BY_NAME,
- SDOFacets.ISMANY_PROPERTIES,
- SDOFacets.GENERIC_DATA_GRAPH_TRAVERSAL,
- SDOFacets.SAVING_DATA_TO_XML
- };
-
- public void runSample() throws Exception {
-
- HelperContext scope = SDOUtil.createHelperContext();
-
- if (typesViaAPI) {
-
- commentary("In this execution of the sample we use Types created\n"
- + "using the SDO API");
-
- createTypesViaAPI(scope);
-
- } else {
-
- commentary("In this execution of the sample we use Types created\n"
- + "by loading a variant of the XMLSchema that includes a change summary Property");
-
- loadTypesFromXMLSchemaFile(scope, "MedicalTest_CS.xsd");
-
- }
-
- commentary(
- COMMENTARY_FOR_NOVICE,
- "The DataFactory associated with the scope that the types were created within\n"
- + "can be used to create an instance of the Person Type\n\n"
- + "DataFactory dataFactory = scope.getDataFactory();\n"
- + "DataObject person1 = dataFactory.create(\"www.example.org/people\", \"Person\");");
-
- DataFactory dataFactory = scope.getDataFactory();
- DataObject person1 = dataFactory.create("www.example.org/people", "Person");
-
- commentary("The setString() of dataObject method is used to set the properties of the\n"
- + "new Person DataObject, including a unique identifier reference value\n"
- + "for the Person instance.\n\n"
- + "person1.setString(\"id\", \"1\");\n"
- + "person1.setString(\"name\", \"Joe Johnson Snr.\");\n"
- + "person1.setString(\"gender\", \"male\"););");
-
- person1.setString("id", "1");
- person1.setString("name", "Joe Johnson Snr.");
- person1.setString("gender", "male");
-
- commentary("An alternative approach to using the DataFactory directly to create\n"
- + "all DataObjects is to use a top-down approach, where we create the\n"
- + "root object for a data graph, and then use the createDataObject(String propertyName)\n"
- + "method to create the contained DataObjects. Here we create the overall\n"
- + "medical test DataObject, and then create the contained \"referrals\" DataObject\n\n"
- + "DataObject test = dataFactory.create(\"www.example.org/MedicalTest\", \"Test\");\n"
- + "DataObject referrals = test.createDataObject(\"referrals\");");
-
- DataObject test = dataFactory.create("www.example.org/MedicalTest", "Test");
-
- DataObject referrals = test.createDataObject("referrals");
-
- commentary("The default state for monitoring changes for the DataObject when created in this\n" +
- "way is the monitoring is switched off, so we switch it on. (Note that if you\n" +
- "get your data graphs from a data Access Service then this service may turn on\n" +
- "change monitoring be default\n\n" +
- "test.getChangeSummary().beginLogging();");
- test.getChangeSummary().beginLogging();
-
- commentary("We'll repeat the whole of the MedicalScenario sample, but then at the \n" +
- "last minute we'll decide it was all wrong and roll back the changes......");
-
- commentary("Now we can add the person we created earlier into the set of people who have\n"
- + "been referred for this medical test.\n\n"
- + "test.set(\"referrals\", referrals);\n"
- + "referrals.getList(\"person\").add(person1);");
-
- test.set("referrals", referrals);
- referrals.getList("person").add(person1);
-
- commentary("Let's take a look at how the current state of the data"
- + "graph is rendered in XML ...");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("The scenario unfolds and the Joe Johnson Snr. becomes a patient\n\n"
- + "DataObject patients = test.createDataObject(\"patients\");\n"
- + "patients.getList(\"person\").add(person1);");
-
- DataObject patients = test.createDataObject("patients");
-
- patients.getList("person").add(person1);
-
- commentary("Having added Joe Johnson Snr. to the set of patients we can see\n"
- + "the way that SDO preserves a single containment hierarchy within a\n"
- + "datagraph. If we look at the XML rendering of the graph again, we will\n"
- + "see that by adding him to the set of patients he has been removed from the\n"
- + "containment property associated with the referrals set ...");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("The 'Person' Type we are making use of here has been designed to be\n"
- + "multi-purpose, in that the type has been declared to be 'Open'.\n"
- + "That means that we can make use of 'Open Content' Properties\n"
- + "(If the type system has been defined using an XML schema\n"
- + "then these properties will derive from global elements)\n"
- + "We can look up open content Properties using the TypeHelper\n\n"
- + "Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(\n"
- + " \"www.example.org/MedicalTest\", \"condition\");");
-
- Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(
- "www.example.org/MedicalTest", "condition");
-
- commentary("We can create a value of the appropriate Type for this open\n"
- + "content Property\n\n"
- + "DataObject condition = dataFactory.create(conditionProperty.getType());\n"
- + "condition.setString(\"name\", \"Panar Syndrome\");");
-
- DataObject condition = dataFactory.create(conditionProperty.getType());
- condition.setString("name", "Panar Syndrome");
-
- commentary("If you ask a DataObject that has an 'Open' Type for its list of\n"
- + "values associated with an open content Property, and the DataObject\n"
- + "doesn't currently have any values for the Property, it will return\n"
- + "an empty list. We can use the list to add values for the Property\n\n"
- + "List conditions = person1.getList(conditionProperty);\n"
- + "conditions.add(condition);");
-
- List conditions = person1.getList(conditionProperty);
- conditions.add(condition);
-
- commentary("A further look at the data graph in XML form shows\n"
- + "the presence of the new condition Property's value ...");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("Having looked at the way SDO handles Open content\n"
- + "We now turn our attention to 'non-containment' relationships.\n"
- + "To do this we first create the set of people in the test that\n"
- + "constitute the blood relatives of patients -- 'relatives'\n"
- + "and define a new person to be Joe Johnson Snr's child.\n\n"
- + "DataObject relatives = test.createDataObject(\"relatives\");\n"
- + "DataObject person2 = relatives.createDataObject(\"person\");\n"
- + "person2.setString(\"id\", \"2\");\n"
- + "person2.setString(\"name\", \"Joe Johnson Jnr.\");\n"
- + "person2.setString(\"gender\", \"male\");");
-
- DataObject relatives = test.createDataObject("relatives");
- DataObject person2 = relatives.createDataObject("person");
-
- person2.setString("id", "2");
- person2.setString("name", "Joe Johnson Jnr.");
- person2.setString("gender", "male");
-
- commentary("Another quick look at the XML rendering of the graph confirms that\n"
- + "the set of relatives now includes Joe Johnson Jnr, but we haven't yet\n"
- + "defined who he is related to, or how.");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("The Person type has a Property 'relative'\n"
- + "so we create a relative for Joe Johnson Snr.\n\n"
- + "DataObject relation = person1.createDataObject(\"relative\");\n"
- + "relation.set(\"target\", person2);\n"
- + "relation.set(\"relationship\", \"child\");");
-
- DataObject relation = person1.createDataObject("relative");
- relation.set("target", person2);
- relation.set("relationship", "child");
-
- commentary("Now when we look at the XML rendering of the data graph\n"
- + "we can see that the action of setting the 'target' of the\n"
- + "relationship to Joe Johnson Jnr didn't displace him from the\n"
- + "set of 'relatives', because the 'target' Property is a\n"
- + "non-containment Property. This non-containment relationship\n"
- + "is reflected in the XML by a reference to the Person DataObject\n"
- + "describing Joe Johnson Jnr, \"2\" ...\n"
- + "If the Type system has been created from an XML schema then the\n"
- + "unique ID of the target can be used in the serialization.\n"
- + "If however the type system was defined dynamically, then the reference\n"
- + "will be represented as an XPath from the root of the data graph.");
-
- System.out.println(scope.getXMLHelper().save(test,
- "www.example.org/MedicalTest", "test"));
-
- commentary("Now that the graph is complete we can use the PrintDataGraph sample utility\n" +
- "to reveal the full SDO nature of the final data graph\n\n" +
- "");
-
- PrintDataGraph printer = new PrintDataGraph(COMMENTARY_FOR_ADVANCED);
- printer.printDataObject(test);
- System.out.println(printer.getBuf());
-
- commentary("But Wait! it's all wrong. Let's go back to our checkpoint where we started monitoring changes\n\n" +
- "test.getChangeSummary().undoChanges();");
-
- test.getChangeSummary().undoChanges();
-
- printer.reset();
- printer.printDataObject(test);
- System.out.println(printer.getBuf());
-
- }
-
- /**
- * @throws Exception
- * @throws FileNotFoundException
- */
- private void createTypesViaAPI(HelperContext scope) throws Exception {
-
- List typeDeclarations = new ArrayList();
-
- TypeHelper typeHelper = scope.getTypeHelper();
-
- Type stringType = typeHelper.getType(sdoApiUri, "String");
- Type dateType = typeHelper.getType(sdoApiUri, "Date");
- Type booleanType = typeHelper.getType(sdoApiUri, "Boolean");
-
- // <complexType name="Person">
- // <sequence>
- // <element name="dob" type="date"/>
- // <element name="relative" maxOccurs="unbounded" type="tns:Relative"/>
- // <any namespace="##other" processContents="lax" maxOccurs="unbounded"/>
- // </sequence>
- // <attribute name="id" type="ID"/>
- // <attribute name="name" type="string"/>
- // <attribute name="gender" type = "tns:Gender"/>
- // </complexType>
-
- DataObject personTypeDesc = createTypeDescription(scope, peopleURI,
- "Person");
- typeDeclarations.add(personTypeDesc);
-
- addPropertyDescription(personTypeDesc, stringType, "name");
- addPropertyDescription(personTypeDesc, dateType, "dob");
- addPropertyDescription(personTypeDesc, stringType, "id"); // set to unique
- // identifier?
- addPropertyDescription(personTypeDesc, stringType, "gender"); // restrict?
-
- DataObject relativeType = createTypeDescription(scope, peopleURI,
- "Relative"); // forward declare the Relative type
- typeDeclarations.add(relativeType);
-
- DataObject rp = addPropertyDescription(personTypeDesc, relativeType,
- "relative");
- rp.setBoolean("many", true);
- personTypeDesc.set("open", Boolean.TRUE);
-
- // <complexType name="Relative">
- // <attribute name="target" type="IDREF" sdoxml:propertyType="tns:Person"
- // use="required"/>
- // <attribute name="relationship" type="string" />
- // <attribute name="genetic" use="optional" type="boolean"/>
- // </complexType>
-
- addPropertyDescription(relativeType, stringType, "relationship");
- addPropertyDescription(relativeType, booleanType, "genetic");
- DataObject targetPersonProp = addPropertyDescription(relativeType,
- personTypeDesc, "target");
- targetPersonProp.setBoolean("containment", false);
-
- // <complexType name="PersonSet">
- // <sequence>
- // <element name="person" type="tns:Person" maxOccurs="unbounded"/>
- // </sequence>
- // </complexType>
-
- DataObject pSet = createTypeDescription(scope, peopleURI, "PersonSet");
- typeDeclarations.add(pSet);
- DataObject pSetProperty = addPropertyDescription(pSet, personTypeDesc,
- "person");
- pSetProperty.setBoolean("many", true);
-
- // <complexType name="Condition">
- // <sequence>
- // <element name="diagnosed" type="date" />
- // </sequence>
- // <attribute name="name" type="tns:ConditionName" />
- // </complexType>
-
- DataObject condition = createTypeDescription(scope, medicalURI, "Condition");
- typeDeclarations.add(condition);
- addPropertyDescription(condition, booleanType, "diagnosed");
- addPropertyDescription(condition, stringType, "name"); // constrain?
-
- // <complexType name="Test">
- // <sequence>
- // <element name="referrals" type="people:PersonSet" />
- // <element name="patients" type="people:PersonSet" />
- // <element name="relatives" type="people:PersonSet" />
- // </sequence>
- // </complexType>
-
- DataObject testType = createTypeDescription(scope, medicalURI, "Test");
- typeDeclarations.add(testType);
- addPropertyDescription(testType, pSet, "referrals");
- addPropertyDescription(testType, pSet, "patients");
- addPropertyDescription(testType, pSet, "relatives");
-
- List types = typeHelper.define(typeDeclarations);
-
- DataObject p = scope.getDataFactory().create("commonj.sdo", "Property");
- p.set("type", typeHelper.getType(medicalURI, "Condition"));
- p.set("name", "condition");
- p.setBoolean("many", true);
- p.setBoolean("containment", true); // why is this not the default?
-
- typeHelper.defineOpenContentProperty(medicalURI, p);
-
- }
-
- /**
- * @param uri
- * @param name
- * @return
- */
- private DataObject createTypeDescription(HelperContext scope, String uri,
- String name) {
- DataObject typeDesc = scope.getDataFactory().create(sdoApiUri, "Type");
- typeDesc.set("name", name);
- typeDesc.set("uri", uri);
- return typeDesc;
- }
-
- private DataObject addPropertyDescription(
- DataObject containerTypeDescription, Object propertyType,
- String propertyName) {
- DataObject property = containerTypeDescription.createDataObject("property");
- property.set("type", propertyType);
- property.setString("name", propertyName);
- property.setBoolean("containment", true);
- return property;
- }
-
-}
+/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.samples.sdo.advanced; + +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.samples.sdo.SampleBase; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * This sample is based on a 2 part article by Kelvin Goodson and Geoffrey Winn. + * In this variant of the sample the model for the test includes change monitoring. + * The facility for undoing changes on the basis of the change monitoring is + * demonstrated. + * See <A href="http://soa.sys-con.com/read/313547.htm">Part1</A> and <A + * href="http://soa.sys-con.com/read/358059.htm">Part 2</A> of the article. + * <p> + * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html" + * target="_top">the main overview</A> for instructions on how to run this + * sample. + */ +public class MedicalScenarioWithChangeMonitoring extends SampleBase { + + private static final String sdoApiUri = "commonj.sdo"; + + private static final String peopleURI = "www.example.org/people"; + + private static final String medicalURI = "www.example.org/MedicalTest"; + + boolean typesViaAPI = false; + + private static final String usage = " [-api |-xsd]\n" + + " -api : define the types using the SDO API\n" + + " -xsd : define the types using an XML schema file"; + + public MedicalScenarioWithChangeMonitoring(String[] args, Integer userLevel) { + + super(userLevel, SAMPLE_LEVEL_ADVANCED); + + if (args.length > 1) { + printUsage(args); + System.exit(-1); + } + if (args.length == 1) { + if (args[0].equals("-xsd")) { + typesViaAPI = false; + } else if (args[0].equals("-api")) { + typesViaAPI = true; + } else { + printUsage(args); + System.exit(-1); + } + } + } + + public MedicalScenarioWithChangeMonitoring(Integer userLevel) { + super(userLevel, SAMPLE_LEVEL_ADVANCED); + } + + + private void printUsage(String[] args) { + System.out.println("Usage: " + this.getClass().getName() + usage); + } + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + + MedicalScenarioWithChangeMonitoring s = new MedicalScenarioWithChangeMonitoring(args, COMMENTARY_FOR_NOVICE); + s.run(); + + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.CONTAINMENT, + SDOFacets.CREATE_TYPES_USING_THE_SDO_API, + SDOFacets.CREATE_TYPES_USING_XML_SCHEMA, + SDOFacets.OPEN_CONTENT, + SDOFacets.NON_CONTAINMENT, + SDOFacets.CHANGE_MONITORING_USING_A_CHANGESUMMARY_PROPERTY_ON_A_DATAOBJECT + }; + + public static int [] SIGNIFICANT_FUNCTION = { + SDOFacets.CREATE_DATAOBJECTS_BY_NAME, + SDOFacets.ISMANY_PROPERTIES, + SDOFacets.GENERIC_DATA_GRAPH_TRAVERSAL, + SDOFacets.SAVING_DATA_TO_XML + }; + + public void runSample() throws Exception { + + HelperContext scope = SDOUtil.createHelperContext(); + + if (typesViaAPI) { + + commentary("In this execution of the sample we use Types created\n" + + "using the SDO API"); + + createTypesViaAPI(scope); + + } else { + + commentary("In this execution of the sample we use Types created\n" + + "by loading a variant of the XMLSchema that includes a change summary Property"); + + loadTypesFromXMLSchemaFile(scope, "MedicalTest_CS.xsd"); + + } + + commentary( + COMMENTARY_FOR_NOVICE, + "The DataFactory associated with the scope that the types were created within\n" + + "can be used to create an instance of the Person Type\n\n" + + "DataFactory dataFactory = scope.getDataFactory();\n" + + "DataObject person1 = dataFactory.create(\"www.example.org/people\", \"Person\");"); + + DataFactory dataFactory = scope.getDataFactory(); + DataObject person1 = dataFactory.create("www.example.org/people", "Person"); + + commentary("The setString() of dataObject method is used to set the properties of the\n" + + "new Person DataObject, including a unique identifier reference value\n" + + "for the Person instance.\n\n" + + "person1.setString(\"id\", \"1\");\n" + + "person1.setString(\"name\", \"Joe Johnson Snr.\");\n" + + "person1.setString(\"gender\", \"male\"););"); + + person1.setString("id", "1"); + person1.setString("name", "Joe Johnson Snr."); + person1.setString("gender", "male"); + + commentary("An alternative approach to using the DataFactory directly to create\n" + + "all DataObjects is to use a top-down approach, where we create the\n" + + "root object for a data graph, and then use the createDataObject(String propertyName)\n" + + "method to create the contained DataObjects. Here we create the overall\n" + + "medical test DataObject, and then create the contained \"referrals\" DataObject\n\n" + + "DataObject test = dataFactory.create(\"www.example.org/MedicalTest\", \"Test\");\n" + + "DataObject referrals = test.createDataObject(\"referrals\");"); + + DataObject test = dataFactory.create("www.example.org/MedicalTest", "Test"); + + DataObject referrals = test.createDataObject("referrals"); + + commentary("The default state for monitoring changes for the DataObject when created in this\n" + + "way is the monitoring is switched off, so we switch it on. (Note that if you\n" + + "get your data graphs from a data Access Service then this service may turn on\n" + + "change monitoring be default\n\n" + + "test.getChangeSummary().beginLogging();"); + test.getChangeSummary().beginLogging(); + + commentary("We'll repeat the whole of the MedicalScenario sample, but then at the \n" + + "last minute we'll decide it was all wrong and roll back the changes......"); + + commentary("Now we can add the person we created earlier into the set of people who have\n" + + "been referred for this medical test.\n\n" + + "test.set(\"referrals\", referrals);\n" + + "referrals.getList(\"person\").add(person1);"); + + test.set("referrals", referrals); + referrals.getList("person").add(person1); + + commentary("Let's take a look at how the current state of the data" + + "graph is rendered in XML ..."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("The scenario unfolds and the Joe Johnson Snr. becomes a patient\n\n" + + "DataObject patients = test.createDataObject(\"patients\");\n" + + "patients.getList(\"person\").add(person1);"); + + DataObject patients = test.createDataObject("patients"); + + patients.getList("person").add(person1); + + commentary("Having added Joe Johnson Snr. to the set of patients we can see\n" + + "the way that SDO preserves a single containment hierarchy within a\n" + + "datagraph. If we look at the XML rendering of the graph again, we will\n" + + "see that by adding him to the set of patients he has been removed from the\n" + + "containment property associated with the referrals set ..."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("The 'Person' Type we are making use of here has been designed to be\n" + + "multi-purpose, in that the type has been declared to be 'Open'.\n" + + "That means that we can make use of 'Open Content' Properties\n" + + "(If the type system has been defined using an XML schema\n" + + "then these properties will derive from global elements)\n" + + "We can look up open content Properties using the TypeHelper\n\n" + + "Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(\n" + + " \"www.example.org/MedicalTest\", \"condition\");"); + + Property conditionProperty = scope.getTypeHelper().getOpenContentProperty( + "www.example.org/MedicalTest", "condition"); + + commentary("We can create a value of the appropriate Type for this open\n" + + "content Property\n\n" + + "DataObject condition = dataFactory.create(conditionProperty.getType());\n" + + "condition.setString(\"name\", \"Panar Syndrome\");"); + + DataObject condition = dataFactory.create(conditionProperty.getType()); + condition.setString("name", "Panar Syndrome"); + + commentary("If you ask a DataObject that has an 'Open' Type for its list of\n" + + "values associated with an open content Property, and the DataObject\n" + + "doesn't currently have any values for the Property, it will return\n" + + "an empty list. We can use the list to add values for the Property\n\n" + + "List conditions = person1.getList(conditionProperty);\n" + + "conditions.add(condition);"); + + List conditions = person1.getList(conditionProperty); + conditions.add(condition); + + commentary("A further look at the data graph in XML form shows\n" + + "the presence of the new condition Property's value ..."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("Having looked at the way SDO handles Open content\n" + + "We now turn our attention to 'non-containment' relationships.\n" + + "To do this we first create the set of people in the test that\n" + + "constitute the blood relatives of patients -- 'relatives'\n" + + "and define a new person to be Joe Johnson Snr's child.\n\n" + + "DataObject relatives = test.createDataObject(\"relatives\");\n" + + "DataObject person2 = relatives.createDataObject(\"person\");\n" + + "person2.setString(\"id\", \"2\");\n" + + "person2.setString(\"name\", \"Joe Johnson Jnr.\");\n" + + "person2.setString(\"gender\", \"male\");"); + + DataObject relatives = test.createDataObject("relatives"); + DataObject person2 = relatives.createDataObject("person"); + + person2.setString("id", "2"); + person2.setString("name", "Joe Johnson Jnr."); + person2.setString("gender", "male"); + + commentary("Another quick look at the XML rendering of the graph confirms that\n" + + "the set of relatives now includes Joe Johnson Jnr, but we haven't yet\n" + + "defined who he is related to, or how."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("The Person type has a Property 'relative'\n" + + "so we create a relative for Joe Johnson Snr.\n\n" + + "DataObject relation = person1.createDataObject(\"relative\");\n" + + "relation.set(\"target\", person2);\n" + + "relation.set(\"relationship\", \"child\");"); + + DataObject relation = person1.createDataObject("relative"); + relation.set("target", person2); + relation.set("relationship", "child"); + + commentary("Now when we look at the XML rendering of the data graph\n" + + "we can see that the action of setting the 'target' of the\n" + + "relationship to Joe Johnson Jnr didn't displace him from the\n" + + "set of 'relatives', because the 'target' Property is a\n" + + "non-containment Property. This non-containment relationship\n" + + "is reflected in the XML by a reference to the Person DataObject\n" + + "describing Joe Johnson Jnr, \"2\" ...\n" + + "If the Type system has been created from an XML schema then the\n" + + "unique ID of the target can be used in the serialization.\n" + + "If however the type system was defined dynamically, then the reference\n" + + "will be represented as an XPath from the root of the data graph."); + + System.out.println(scope.getXMLHelper().save(test, + "www.example.org/MedicalTest", "test")); + + commentary("Now that the graph is complete we can use the PrintDataGraph sample utility\n" + + "to reveal the full SDO nature of the final data graph\n\n" + + ""); + + PrintDataGraph printer = new PrintDataGraph(COMMENTARY_FOR_ADVANCED); + printer.printDataObject(test); + System.out.println(printer.getBuf()); + + commentary("But Wait! it's all wrong. Let's go back to our checkpoint where we started monitoring changes\n\n" + + "test.getChangeSummary().undoChanges();"); + + test.getChangeSummary().undoChanges(); + + printer.reset(); + printer.printDataObject(test); + System.out.println(printer.getBuf()); + + } + + /** + * @throws Exception + * @throws FileNotFoundException + */ + private void createTypesViaAPI(HelperContext scope) throws Exception { + + List typeDeclarations = new ArrayList(); + + TypeHelper typeHelper = scope.getTypeHelper(); + + Type stringType = typeHelper.getType(sdoApiUri, "String"); + Type dateType = typeHelper.getType(sdoApiUri, "Date"); + Type booleanType = typeHelper.getType(sdoApiUri, "Boolean"); + + // <complexType name="Person"> + // <sequence> + // <element name="dob" type="date"/> + // <element name="relative" maxOccurs="unbounded" type="tns:Relative"/> + // <any namespace="##other" processContents="lax" maxOccurs="unbounded"/> + // </sequence> + // <attribute name="id" type="ID"/> + // <attribute name="name" type="string"/> + // <attribute name="gender" type = "tns:Gender"/> + // </complexType> + + DataObject personTypeDesc = createTypeDescription(scope, peopleURI, + "Person"); + typeDeclarations.add(personTypeDesc); + + addPropertyDescription(personTypeDesc, stringType, "name"); + addPropertyDescription(personTypeDesc, dateType, "dob"); + addPropertyDescription(personTypeDesc, stringType, "id"); // set to unique + // identifier? + addPropertyDescription(personTypeDesc, stringType, "gender"); // restrict? + + DataObject relativeType = createTypeDescription(scope, peopleURI, + "Relative"); // forward declare the Relative type + typeDeclarations.add(relativeType); + + DataObject rp = addPropertyDescription(personTypeDesc, relativeType, + "relative"); + rp.setBoolean("many", true); + personTypeDesc.set("open", Boolean.TRUE); + + // <complexType name="Relative"> + // <attribute name="target" type="IDREF" sdoxml:propertyType="tns:Person" + // use="required"/> + // <attribute name="relationship" type="string" /> + // <attribute name="genetic" use="optional" type="boolean"/> + // </complexType> + + addPropertyDescription(relativeType, stringType, "relationship"); + addPropertyDescription(relativeType, booleanType, "genetic"); + DataObject targetPersonProp = addPropertyDescription(relativeType, + personTypeDesc, "target"); + targetPersonProp.setBoolean("containment", false); + + // <complexType name="PersonSet"> + // <sequence> + // <element name="person" type="tns:Person" maxOccurs="unbounded"/> + // </sequence> + // </complexType> + + DataObject pSet = createTypeDescription(scope, peopleURI, "PersonSet"); + typeDeclarations.add(pSet); + DataObject pSetProperty = addPropertyDescription(pSet, personTypeDesc, + "person"); + pSetProperty.setBoolean("many", true); + + // <complexType name="Condition"> + // <sequence> + // <element name="diagnosed" type="date" /> + // </sequence> + // <attribute name="name" type="tns:ConditionName" /> + // </complexType> + + DataObject condition = createTypeDescription(scope, medicalURI, "Condition"); + typeDeclarations.add(condition); + addPropertyDescription(condition, booleanType, "diagnosed"); + addPropertyDescription(condition, stringType, "name"); // constrain? + + // <complexType name="Test"> + // <sequence> + // <element name="referrals" type="people:PersonSet" /> + // <element name="patients" type="people:PersonSet" /> + // <element name="relatives" type="people:PersonSet" /> + // </sequence> + // </complexType> + + DataObject testType = createTypeDescription(scope, medicalURI, "Test"); + typeDeclarations.add(testType); + addPropertyDescription(testType, pSet, "referrals"); + addPropertyDescription(testType, pSet, "patients"); + addPropertyDescription(testType, pSet, "relatives"); + + List types = typeHelper.define(typeDeclarations); + + DataObject p = scope.getDataFactory().create("commonj.sdo", "Property"); + p.set("type", typeHelper.getType(medicalURI, "Condition")); + p.set("name", "condition"); + p.setBoolean("many", true); + p.setBoolean("containment", true); // why is this not the default? + + typeHelper.defineOpenContentProperty(medicalURI, p); + + } + + /** + * @param uri + * @param name + * @return + */ + private DataObject createTypeDescription(HelperContext scope, String uri, + String name) { + DataObject typeDesc = scope.getDataFactory().create(sdoApiUri, "Type"); + typeDesc.set("name", name); + typeDesc.set("uri", uri); + return typeDesc; + } + + private DataObject addPropertyDescription( + DataObject containerTypeDescription, Object propertyType, + String propertyName) { + DataObject property = containerTypeDescription.createDataObject("property"); + property.set("type", propertyType); + property.setString("name", propertyName); + property.setBoolean("containment", true); + return property; + } + +} diff --git a/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/PrintDataGraph.java b/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/PrintDataGraph.java index 6647f54501..7458eef76c 100644 --- a/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/PrintDataGraph.java +++ b/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/advanced/PrintDataGraph.java @@ -1,498 +1,498 @@ -/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.samples.sdo.advanced;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.tuscany.samples.sdo.SampleBase;
-import org.apache.tuscany.samples.sdo.internal.SampleInfrastructure;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.Property;
-import commonj.sdo.Sequence;
-import commonj.sdo.Type;
-import commonj.sdo.helper.HelperContext;
-import commonj.sdo.helper.XMLDocument;
-import commonj.sdo.helper.XSDHelper;
-import commonj.sdo.impl.HelperProvider;
-
-/**
- *
- * This sample program traverses data graphs and builds up a text representation of the
- * data graph. As it traverses a graph it outputs commentary to the console
- * about what it has encountered and how it intends to process what it finds. At
- * the end of each traversal the text representation of the graph is printed to
- * the console.
- * <p>
- * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html"
- * target="_top">the main overview</A> for instructions on how to run this
- * sample.
- */
-public class PrintDataGraph extends SampleBase {
-
- StringBuffer buf = null;
- HelperContext scope = HelperProvider.getDefaultContext();
-
- private int indent;
-
- private int indentIncrement = 2;
-
- public PrintDataGraph(Integer userLevel) {
- super(userLevel, SAMPLE_LEVEL_ADVANCED);
- buf = new StringBuffer();
- }
-
- public static void main(String[] args) {
- PrintDataGraph sample = new PrintDataGraph(COMMENTARY_FOR_NOVICE);
- sample.run();
- }
-
- /*
- * metadata for the sample documenting the areas of SDO that are explored
- */
- public static int [] CORE_FUNCTION = {
- SDOFacets.GENERIC_DATA_GRAPH_TRAVERSAL
- };
-
- public static int [] SIGNIFICANT_FUNCTION = {
- SDOFacets.GET_SET_PROPERTIES_BY_INSTANCE_PROPERTIES,
- SDOFacets.ISMANY_PROPERTIES,
- SDOFacets.CREATE_TYPES_USING_THE_SDO_API,
- SDOFacets.ACCESSING_VALUES_IN_A_SEQUENCE,
- SDOFacets.NON_CONTAINMENT
- };
-
- public void runSample() throws Exception {
- commentary("This sample demonstrates a common pattern of traversing a data graph\n"
- + "and printing the values of its Properties. As the sample traverses a couple of\n"
- + "graphs it provides commentary about what it has found and what actions it\n"
- + "is taking, whilst building up a text representation of the graph. It then\n"
- + "shows you the results of its labours.");
-
- HelperContext scope = createScopeForTypes();
-
- commentary(
- COMMENTARY_ALWAYS,
- "First we look at a data graph of a Purchase Order which has a fairly simple XML schema\n"
- + "and the graph's containment hierarchy has a couple of levels of depth");
-
- loadTypesFromXMLSchemaFile(scope, SampleInfrastructure.PO_XSD_RESOURCE);
-
- XMLDocument purchaseOrder = getXMLDocumentFromFile(scope,
- SampleInfrastructure.PO_XML_RESOURCE);
-
- printXMLDocument(purchaseOrder);
-
- commentary(COMMENTARY_ALWAYS,
- "And here is the resultant view of the data graph\n\n");
- System.out.println(getBuf().toString());
-
- commentary(COMMENTARY_ALWAYS,
- "Next we look at a graph representing a form letter, where the Type of the\n"
- + "root data object is 'Sequenced'");
-
- loadTypesFromXMLSchemaFile(scope, "letter.xsd");
- DataObject letter = getDataObjectFromFile(scope, "letter.xml");
-
- reset();
- print(letter);
-
- commentary(COMMENTARY_ALWAYS,
- "And here is the resultant view of the data graph\n\n");
-
- System.out.println(getBuf().toString());
-
- }
-
- public void reset() {
- indent = 0;
- buf = new StringBuffer();
- }
-
- /*
- * a convenience method allowing untyped access to the print function for
- * selected SDO artifacts
- */
- public void print(Object sdoObject) throws Exception {
-
- if (sdoObject instanceof XMLDocument) {
- printXMLDocument((XMLDocument) sdoObject);
- } else if (sdoObject instanceof DataObject) {
- printDataObject((DataObject) sdoObject);
- }
-
- }
-
- public void printXMLDocument(XMLDocument xmlDocument) {
-
- commentary(
- COMMENTARY_FOR_NOVICE,
- "We are going to traverse a data graph that has been wrapped in an instance of XMLDocument\n"
- + "Amongst other things, the XMLDocument instance provides access to the root element name\n"
- + "and the root DataObject of the data graph.\n\n"
- + "xmlDocument.getRootElementName();\n"
- + "xmlDocument.getRootObject();",
-
- "Accessing another graph via an XMLDocument instance as we saw previously ...\n"
- + "xmlDocument.getRootElementName();\n"
- + "xmlDocument.getRootObject();");
-
- buf.append("XMLDocument: ").append(xmlDocument.getRootElementName());
- lineBreak();
- incrementIndent();
- printDataObject(xmlDocument.getRootObject());
- decrementIndent();
- }
-
- public void printDataObject(DataObject dataObject) {
-
- if (dataObject.getContainer() == null) {
- commentary(
- COMMENTARY_FOR_NOVICE,
- "We begin traversing the data graph by examining the root object of the graph's containment hierarchy,\n"
- + "making a record of the values of its Properties. As we inspect the values of the Properties of this object\n"
- + "if we encounter contained DataObjects, then we will recurs through the containment hierarchy of the\n"
- + "data graph in a depth first fashion, and create a text representation of the graph that we'll print\n"
- + "out after the graph traversal has been completed.",
-
- "We are beginning to traverse another data graph from its root object, in the same way that we saw previously");
- } else {
- commentary(
- COMMENTARY_FOR_NOVICE,
- "We have arrived at a contained dataObject in the graph, and will inspect its Property values,\n"
- + "recursing deeper if necessary",
-
- "Inspecting another contained dataObject");
- }
-
- lineBreak();
- indent();
- buf.append("DataObject: ");
- Type type = dataObject.getType();
- buf.append("Type: ").append(type.getURI()).append('#').append(
- type.getName());
- lineBreak();
-
- if (dataObject.getType().isSequenced()) {
-
- commentary(
- COMMENTARY_FOR_INTERMEDIATE,
- "We've encountered a DataObject in the graph for which the Type is 'Sequenced'\n"
- + "That is to say that the order of addition of Property values to the DataObject instance\n"
- + "is important, and is preserved by the DataObject\n\n"
- + "dataObject.getType().isSequenced();",
-
- "We've encountered another sequenced DataObject instance, and so will traverse the Property\n"
- + "values in the order preerved by the instance, as we saw before\n\n"
- + "dataObject.getType().isSequenced();");
-
- commentary(
- "There's a subtlety here which we must deal with if this sample code is to\n" +
- "handle both Type systems that derive from XML schema, and those that come from elsewhere,\n" +
- "e.g. using the SDO API. If a Sequenced DataObject has a Type that comes from XML schema\n" +
- "then its Properties that derive from XML attributes are not ordered, whereas those that\n" +
- "derive from XML elements are ordered. The SDO specification doesn't say whether\n" +
- "the attribute related Properties should appear at the start of a Sequence or not.\n" +
- "Currently in Tuscany we leave them out of the Sequence; other SDO implementations may\n" +
- "include the XML attributes in the Sequence. This sample code is written to deal with\n" +
- "either approach\n." +
- "We use the XSDHelper.isAttribute(Property) and isElement(Property) methods to distinguish\n" +
- "between the two kinds of Property",
-
- "Examining the xml attributes and elements of a Sequenced DataObject again."
- );
-
- XSDHelper xsdHelper = getScope().getXSDHelper();
- incrementIndent();
- for(Iterator it=dataObject.getInstanceProperties().iterator(); it.hasNext();) {
- Property property = (Property)it.next();
- if (xsdHelper.isAttribute(property)) {
- indent();
- buf.append("Property (XML Attribute): ").append(property.getName()).append(" - ").append(dataObject.get(property));
- lineBreak();
- }
-
- }
- decrementIndent();
- Sequence seq = dataObject.getSequence();
-
- commentary(
- "The Property/Value pairs of a Sequence can be accessed via the getProperty(int) and getValue(int)\n"
- + "accessor methods of the Sequence interface. The size() method of the Sequence tells us how many there are.\n"
- + "If the getProperty(int) method returns null, then the value is text. These text values may be encountered\n"
- + "when the DataObject's type is 'mixed' (dataObject.getType().isMixed() == true). A typical example of this\n"
- + "is when the data graph represents a form letter.",
-
- "Inspecting the Property/Value pairs of another Sequence");
-
- incrementIndent();
- indent();
- buf.append("Sequence: {\n");
-
- incrementIndent();
- for (int i = 0; i < seq.size(); i++) {
- Property p = seq.getProperty(i);
- if (p == null) {
- indent();
- buf.append("text: ").append(seq.getValue(i));
- lineBreak();
- } else if(!xsdHelper.isAttribute(p)){
- printPropertyValuePair(p, seq.getValue(i));
- }
- }
- decrementIndent();
-
- indent();
- buf.append("}\n");
- decrementIndent();
-
- } else {
- incrementIndent();
-
- commentary(
- COMMENTARY_FOR_INTERMEDIATE,
- "We access the Property values of this DataObject by first getting the list of 'Instance Properties'\n"
- + "from the DataObject. For many DataObjects, this will be the same set of Properties that are defined\n"
- + "by the DataObject's Type. However, if the DataObject's type is 'Open' then an instance of that Type\n"
- + "may contain more Properties than the type itself. The list of Instance Properties will always include\n"
- + "the Properties defined in the Type, but will also include any Properties that the instance has values for\n"
- + "by virtue of it's type being 'Open'\n\n"
- + "for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) {\n"
- + " Property p = (Property) dataObject.getInstanceProperties().get(i);",
-
- "Traversing the instance Properties of this DataObject\n"
- + "for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) {\n"
- + " Property p = (Property) dataObject.getInstanceProperties().get(i);"
-
- );
-
- for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) {
- Property p = (Property) dataObject.getInstanceProperties().get(i);
- indent();
- printValueOfProperty(dataObject, p);
- }
-
- decrementIndent();
- }
-
- }
-
-
-
-
-
- private void printPropertyValuePair(Property p, Object value) {
-
- indent();
- buf.append("Property: ").append(p.getName()).append(": ");
- if(p.getType().isDataType()) {
- printSimpleValue(value);
- lineBreak();
- } else {
- if(p.isContainment()) {
- incrementIndent();
- printDataObject((DataObject)value);
- decrementIndent();
- } else {
- printReferencedDataObject((DataObject)value);
- }
- }
-
-
- }
-
- private void printValueOfProperty(DataObject dataObject, Property p) {
-
- commentary(
- COMMENTARY_FOR_INTERMEDIATE,
- "We are about to inspect the value of a Property, but we must\n"
- + "consider the nature of that Property in order to deal with it appropriately.\n"
- + "Firstly we see if the Property value has been set (dataObject.isSet(property))\n"
- + "Then we see if the Property is simple valued (property.isDataType() == true)\n"
- + "--if not then we know it's a DataObject and we must recurs deeper into the graph's\n"
- + "containment hierarchy\n"
- + "Whether or not the property value is a DataObject, is may be single or multi-valued\n"
- + "so we must either use one of the DataObject's get*(Property) accessors for single\n"
- + "valued Properties or the getList() method for multi-valued properties.\n"
- + "Another thing we must deal with when the Property is a DataObject, is whether or not the\n"
- + "Property is a 'containment' Property. If it isn't, then here we simply record the fact that\n"
- + "we have encountered this non-containment relationship, and move on to the next Property",
-
- "Inspecting another property to determine how to access its value, as we saw before");
-
- // TODO deal with nullable
-
- buf.append("Property ").append(p.getName()).append(": ").append(" - ");
-
- if (dataObject.isSet(p)) {
- if (p.getType().isDataType()) {
- if (p.isMany()) {
- printSimpleValues(dataObject.getList(p));
- } else {
- printSimpleValue(dataObject.get(p));
- }
- } else {
- if (p.isContainment()) {
- incrementIndent();
- if (p.isMany()) {
- printDataObjects(dataObject.getList(p));
- } else {
- printDataObject(dataObject.getDataObject(p));
- }
- decrementIndent();
- } else {
- if (p.isMany()) {
- printReferencedDataObjects(dataObject.getList(p));
- } else {
- printReferencedDataObject(dataObject.getDataObject(p));
- }
- }
- }
- } else {
- buf.append(" is not set");
- }
-
- lineBreak();
-
- }
-
- private void printReferencedDataObject(DataObject dataObject) {
-
- commentary(
- COMMENTARY_FOR_INTERMEDIATE,
- "We have encounted a non-containment reference to a DataObject, and so\n"
- + "we know that this DataObject will be fully inspected when encountered by the\n"
- + "traversal of the data graph's containment hierarchy.\n"
- + "We therefore record the fact that this association has been encountered by\n"
- + "establishing the path from the root object of the data graph to the referenced\n"
- + "DataObject",
-
- "Recording the fact that we have encountered another non-containment reference");
-
- List path = new ArrayList();
- DataObject current = dataObject;
- while (current != null) {
- Property containmentProperty = current.getContainmentProperty();
- if(containmentProperty != null) {
- if(containmentProperty.isMany()) {
- List pValues = current.getContainer().getList(containmentProperty);
- int index = pValues.indexOf(current)+1;
- path.add("["+index+"]");
- }
- path.add("/"+current.getContainmentProperty().getName());
- }
- current = current.getContainer();
- }
- buf.append("reference to: ");
- for (ListIterator i = path.listIterator(path.size()); i.hasPrevious();) {
- buf.append(i.previous());
- }
- }
-
- private void printReferencedDataObjects(List list) {
-
- commentary(
- COMMENTARY_FOR_NOVICE,
- "Traversing a list of DataObjects which represent the values of a multi-valued non-containment Property");
-
- indent();
- buf.append('[');
- for (Iterator i = list.iterator(); i.hasNext();) {
- printReferencedDataObject((DataObject) i.next());
- }
- indent();
- buf.append(']');
- }
-
- private void printDataObjects(List list) {
-
- commentary(
- COMMENTARY_FOR_NOVICE,
- "Traversing a list of DataObjects which represent the values of a multi-valued containment Property");
-
-
- lineBreak();
- indent();
- buf.append("[");
- incrementIndent();
- for (Iterator i = list.iterator(); i.hasNext();) {
- printDataObject((DataObject) i.next());
- }
- decrementIndent();
- indent();
- buf.append(']');
- }
-
- private void printSimpleValue(Object object) {
- buf.append(object);
- }
-
- private void printSimpleValues(List values) {
- buf.append('[');
- for (Iterator i = values.iterator(); i.hasNext();) {
- printSimpleValue(i.next());
- if (i.hasNext()) {
- buf.append(',');
- }
- }
- buf.append(']');
-
- }
-
- private void decrementIndent() {
- indent -= indentIncrement;
-
- }
-
- private void incrementIndent() {
- indent += indentIncrement;
-
- }
-
- private void indent() {
- for (int i = 0; i < indent; i++) {
- buf.append(' ');
- }
- }
-
- private void lineBreak() {
- buf.append('\n');
- }
-
- public StringBuffer getBuf() {
- return buf;
- }
-
- public void setBuf(StringBuffer b) {
- buf = b;
- }
-
- public HelperContext getScope() {
- return scope;
- }
-
- public void setScope(HelperContext scope) {
- this.scope = scope;
- }
-
-}
+/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.samples.sdo.advanced; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import org.apache.tuscany.samples.sdo.SampleBase; +import org.apache.tuscany.samples.sdo.internal.SampleInfrastructure; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XSDHelper; +import commonj.sdo.impl.HelperProvider; + +/** + * + * This sample program traverses data graphs and builds up a text representation of the + * data graph. As it traverses a graph it outputs commentary to the console + * about what it has encountered and how it intends to process what it finds. At + * the end of each traversal the text representation of the graph is printed to + * the console. + * <p> + * <h3>Running this Sample</h3> See <A HREF="../../../../../../index.html" + * target="_top">the main overview</A> for instructions on how to run this + * sample. + */ +public class PrintDataGraph extends SampleBase { + + StringBuffer buf = null; + HelperContext scope = HelperProvider.getDefaultContext(); + + private int indent; + + private int indentIncrement = 2; + + public PrintDataGraph(Integer userLevel) { + super(userLevel, SAMPLE_LEVEL_ADVANCED); + buf = new StringBuffer(); + } + + public static void main(String[] args) { + PrintDataGraph sample = new PrintDataGraph(COMMENTARY_FOR_NOVICE); + sample.run(); + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.GENERIC_DATA_GRAPH_TRAVERSAL + }; + + public static int [] SIGNIFICANT_FUNCTION = { + SDOFacets.GET_SET_PROPERTIES_BY_INSTANCE_PROPERTIES, + SDOFacets.ISMANY_PROPERTIES, + SDOFacets.CREATE_TYPES_USING_THE_SDO_API, + SDOFacets.ACCESSING_VALUES_IN_A_SEQUENCE, + SDOFacets.NON_CONTAINMENT + }; + + public void runSample() throws Exception { + commentary("This sample demonstrates a common pattern of traversing a data graph\n" + + "and printing the values of its Properties. As the sample traverses a couple of\n" + + "graphs it provides commentary about what it has found and what actions it\n" + + "is taking, whilst building up a text representation of the graph. It then\n" + + "shows you the results of its labours."); + + HelperContext scope = createScopeForTypes(); + + commentary( + COMMENTARY_ALWAYS, + "First we look at a data graph of a Purchase Order which has a fairly simple XML schema\n" + + "and the graph's containment hierarchy has a couple of levels of depth"); + + loadTypesFromXMLSchemaFile(scope, SampleInfrastructure.PO_XSD_RESOURCE); + + XMLDocument purchaseOrder = getXMLDocumentFromFile(scope, + SampleInfrastructure.PO_XML_RESOURCE); + + printXMLDocument(purchaseOrder); + + commentary(COMMENTARY_ALWAYS, + "And here is the resultant view of the data graph\n\n"); + System.out.println(getBuf().toString()); + + commentary(COMMENTARY_ALWAYS, + "Next we look at a graph representing a form letter, where the Type of the\n" + + "root data object is 'Sequenced'"); + + loadTypesFromXMLSchemaFile(scope, "letter.xsd"); + DataObject letter = getDataObjectFromFile(scope, "letter.xml"); + + reset(); + print(letter); + + commentary(COMMENTARY_ALWAYS, + "And here is the resultant view of the data graph\n\n"); + + System.out.println(getBuf().toString()); + + } + + public void reset() { + indent = 0; + buf = new StringBuffer(); + } + + /* + * a convenience method allowing untyped access to the print function for + * selected SDO artifacts + */ + public void print(Object sdoObject) throws Exception { + + if (sdoObject instanceof XMLDocument) { + printXMLDocument((XMLDocument) sdoObject); + } else if (sdoObject instanceof DataObject) { + printDataObject((DataObject) sdoObject); + } + + } + + public void printXMLDocument(XMLDocument xmlDocument) { + + commentary( + COMMENTARY_FOR_NOVICE, + "We are going to traverse a data graph that has been wrapped in an instance of XMLDocument\n" + + "Amongst other things, the XMLDocument instance provides access to the root element name\n" + + "and the root DataObject of the data graph.\n\n" + + "xmlDocument.getRootElementName();\n" + + "xmlDocument.getRootObject();", + + "Accessing another graph via an XMLDocument instance as we saw previously ...\n" + + "xmlDocument.getRootElementName();\n" + + "xmlDocument.getRootObject();"); + + buf.append("XMLDocument: ").append(xmlDocument.getRootElementName()); + lineBreak(); + incrementIndent(); + printDataObject(xmlDocument.getRootObject()); + decrementIndent(); + } + + public void printDataObject(DataObject dataObject) { + + if (dataObject.getContainer() == null) { + commentary( + COMMENTARY_FOR_NOVICE, + "We begin traversing the data graph by examining the root object of the graph's containment hierarchy,\n" + + "making a record of the values of its Properties. As we inspect the values of the Properties of this object\n" + + "if we encounter contained DataObjects, then we will recurs through the containment hierarchy of the\n" + + "data graph in a depth first fashion, and create a text representation of the graph that we'll print\n" + + "out after the graph traversal has been completed.", + + "We are beginning to traverse another data graph from its root object, in the same way that we saw previously"); + } else { + commentary( + COMMENTARY_FOR_NOVICE, + "We have arrived at a contained dataObject in the graph, and will inspect its Property values,\n" + + "recursing deeper if necessary", + + "Inspecting another contained dataObject"); + } + + lineBreak(); + indent(); + buf.append("DataObject: "); + Type type = dataObject.getType(); + buf.append("Type: ").append(type.getURI()).append('#').append( + type.getName()); + lineBreak(); + + if (dataObject.getType().isSequenced()) { + + commentary( + COMMENTARY_FOR_INTERMEDIATE, + "We've encountered a DataObject in the graph for which the Type is 'Sequenced'\n" + + "That is to say that the order of addition of Property values to the DataObject instance\n" + + "is important, and is preserved by the DataObject\n\n" + + "dataObject.getType().isSequenced();", + + "We've encountered another sequenced DataObject instance, and so will traverse the Property\n" + + "values in the order preerved by the instance, as we saw before\n\n" + + "dataObject.getType().isSequenced();"); + + commentary( + "There's a subtlety here which we must deal with if this sample code is to\n" + + "handle both Type systems that derive from XML schema, and those that come from elsewhere,\n" + + "e.g. using the SDO API. If a Sequenced DataObject has a Type that comes from XML schema\n" + + "then its Properties that derive from XML attributes are not ordered, whereas those that\n" + + "derive from XML elements are ordered. The SDO specification doesn't say whether\n" + + "the attribute related Properties should appear at the start of a Sequence or not.\n" + + "Currently in Tuscany we leave them out of the Sequence; other SDO implementations may\n" + + "include the XML attributes in the Sequence. This sample code is written to deal with\n" + + "either approach\n." + + "We use the XSDHelper.isAttribute(Property) and isElement(Property) methods to distinguish\n" + + "between the two kinds of Property", + + "Examining the xml attributes and elements of a Sequenced DataObject again." + ); + + XSDHelper xsdHelper = getScope().getXSDHelper(); + incrementIndent(); + for(Iterator it=dataObject.getInstanceProperties().iterator(); it.hasNext();) { + Property property = (Property)it.next(); + if (xsdHelper.isAttribute(property)) { + indent(); + buf.append("Property (XML Attribute): ").append(property.getName()).append(" - ").append(dataObject.get(property)); + lineBreak(); + } + + } + decrementIndent(); + Sequence seq = dataObject.getSequence(); + + commentary( + "The Property/Value pairs of a Sequence can be accessed via the getProperty(int) and getValue(int)\n" + + "accessor methods of the Sequence interface. The size() method of the Sequence tells us how many there are.\n" + + "If the getProperty(int) method returns null, then the value is text. These text values may be encountered\n" + + "when the DataObject's type is 'mixed' (dataObject.getType().isMixed() == true). A typical example of this\n" + + "is when the data graph represents a form letter.", + + "Inspecting the Property/Value pairs of another Sequence"); + + incrementIndent(); + indent(); + buf.append("Sequence: {\n"); + + incrementIndent(); + for (int i = 0; i < seq.size(); i++) { + Property p = seq.getProperty(i); + if (p == null) { + indent(); + buf.append("text: ").append(seq.getValue(i)); + lineBreak(); + } else if(!xsdHelper.isAttribute(p)){ + printPropertyValuePair(p, seq.getValue(i)); + } + } + decrementIndent(); + + indent(); + buf.append("}\n"); + decrementIndent(); + + } else { + incrementIndent(); + + commentary( + COMMENTARY_FOR_INTERMEDIATE, + "We access the Property values of this DataObject by first getting the list of 'Instance Properties'\n" + + "from the DataObject. For many DataObjects, this will be the same set of Properties that are defined\n" + + "by the DataObject's Type. However, if the DataObject's type is 'Open' then an instance of that Type\n" + + "may contain more Properties than the type itself. The list of Instance Properties will always include\n" + + "the Properties defined in the Type, but will also include any Properties that the instance has values for\n" + + "by virtue of it's type being 'Open'\n\n" + + "for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) {\n" + + " Property p = (Property) dataObject.getInstanceProperties().get(i);", + + "Traversing the instance Properties of this DataObject\n" + + "for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) {\n" + + " Property p = (Property) dataObject.getInstanceProperties().get(i);" + + ); + + for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) { + Property p = (Property) dataObject.getInstanceProperties().get(i); + indent(); + printValueOfProperty(dataObject, p); + } + + decrementIndent(); + } + + } + + + + + + private void printPropertyValuePair(Property p, Object value) { + + indent(); + buf.append("Property: ").append(p.getName()).append(": "); + if(p.getType().isDataType()) { + printSimpleValue(value); + lineBreak(); + } else { + if(p.isContainment()) { + incrementIndent(); + printDataObject((DataObject)value); + decrementIndent(); + } else { + printReferencedDataObject((DataObject)value); + } + } + + + } + + private void printValueOfProperty(DataObject dataObject, Property p) { + + commentary( + COMMENTARY_FOR_INTERMEDIATE, + "We are about to inspect the value of a Property, but we must\n" + + "consider the nature of that Property in order to deal with it appropriately.\n" + + "Firstly we see if the Property value has been set (dataObject.isSet(property))\n" + + "Then we see if the Property is simple valued (property.isDataType() == true)\n" + + "--if not then we know it's a DataObject and we must recurs deeper into the graph's\n" + + "containment hierarchy\n" + + "Whether or not the property value is a DataObject, is may be single or multi-valued\n" + + "so we must either use one of the DataObject's get*(Property) accessors for single\n" + + "valued Properties or the getList() method for multi-valued properties.\n" + + "Another thing we must deal with when the Property is a DataObject, is whether or not the\n" + + "Property is a 'containment' Property. If it isn't, then here we simply record the fact that\n" + + "we have encountered this non-containment relationship, and move on to the next Property", + + "Inspecting another property to determine how to access its value, as we saw before"); + + // TODO deal with nullable + + buf.append("Property ").append(p.getName()).append(": ").append(" - "); + + if (dataObject.isSet(p)) { + if (p.getType().isDataType()) { + if (p.isMany()) { + printSimpleValues(dataObject.getList(p)); + } else { + printSimpleValue(dataObject.get(p)); + } + } else { + if (p.isContainment()) { + incrementIndent(); + if (p.isMany()) { + printDataObjects(dataObject.getList(p)); + } else { + printDataObject(dataObject.getDataObject(p)); + } + decrementIndent(); + } else { + if (p.isMany()) { + printReferencedDataObjects(dataObject.getList(p)); + } else { + printReferencedDataObject(dataObject.getDataObject(p)); + } + } + } + } else { + buf.append(" is not set"); + } + + lineBreak(); + + } + + private void printReferencedDataObject(DataObject dataObject) { + + commentary( + COMMENTARY_FOR_INTERMEDIATE, + "We have encounted a non-containment reference to a DataObject, and so\n" + + "we know that this DataObject will be fully inspected when encountered by the\n" + + "traversal of the data graph's containment hierarchy.\n" + + "We therefore record the fact that this association has been encountered by\n" + + "establishing the path from the root object of the data graph to the referenced\n" + + "DataObject", + + "Recording the fact that we have encountered another non-containment reference"); + + List path = new ArrayList(); + DataObject current = dataObject; + while (current != null) { + Property containmentProperty = current.getContainmentProperty(); + if(containmentProperty != null) { + if(containmentProperty.isMany()) { + List pValues = current.getContainer().getList(containmentProperty); + int index = pValues.indexOf(current)+1; + path.add("["+index+"]"); + } + path.add("/"+current.getContainmentProperty().getName()); + } + current = current.getContainer(); + } + buf.append("reference to: "); + for (ListIterator i = path.listIterator(path.size()); i.hasPrevious();) { + buf.append(i.previous()); + } + } + + private void printReferencedDataObjects(List list) { + + commentary( + COMMENTARY_FOR_NOVICE, + "Traversing a list of DataObjects which represent the values of a multi-valued non-containment Property"); + + indent(); + buf.append('['); + for (Iterator i = list.iterator(); i.hasNext();) { + printReferencedDataObject((DataObject) i.next()); + } + indent(); + buf.append(']'); + } + + private void printDataObjects(List list) { + + commentary( + COMMENTARY_FOR_NOVICE, + "Traversing a list of DataObjects which represent the values of a multi-valued containment Property"); + + + lineBreak(); + indent(); + buf.append("["); + incrementIndent(); + for (Iterator i = list.iterator(); i.hasNext();) { + printDataObject((DataObject) i.next()); + } + decrementIndent(); + indent(); + buf.append(']'); + } + + private void printSimpleValue(Object object) { + buf.append(object); + } + + private void printSimpleValues(List values) { + buf.append('['); + for (Iterator i = values.iterator(); i.hasNext();) { + printSimpleValue(i.next()); + if (i.hasNext()) { + buf.append(','); + } + } + buf.append(']'); + + } + + private void decrementIndent() { + indent -= indentIncrement; + + } + + private void incrementIndent() { + indent += indentIncrement; + + } + + private void indent() { + for (int i = 0; i < indent; i++) { + buf.append(' '); + } + } + + private void lineBreak() { + buf.append('\n'); + } + + public StringBuffer getBuf() { + return buf; + } + + public void setBuf(StringBuffer b) { + buf = b; + } + + public HelperContext getScope() { + return scope; + } + + public void setScope(HelperContext scope) { + this.scope = scope; + } + +} diff --git a/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/internal/DocumentSamples.java b/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/internal/DocumentSamples.java index 8d0cba0663..af20cb663a 100644 --- a/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/internal/DocumentSamples.java +++ b/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/internal/DocumentSamples.java @@ -1,218 +1,218 @@ -/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.samples.sdo.internal;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.tuscany.samples.sdo.internal.SampleInfrastructure.SDOFacets;
-
-
-/**
- * Class to generate html documentation for the SDO Samples.
- * The program introspects the sample programs listed in the
- * {@link SampleInfrastructure#sampleClasses sample classes}
- * static constant, for the values of the static CORE_FUNCTION
- * and SIGNIFICANT_FUNCTION variables.
- * <P>
- * It builds indexes from
- * sample to function and from function to sample and creates
- * html output that displays these indexes.
- */
-public class DocumentSamples {
-
- private Map classToCoreFunction = new HashMap();
- private Map coreFunctionToClass = new HashMap();
- private Map classToSignificantFunction = new HashMap();
- private Map significantFunctionToClass = new HashMap();
-
- public static void main(String[] args) throws SecurityException,
- NoSuchMethodException, IllegalArgumentException, InstantiationException,
- IllegalAccessException, InvocationTargetException, IOException {
-
- DocumentSamples ds = new DocumentSamples();
- ds.run();
-
- }
-
- private static String HTML_HEADER =
- "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" +
- "<html>\n" +
- "<!-- Note: This file is GENERATED from the samples using the\n" +
- "Document Samples utility. Hand edits will be lost when regenerated! --> \n"+
- "<!-- \n"+
- "* \n"+
- "* Licensed to the Apache Software Foundation (ASF) under one \n"+
- "* or more contributor license agreements. See the NOTICE file\n"+
- "* distributed with this work for additional information \n"+
- "* regarding copyright ownership. The ASF licenses this file \n"+
- "* to you under the Apache License, Version 2.0 (the \n"+
- "* \"License\"); you may not use this file except in compliance \n"+
- "* with the License. You may obtain a copy of the License at \n"+
- "* \n"+
- "* http://www.apache.org/licenses/LICENSE-2.0 \n"+
- "* \n"+
- "* Unless required by applicable law or agreed to in writing, \n"+
- "* software distributed under the License is distributed on an \n"+
- "* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY \n"+
- "* KIND, either express or implied. See the License for the \n"+
- "* specific language governing permissions and limitations \n"+
- "* under the License. \n"+
- "--> \n"+
- "<head><title>SDO Samples</title></head><body>\n" +
- " <h1>SDO Samples</h1>\n" +
- "<P>\n" +
- "The samples provided in the Tuscany SDO distribution cover many areas of\n" +
- "the SDO API. Here we provide two indexes into the samples. The first lists\n" +
- "each sample in sequence and details the central theme(s) of the sample.\n" +
- "It also mentions if the sample significantly demonstrates other areas in passing.\n" +
- "The second index lists all the themes that are covered by these samples, and\n" +
- "indicates which of the samples has that subject area as a central theme or as\n" +
- "demonstrates the subject area significant as an incidental part of the sample.";
-
- private static String CLASSES_HEADING =
- "<H2>Index by Sample Program Name</H2>\n";
-
- private static String FUNCTION_HEADING =
- "<H2>Index by function</H2>\n";
-
- private static String HTML_FOOTER =
- "</body>\n</html>";
-
-
- private void run() throws IllegalAccessException {
- /*
- * gather the data
- */
- for (int i = 0; i < SampleInfrastructure.sampleClasses.length; i++) {
- Class c = SampleInfrastructure.sampleClasses[i];
- classToCoreFunction.put(c, new HashSet());
- try {
- Field coreFunction = c.getField("CORE_FUNCTION");
- recordFunction(c, coreFunction, coreFunctionToClass, classToCoreFunction);
- } catch (NoSuchFieldException e) {
- // no problem
- }
- try {
- Field sigFunction = c.getField("SIGNIFICANT_FUNCTION");
- recordFunction(c, sigFunction, significantFunctionToClass, classToSignificantFunction);
- } catch (NoSuchFieldException e) {
- // no problem
- }
- }
-
- /*
- * create the documentation
- */
- StringBuffer doc = new StringBuffer();
- doc.append(HTML_HEADER);
-
- doc.append(CLASSES_HEADING);
- Class [] classes = SampleInfrastructure.sampleClasses;
- for(int i=0; i < classes.length;i++) {
- doc.append("<h3>Sample Program " + getSimpleName(classes[i]) + "</h3>\n");
- doc.append("<b>Core function:</b><br/>\n");
- int [] functions = (int[])classToCoreFunction.get(classes[i]);
- for(int j=0;j<functions.length;j++) {
- doc.append("<a href=\"#facet")
- .append(functions[j])
- .append("\">")
- .append(SDOFacets.subject_areas[functions[j]])
- .append("</a><br/>\n"); }
- doc.append("<br/>");
- if(classToSignificantFunction.get(classes[i])!= null) {
- doc.append("<b>Also demonstrates:</b><br/>\n");
- functions = (int[])classToSignificantFunction.get(classes[i]);
- for(int j=0;j<functions.length;j++) {
- doc.append("<a href=\"#facet")
- .append(functions[j])
- .append("\">")
- .append(SDOFacets.subject_areas[functions[j]])
- .append("</a><br/>\n");
- }
- }
- }
-
- doc.append(FUNCTION_HEADING);
-
- String [] facets = SDOFacets.subject_areas;
- for(int f = 0; f<facets.length; f++) {
- Integer fobj = new Integer(f);
- doc.append("<a name=\"facet")
- .append(f)
- .append("\"/>\n<h3>")
- .append(SDOFacets.subject_areas[f])
- .append("</h3>\n");
- if(coreFunctionToClass.keySet().contains(fobj)) {
- doc.append("<b>Samples which demonstrate this as their core function</b><br/>\n");
- Set classesWithFunction = (Set)coreFunctionToClass.get(fobj);
- for(Iterator cwf = classesWithFunction.iterator(); cwf.hasNext();) {
- Class c = (Class)cwf.next();
- doc.append(getSimpleName(c)).append("<br/>\n");
- }
- }
- if(significantFunctionToClass.keySet().contains(fobj)) {
- doc.append("<b>Samples which demonstrate this in addition to their core function</b><br/>\n");
- Set classesWithFunction = (Set)significantFunctionToClass.get(fobj);
- for(Iterator cwf = classesWithFunction.iterator(); cwf.hasNext();) {
- Class c = (Class)cwf.next();
- doc.append(getSimpleName(c)).append("<br/>\n");
- }
- }
-
- }
-
- doc.append(HTML_FOOTER);
- System.out.println(doc);
- }
-
- private int[] recordFunction(Class c, Field functionIndices, Map ftoc, Map ctof)
- throws IllegalAccessException {
- int[] functions = (int[]) functionIndices.get(c);
- for (int j = 0; j < functions.length; j++) {
- addClassesToFunction(ftoc, functions[j], c);
- }
- ctof.put(c, functions);
- return functions;
- }
-
- private void addClassesToFunction(Map functionToClass, int i, Class c) {
- Integer iobj = new Integer(i);
- if (!functionToClass.containsKey(iobj)) {
- functionToClass.put(iobj, new HashSet());
- }
- ((Set) (functionToClass.get(iobj))).add(c);
- }
-
- private String getSimpleName(Class c) {
- String result = c.getName();
- int lastDot = result.lastIndexOf('.');
- if(lastDot != -1) {
- result = result.substring(lastDot+1);
- }
- return result;
- }
-}
+/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.samples.sdo.internal; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.samples.sdo.internal.SampleInfrastructure.SDOFacets; + + +/** + * Class to generate html documentation for the SDO Samples. + * The program introspects the sample programs listed in the + * {@link SampleInfrastructure#sampleClasses sample classes} + * static constant, for the values of the static CORE_FUNCTION + * and SIGNIFICANT_FUNCTION variables. + * <P> + * It builds indexes from + * sample to function and from function to sample and creates + * html output that displays these indexes. + */ +public class DocumentSamples { + + private Map classToCoreFunction = new HashMap(); + private Map coreFunctionToClass = new HashMap(); + private Map classToSignificantFunction = new HashMap(); + private Map significantFunctionToClass = new HashMap(); + + public static void main(String[] args) throws SecurityException, + NoSuchMethodException, IllegalArgumentException, InstantiationException, + IllegalAccessException, InvocationTargetException, IOException { + + DocumentSamples ds = new DocumentSamples(); + ds.run(); + + } + + private static String HTML_HEADER = + "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" + + "<html>\n" + + "<!-- Note: This file is GENERATED from the samples using the\n" + + "Document Samples utility. Hand edits will be lost when regenerated! --> \n"+ + "<!-- \n"+ + "* \n"+ + "* Licensed to the Apache Software Foundation (ASF) under one \n"+ + "* or more contributor license agreements. See the NOTICE file\n"+ + "* distributed with this work for additional information \n"+ + "* regarding copyright ownership. The ASF licenses this file \n"+ + "* to you under the Apache License, Version 2.0 (the \n"+ + "* \"License\"); you may not use this file except in compliance \n"+ + "* with the License. You may obtain a copy of the License at \n"+ + "* \n"+ + "* http://www.apache.org/licenses/LICENSE-2.0 \n"+ + "* \n"+ + "* Unless required by applicable law or agreed to in writing, \n"+ + "* software distributed under the License is distributed on an \n"+ + "* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY \n"+ + "* KIND, either express or implied. See the License for the \n"+ + "* specific language governing permissions and limitations \n"+ + "* under the License. \n"+ + "--> \n"+ + "<head><title>SDO Samples</title></head><body>\n" + + " <h1>SDO Samples</h1>\n" + + "<P>\n" + + "The samples provided in the Tuscany SDO distribution cover many areas of\n" + + "the SDO API. Here we provide two indexes into the samples. The first lists\n" + + "each sample in sequence and details the central theme(s) of the sample.\n" + + "It also mentions if the sample significantly demonstrates other areas in passing.\n" + + "The second index lists all the themes that are covered by these samples, and\n" + + "indicates which of the samples has that subject area as a central theme or as\n" + + "demonstrates the subject area significant as an incidental part of the sample."; + + private static String CLASSES_HEADING = + "<H2>Index by Sample Program Name</H2>\n"; + + private static String FUNCTION_HEADING = + "<H2>Index by function</H2>\n"; + + private static String HTML_FOOTER = + "</body>\n</html>"; + + + private void run() throws IllegalAccessException { + /* + * gather the data + */ + for (int i = 0; i < SampleInfrastructure.sampleClasses.length; i++) { + Class c = SampleInfrastructure.sampleClasses[i]; + classToCoreFunction.put(c, new HashSet()); + try { + Field coreFunction = c.getField("CORE_FUNCTION"); + recordFunction(c, coreFunction, coreFunctionToClass, classToCoreFunction); + } catch (NoSuchFieldException e) { + // no problem + } + try { + Field sigFunction = c.getField("SIGNIFICANT_FUNCTION"); + recordFunction(c, sigFunction, significantFunctionToClass, classToSignificantFunction); + } catch (NoSuchFieldException e) { + // no problem + } + } + + /* + * create the documentation + */ + StringBuffer doc = new StringBuffer(); + doc.append(HTML_HEADER); + + doc.append(CLASSES_HEADING); + Class [] classes = SampleInfrastructure.sampleClasses; + for(int i=0; i < classes.length;i++) { + doc.append("<h3>Sample Program " + getSimpleName(classes[i]) + "</h3>\n"); + doc.append("<b>Core function:</b><br/>\n"); + int [] functions = (int[])classToCoreFunction.get(classes[i]); + for(int j=0;j<functions.length;j++) { + doc.append("<a href=\"#facet") + .append(functions[j]) + .append("\">") + .append(SDOFacets.subject_areas[functions[j]]) + .append("</a><br/>\n"); } + doc.append("<br/>"); + if(classToSignificantFunction.get(classes[i])!= null) { + doc.append("<b>Also demonstrates:</b><br/>\n"); + functions = (int[])classToSignificantFunction.get(classes[i]); + for(int j=0;j<functions.length;j++) { + doc.append("<a href=\"#facet") + .append(functions[j]) + .append("\">") + .append(SDOFacets.subject_areas[functions[j]]) + .append("</a><br/>\n"); + } + } + } + + doc.append(FUNCTION_HEADING); + + String [] facets = SDOFacets.subject_areas; + for(int f = 0; f<facets.length; f++) { + Integer fobj = new Integer(f); + doc.append("<a name=\"facet") + .append(f) + .append("\"/>\n<h3>") + .append(SDOFacets.subject_areas[f]) + .append("</h3>\n"); + if(coreFunctionToClass.keySet().contains(fobj)) { + doc.append("<b>Samples which demonstrate this as their core function</b><br/>\n"); + Set classesWithFunction = (Set)coreFunctionToClass.get(fobj); + for(Iterator cwf = classesWithFunction.iterator(); cwf.hasNext();) { + Class c = (Class)cwf.next(); + doc.append(getSimpleName(c)).append("<br/>\n"); + } + } + if(significantFunctionToClass.keySet().contains(fobj)) { + doc.append("<b>Samples which demonstrate this in addition to their core function</b><br/>\n"); + Set classesWithFunction = (Set)significantFunctionToClass.get(fobj); + for(Iterator cwf = classesWithFunction.iterator(); cwf.hasNext();) { + Class c = (Class)cwf.next(); + doc.append(getSimpleName(c)).append("<br/>\n"); + } + } + + } + + doc.append(HTML_FOOTER); + System.out.println(doc); + } + + private int[] recordFunction(Class c, Field functionIndices, Map ftoc, Map ctof) + throws IllegalAccessException { + int[] functions = (int[]) functionIndices.get(c); + for (int j = 0; j < functions.length; j++) { + addClassesToFunction(ftoc, functions[j], c); + } + ctof.put(c, functions); + return functions; + } + + private void addClassesToFunction(Map functionToClass, int i, Class c) { + Integer iobj = new Integer(i); + if (!functionToClass.containsKey(iobj)) { + functionToClass.put(iobj, new HashSet()); + } + ((Set) (functionToClass.get(iobj))).add(c); + } + + private String getSimpleName(Class c) { + String result = c.getName(); + int lastDot = result.lastIndexOf('.'); + if(lastDot != -1) { + result = result.substring(lastDot+1); + } + return result; + } +} diff --git a/java/sdo/sample/src/main/resources/META-INF/LICENSE.txt b/java/sdo/sample/src/main/resources/META-INF/LICENSE.txt index e55ca67ba9..9a90d375bc 100644 --- a/java/sdo/sample/src/main/resources/META-INF/LICENSE.txt +++ b/java/sdo/sample/src/main/resources/META-INF/LICENSE.txt @@ -1,207 +1,207 @@ -
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- 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.
-
-
-
-
-
+ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + + + + diff --git a/java/sdo/sample/src/main/resources/MedicalTest.xsd b/java/sdo/sample/src/main/resources/MedicalTest.xsd index 0188fea46c..34ae528148 100644 --- a/java/sdo/sample/src/main/resources/MedicalTest.xsd +++ b/java/sdo/sample/src/main/resources/MedicalTest.xsd @@ -1,57 +1,57 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- -->
-<schema xmlns="http://www.w3.org/2001/XMLSchema"
- xmlns:people="www.example.org/people" xmlns:sdo="commonj.sdo"
- xmlns:sdoxml="commonj.sdo/xml"
- xmlns:tns="www.example.org/MedicalTest"
- targetNamespace="www.example.org/MedicalTest">
-
- <import namespace="www.example.org/people"
- schemaLocation="People.xsd" />
-
- <element name="test" type="tns:Test" />
- <element name="condition" type="tns:Condition" />
-
- <complexType name="Test">
- <sequence>
- <element name="referrals" type="people:PersonSet" />
- <element name="patients" type="people:PersonSet" />
- <element name="relatives" type="people:PersonSet" />
- </sequence>
- </complexType>
-
- <complexType name="Condition">
- <sequence>
- <element name="diagnosed" type="date" />
- </sequence>
- <attribute name="name" type="tns:ConditionName" />
- </complexType>
-
- <simpleType name="ConditionName">
- <restriction base="string">
- <enumeration value="Rigellian fever" />
- <enumeration value="Vegan choriomeningitis" />
- <enumeration value="Scrofungulus" />
- <enumeration value="Panar Syndrome" />
- </restriction>
- </simpleType>
-
-
-</schema>
+<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + --> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:people="www.example.org/people" xmlns:sdo="commonj.sdo" + xmlns:sdoxml="commonj.sdo/xml" + xmlns:tns="www.example.org/MedicalTest" + targetNamespace="www.example.org/MedicalTest"> + + <import namespace="www.example.org/people" + schemaLocation="People.xsd" /> + + <element name="test" type="tns:Test" /> + <element name="condition" type="tns:Condition" /> + + <complexType name="Test"> + <sequence> + <element name="referrals" type="people:PersonSet" /> + <element name="patients" type="people:PersonSet" /> + <element name="relatives" type="people:PersonSet" /> + </sequence> + </complexType> + + <complexType name="Condition"> + <sequence> + <element name="diagnosed" type="date" /> + </sequence> + <attribute name="name" type="tns:ConditionName" /> + </complexType> + + <simpleType name="ConditionName"> + <restriction base="string"> + <enumeration value="Rigellian fever" /> + <enumeration value="Vegan choriomeningitis" /> + <enumeration value="Scrofungulus" /> + <enumeration value="Panar Syndrome" /> + </restriction> + </simpleType> + + +</schema> diff --git a/java/sdo/sample/src/main/resources/MedicalTest_CS.xsd b/java/sdo/sample/src/main/resources/MedicalTest_CS.xsd index 62a6d2998d..668c023bc6 100644 --- a/java/sdo/sample/src/main/resources/MedicalTest_CS.xsd +++ b/java/sdo/sample/src/main/resources/MedicalTest_CS.xsd @@ -1,58 +1,58 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- -->
-<schema xmlns="http://www.w3.org/2001/XMLSchema"
- xmlns:people="www.example.org/people" xmlns:sdo="commonj.sdo"
- xmlns:sdoxml="commonj.sdo/xml"
- xmlns:tns="www.example.org/MedicalTest"
- targetNamespace="www.example.org/MedicalTest">
-
- <import namespace="www.example.org/people"
- schemaLocation="People.xsd" />
-
- <element name="test" type="tns:Test" />
- <element name="condition" type="tns:Condition" />
-
- <complexType name="Test">
- <sequence>
- <element name="referrals" type="people:PersonSet" />
- <element name="patients" type="people:PersonSet" />
- <element name="relatives" type="people:PersonSet" />
- <element name="changes" type="sdo:ChangeSummaryType" />
- </sequence>
- </complexType>
-
- <complexType name="Condition">
- <sequence>
- <element name="diagnosed" type="date" />
- </sequence>
- <attribute name="name" type="tns:ConditionName" />
- </complexType>
-
- <simpleType name="ConditionName">
- <restriction base="string">
- <enumeration value="Rigellian fever" />
- <enumeration value="Vegan choriomeningitis" />
- <enumeration value="Scrofungulus" />
- <enumeration value="Panar Syndrome" />
- </restriction>
- </simpleType>
-
-
-</schema>
+<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + --> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:people="www.example.org/people" xmlns:sdo="commonj.sdo" + xmlns:sdoxml="commonj.sdo/xml" + xmlns:tns="www.example.org/MedicalTest" + targetNamespace="www.example.org/MedicalTest"> + + <import namespace="www.example.org/people" + schemaLocation="People.xsd" /> + + <element name="test" type="tns:Test" /> + <element name="condition" type="tns:Condition" /> + + <complexType name="Test"> + <sequence> + <element name="referrals" type="people:PersonSet" /> + <element name="patients" type="people:PersonSet" /> + <element name="relatives" type="people:PersonSet" /> + <element name="changes" type="sdo:ChangeSummaryType" /> + </sequence> + </complexType> + + <complexType name="Condition"> + <sequence> + <element name="diagnosed" type="date" /> + </sequence> + <attribute name="name" type="tns:ConditionName" /> + </complexType> + + <simpleType name="ConditionName"> + <restriction base="string"> + <enumeration value="Rigellian fever" /> + <enumeration value="Vegan choriomeningitis" /> + <enumeration value="Scrofungulus" /> + <enumeration value="Panar Syndrome" /> + </restriction> + </simpleType> + + +</schema> diff --git a/java/sdo/sample/src/main/resources/People.xsd b/java/sdo/sample/src/main/resources/People.xsd index c0402bcc3b..b9e59701ae 100644 --- a/java/sdo/sample/src/main/resources/People.xsd +++ b/java/sdo/sample/src/main/resources/People.xsd @@ -1,70 +1,70 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- -->
-<schema xmlns="http://www.w3.org/2001/XMLSchema"
- targetNamespace="www.example.org/people"
- xmlns:sdo="commonj.sdo"
- xmlns:sdoxml="commonj.sdo/xml"
- xmlns:tns="www.example.org/people">
-
- <!-- <import namespace="commonj.sdo/xml" schemaLocation="sdoXML.xsd" /> -->
-
- <complexType name="Person">
- <sequence>
- <element name="dob" type="date"/>
- <element name="relative" maxOccurs="unbounded" type="tns:Relative"/>
- <any namespace="##other" processContents="lax" maxOccurs="unbounded"/>
- </sequence>
- <attribute name="id" type="ID"/>
- <attribute name="name" type="string"/>
- <attribute name="gender" type = "tns:Gender"/>
- </complexType>
-
- <!-- <complexType name="Parent">
- <attribute name="parent" type="IDREF" sdoxml:propertyType="tns:Person" use="required"/>
- <attribute name="genetic" use="optional" type="boolean"/>
- </complexType> -->
-
- <complexType name="Relative">
- <attribute name="target" type="IDREF" sdoxml:propertyType="tns:Person" use="required"/>
- <attribute name="relationship" type="string" />
- <attribute name="genetic" use="optional" type="boolean"/>
- </complexType>
-
- <!-- <complexType name="GeneticParent">
- <complexContent>
- <extension base="tns:Parent">
- </extension>
- </complexContent>
- </complexType> -->
-
- <complexType name="PersonSet">
- <sequence>
- <element name="person" type="tns:Person" maxOccurs="unbounded"/>
- </sequence>
- </complexType>
-
- <simpleType name="Gender">
- <restriction base="string">
- <enumeration value="male" />
- <enumeration value="female" />
- </restriction>
- </simpleType>
-
-</schema>
+<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + --> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="www.example.org/people" + xmlns:sdo="commonj.sdo" + xmlns:sdoxml="commonj.sdo/xml" + xmlns:tns="www.example.org/people"> + + <!-- <import namespace="commonj.sdo/xml" schemaLocation="sdoXML.xsd" /> --> + + <complexType name="Person"> + <sequence> + <element name="dob" type="date"/> + <element name="relative" maxOccurs="unbounded" type="tns:Relative"/> + <any namespace="##other" processContents="lax" maxOccurs="unbounded"/> + </sequence> + <attribute name="id" type="ID"/> + <attribute name="name" type="string"/> + <attribute name="gender" type = "tns:Gender"/> + </complexType> + + <!-- <complexType name="Parent"> + <attribute name="parent" type="IDREF" sdoxml:propertyType="tns:Person" use="required"/> + <attribute name="genetic" use="optional" type="boolean"/> + </complexType> --> + + <complexType name="Relative"> + <attribute name="target" type="IDREF" sdoxml:propertyType="tns:Person" use="required"/> + <attribute name="relationship" type="string" /> + <attribute name="genetic" use="optional" type="boolean"/> + </complexType> + + <!-- <complexType name="GeneticParent"> + <complexContent> + <extension base="tns:Parent"> + </extension> + </complexContent> + </complexType> --> + + <complexType name="PersonSet"> + <sequence> + <element name="person" type="tns:Person" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <simpleType name="Gender"> + <restriction base="string"> + <enumeration value="male" /> + <enumeration value="female" /> + </restriction> + </simpleType> + +</schema> |