I'm still looking for input to understand if I'm doing the right kind of thing for our users with these samples. It's work in progress, but the time I have available for taking on board your suggestions is decreasing. I have just substituted the PrintPropertiesOfDataObject sample with something a bit more generic, in the new PrintDataGraph sample [1]. Again I attach the output of this sample to save you the trouble of building from the svn trunk.
Regards, Kelvin. [1] http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/sample/src/main/java/org/apache/tuscany/samples/sdo/PrintDataGraph.java?view=markup -------------------------------------------------------------- - Running with commentary level for a novice user - - Edit the sample program's constructor argument to one from - - COMMENTARY_FOR_NOVICE - - COMMENTARY_FOR_INTERMEDIATE or - - COMMENTARY_FOR_ADVANCED - - in order to alter the level of commentary you are seeing - -------------------------------------------------------------- --------------------------------------------------------------------------------- - Tuscany SDO Java Sample org.apache.tuscany.samples.sdo.PrintDataGraph - - This sample is aimed at a intermediate user - --------------------------------------------------------------------------------- ----------------------------------------------------------------------------------- - This sample demonstrates a common pattern of traversing a data graph - - and printing the values of its Properties. As the sample traverses a couple of - - graphs it provides commentary about what it has found and what actions it - - is taking, whilst building up a text representation of the graph. It then - - shows you the results of its labours. - ----------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------- - All MetaData for SDO types can be viewed as being held in an instance of HelperContext - - The Helper Context instance provides access to a collection of other helpers - - that you will see exercised in the SDO samples - - All the Helpers related to a given helper context instance know about the same set of types - - - - The SDO specification doesn't state how an SDO implementation should create a HelperContext - - So we use a Tuscany specific API to do this ... - - - - HelperContext scope = SDOUtil.createHelperContext(); - ----------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------ - First we look at a data graph of a Purchase Order which has a fairly simple XML schema - - and the graph's containment hierarchy has a couple of levels of depth - ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------ - If you want to create types dynamically by loading an XML schema you - - use an instance of XSDHelper. You get that helper from a HelperContext. - - After successful loading of a schema, the new types are available to every - - other helper belonging to the HelperContext instance - - - - XSDHelper xsdHelper = scope.getXSDHelper(); - - xsdHelper.define(inputStream, null); - ------------------------------------------------------------------------------ ------------------------------------------------------------------------------- - The XMLHelper can be used to create an SDO XMLDocument instance from a file - - - - inputStream = ClassLoader.getSystemResourceAsStream(filename); - - result = scope.getXMLHelper().load(is); - ------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------- - We are going to traverse a data graph that has been wrapped in an instance of XMLDocument - - Amongst other things, the XMLDocument instance provides access to the root element name - - and the root DataObject of the data graph. - - - - xmlDocument.getRootElementName(); - - xmlDocument.getRootObject(); - --------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------- - We begin traversing the data graph by examining the root object of the graph's containment hierarchy - - making a record of the values of its Properties. As we inspect the values of the Properties of this object - - if we encounter contained DataObjects, then we will recurse through the containment hierarchy of the - - data graph in a depth first fashion, and create a text representaation of the graph that we'll print - - out after the graph traversal has been completed. - -------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------- - We access the Property values of this DataObject by first getting the list of 'Instance Properties' - - from the DataObject. For many DataObjects, this will be the same set of Properties that are defined - - by the DataObject's Type. However, if the DataObject's type is 'Open' then an instance of that Type - - may contain more Properties that the type itself. The list of Instance Properties will always include - - the Properties defined in the Type, but will also include any Properties that the instance has values for - - by virtue of it's type being 'Open' - - - - for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) { - - Property p = (Property) dataObject.getInstanceProperties().get(i); - -------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------- - We are about to inspect the value of a Property, but we must - - consider the nature of that Property in order to deal with it appropriately. - - Firstly we see if the Property value has been set (dataObject.isSet(property)) - - Then we see if the Property is simple valued (property.isDataType() == true) - - --if not then we know it's a DataObject and we must recurse deepen into the graph's - - containment hierarchy - - Whether or not the property value is a DataObject, is may be single or multi-valued - - so we must either use one of the DataObject's get*(Property) accessors for single - - valued Properties or the getList() method for multi-valued properties. - - Another thing we must deal with when the Property is a DataObject, is whether or not the - - Property is a 'containment' Property. If it isn't then we simple record the fact that - - we have encountered this non-containment relationship, and move on to the next Property - -------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------- - We have arrived at a contained dataObject in the graph, and will inspect its Property values, - - recursing deeper if necessary - ------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------- - Traversing the instance Properties of this DataObject - - for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) { - - Property p = (Property) dataObject.getInstanceProperties().get(i); - ------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ------------------------------------------- - Inspecting another contained dataObject - ------------------------------------------- ------------------------------------------------------------------------- - Traversing the instance Properties of this DataObject - - for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) { - - Property p = (Property) dataObject.getInstanceProperties().get(i); - ------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ------------------------------------------- - Inspecting another contained dataObject - ------------------------------------------- ------------------------------------------------------------------------- - Traversing the instance Properties of this DataObject - - for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) { - - Property p = (Property) dataObject.getInstanceProperties().get(i); - ------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------ - Traversing a list of DataObjects which represent the values of a multi-valued containment Property - ------------------------------------------------------------------------------------------------------ ------------------------------------------- - Inspecting another contained dataObject - ------------------------------------------- ------------------------------------------------------------------------- - Traversing the instance Properties of this DataObject - - for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) { - - Property p = (Property) dataObject.getInstanceProperties().get(i); - ------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ------------------------------------------- - Inspecting another contained dataObject - ------------------------------------------- ------------------------------------------------------------------------- - Traversing the instance Properties of this DataObject - - for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) { - - Property p = (Property) dataObject.getInstanceProperties().get(i); - ------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ------------------------------------------- - Inspecting another contained dataObject - ------------------------------------------- ------------------------------------------------------------------------- - Traversing the instance Properties of this DataObject - - for (int i = 0; i < dataObject.getInstanceProperties().size(); i++) { - - Property p = (Property) dataObject.getInstanceProperties().get(i); - ------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- - Inspecting another property to determine how to access it's value, as we saw before - ---------------------------------------------------------------------------------------- ---------------------------------------------------- - And here is the resultant view of the data graph - ---------------------------------------------------- XMLDocument: purchaseOrder DataObject: Type: http://www.example.com/PO#PurchaseOrderType Property shipTo: - DataObject: Type: http://www.example.com/PO#USAddress Property name: - Robbie Minshall Property street: - 123 Maple Street Property city: - Mill Valley Property state: - CA Property zip: - 90952 Property country: - US Property billTo: - DataObject: Type: http://www.example.com/PO#USAddress Property name: - Robert Smith Property street: - 8 Oak Avenue Property city: - Mill Valley Property state: - PA Property zip: - 95819 Property country: - US Property comment: - Hurry, my lawn is going wild! Property items: - DataObject: Type: http://www.example.com/PO#Items Property item: - [ DataObject: Type: http://www.example.com/PO#item Property productName: - Lawnmower Property price: - 148.95 Property quantity: - 1 Property comment: - Confirm this is electric Property shipDate: - is not set Property partNum: - 872-AA DataObject: Type: http://www.example.com/PO#item Property productName: - Baby Monitor Property price: - 39.98 Property quantity: - 1 Property comment: - is not set Property shipDate: - 1999-05-21 Property partNum: - 926-AA DataObject: Type: http://www.example.com/PO#item Property productName: - GrassSeed Property price: - 50 Property quantity: - 100 Property comment: - For Shade Property shipDate: - is not set Property partNum: - 876 ] Property orderDate: - 1999-10-20 ------------------------------------------------------------------------------ - Next we look at a graph represneting a form letter, where the Type of the - - root data object is 'Sequenced' - ------------------------------------------------------------------------------ --------------------------------------------------------------------------------------------------- - Using an XSDHelper again to create types from an XML schema file as we saw in a previous sample - --------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- - Getting an XMLDocument instance from an XML file as seen in previous samples - -------------------------------------------------------------------------------- -------------------------------------------------------------------------------------- - An XMLDocument instance provides a wrapper for the root DataObject of a data graph - - along with other aspects of the XML nature of the document - - - - DataObject result = xmlDoc.getRootObject(); - -------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------- - We are beginning to start to traverse another data graph from its root object, as we have seen previously - ------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- - We've encountered a DataObject in the graph for which the Type is 'Sequenced' - - That is to say that the order of addition of property values to the DataObject instance - - is important, and is preserved by the DataObject - - - - dataObject.getType().isSequenced(); - ------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------- - The Property/Value pairs of a Sequence can be accessed via the getProperty(int) and getValue(int) - - accessor methods of the Sequence interface. The size() method of the Sequence tells us how many there are - - If the getProperty(int) method retunes null, then the value is text. These values may be encountered - - when the DataObject's type is 'mixed' (dataObject.getType().isMixed() == true). A typical example of this - - is when the data graph represents a form letter. - -------------------------------------------------------------------------------------------------------------- ---------------------------------------------------- - And here is the resultant view of the data graph - ---------------------------------------------------- DataObject: Type: letter.xsd#FormLetter Sequence: { Property: date: August 1, 2003 text: Mutual of Omaha Wild Kingdom, USA Dear Property: firstName: Casy Property: lastName: Crocodile text: Please buy more shark repellent. Your premium is past due. } ----------------------------------------------------------------------- - End of sample org.apache.tuscany.samples.sdo.PrintDataGraph - -----------------------------------------------------------------------
