You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by fr...@apache.org on 2007/05/14 17:38:09 UTC

svn commit: r537884 [1/2] - in /incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo: api/ helper/ rtlib/ rtlib/helper/ util/

Author: frankb
Date: Mon May 14 08:38:08 2007
New Revision: 537884

URL: http://svn.apache.org/viewvc?view=rev&rev=537884
Log:
First step of TUSCANY-1283 - add some new packages/classes

Added:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/HelperProviderBase.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/SDOHelperBase.java
Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLStreamHelper.java
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java

Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java?view=auto&rev=537884
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java Mon May 14 08:38:08 2007
@@ -0,0 +1,376 @@
+/**
+ *
+ *  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.sdo.api;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sdo.helper.XMLStreamHelper;
+
+import commonj.sdo.DataGraph;
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Sequence;
+import commonj.sdo.Type;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * This interface provides helper functions which are not included in the SDO specification itself.
+ * Use of the functions in this interface is recommended, instead of resorting to low-level 
+ * implementation-specific APIs.
+ */
+public interface SDOHelper
+{
+  /**
+   * Create a non-extensible HelperContext to provide access to a consistent set of Helpers which make use
+   * of a new TypeHelper instance to provide scope for type definitions.
+   * @return the new HelperContext
+   * @see #createHelperContext(boolean)
+   */
+  public HelperContext createHelperContext();
+
+  /**
+   * Create a HelperContext to provide access to a consistent set of Helpers which make use of a new
+   * TypeHelper instance to provide scope for type definitions.
+   * @param extensibleNamespaces true if the contents of a namespaces should be incrementally modifiable over time
+   * @return the new HelperContext
+   */
+  public HelperContext createHelperContext(boolean extensibleNamespaces);
+
+  /**
+   * Creates an instance of a data type from the specified string.
+   * @param dataType a Type, for which isDataType() returns true, to instantiate.
+   * @param literal the string value of the dataType.
+   * @return an instance of the dataType.
+   * @see #convertToString(Type, Object)
+   */
+  public Object createFromString(Type dataType, String literal);
+
+  /**
+   * Converts an instance of a data type to a string literal representation.
+   * @param dataType the Type, for which isDataType() returns true, of the value to convert.
+   * @param value a value of the dataType.
+   * @return the string literal representation of the value.
+   * @see #createFromString(Type, String)
+   */
+  public String convertToString(Type dataType, Object value);
+
+  /**
+   * Create a DataObject wrapper for an instance of the specified dataType.
+   * This method is typically used to create a root object that can be passed to the XMLHelper.save() 
+   * method when the root element to be serialized is an XMLSchema simpleType.
+   * @param dataType a Type for which isDataType() returns true.
+   * @param value the instance value.
+   * @return a DataObject wrapper for the specified value.
+   */
+  public DataObject createDataTypeWrapper(Type dataType, Object value);
+
+  /**
+   * Get the SDO built-in type corresponding to the specified XSD type in the XML Schema
+   * namespace ("http://www.w3.org/2001/XMLSchema").
+   * @param xsdType a type name in the XML Schema namespace.
+   * @return the SDO built-in Type corresponding to the specified XSD type.
+   */
+  public Type getXSDSDOType(String xsdType);
+
+  /**
+   * Gets the Sequence corresponding to the specified substitutable Property of the specified DataObject.
+   * @param dataObject the data object.
+   * @param head a substitution group head property.
+   * @return the Sequence corresponding to the specified substitutable Property of the specified DataObject or
+   *         null if the specified Property isn't a substitution head.
+   */
+  public Sequence getSubstitutionValues(DataObject dataObject, Property head);
+
+  /**
+   * Get the SDO built-in type corresponding to the specified Java instanceClass.
+   * @param javaClass the Java instanceClass of the type.
+   * @return the SDO built-in Type corresponding to the specified instanceClass.
+   */
+  public Type getJavaSDOType(Class javaClass);
+
+  /**
+   * Return whether at least one value is required for a valid instance of the specified property.
+   * @param the property in question.
+   * @return true if the property is required.
+   */
+  public boolean isRequired(Property property);
+
+  /**
+   * Return the upper bound of the specified property or -1 if unbounded.
+   * @param the property in question.
+   * @return the upper bound.
+   */
+  public int getUpperBound(Property property);
+
+  /**
+   * Returns whether the Property is many-valued given the specified context.
+   * @param property The Property in question
+   * @param context The context to check whether the specified Property is many-valued
+   * @return true if the Property is many-valued given the specified context.
+   */
+  public boolean isMany(Property property, DataObject context);
+
+  /**
+   * Create an empty data graph.
+   * @return the new data graph instance.
+   */
+  public DataGraph createDataGraph();
+
+  /**
+   * Set the root object of a data graph.
+   * @param dataGraph the data graph in which to set the root object.
+   * @param rootObject the root object.
+   */
+  public void setRootObject(DataGraph dataGraph, DataObject rootObject);
+
+  /**
+   * Load a serialized data graph from the specified insputStream.
+   * 
+   * @param inputStream the inputStream of the data graph.
+   * @param options loader control options, or null.
+   * @param scope the TypeHelper in which to register deserialized Types and to find Types when
+   *              creating DataObject instances, or null for default TypeHelper.
+   * @return the de-serialized data graph.
+   * @throws IOException
+   */
+  public DataGraph loadDataGraph(InputStream inputStream, Map options, TypeHelper scope) throws IOException;
+
+  /**
+   * Serialize the specified data graph to the specified outputStream.
+   * @param dataGraph the data graph to save.
+   * @param outputStream the outputStream for the data graph.
+   * @param options serializer control options, or null.
+   * @throws IOException
+   */
+  public void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, Map options) throws IOException;
+
+  /**
+   * Registers the specified {@link Type type}(s) to be serialized along with
+   * the {@link DataObject data object}(s) in the graph. For example, the list of types returned from 
+   * {@link TypeHelper#define} can be registered with this method, allowing deserialization of
+   * instances of a dynamically defined model.
+   * @param dataGraph the DataGraph in which to register the specified type(s).
+   * @param types a list containing the type(s) to be registered (TBD or null to automatically register all 
+   * types used by the objects in the DataGraph).
+   */
+  public void registerDataGraphTypes(DataGraph dataGraph, List/*Type*/types);
+
+  /**
+   * Create a new cross scope CopyHelper.
+   * @param targetScope the TypeHelper containing the Types to use to create the copy objects.
+   * @return the new CopyHelper.
+   */
+  public CopyHelper createCrossScopeCopyHelper(TypeHelper targetScope);
+
+  /**
+   * Create a new XMLStreamHelper, with visibility to types in the specified TypeHelper scope.
+   * @param scope the TypeHelper to use for locating types.
+   * @return the new XMLStreamHelper.
+   */
+  public XMLStreamHelper createXMLStreamHelper(TypeHelper scope);
+  
+  /**
+   * Create a new ObjectInputStream in the specifice HelperContext scope.
+   * @param inputStream the inputStream with which to create the ObjectInputStream.
+   * @param helperContext the HelperContext scope.
+   * @return the new ObjectInputStream.
+   */
+  public ObjectInputStream createObjectInputStream(InputStream inputStream, HelperContext helperContext) throws IOException;
+
+  /**
+   * Create a new ObjectOutputStream in the specifice HelperContext scope.
+   * @param outputStream the outputStream with which to create the ObjectOutputStream.
+   * @param helperContext the HelperContext scope.
+   * @return the new ObjectOutputStream.
+   */
+  public ObjectOutputStream createObjectOutputStream(OutputStream outputStream, HelperContext helperContext) throws IOException;
+
+  /**
+   * Gets all of the types associated with a uri.
+   * @param scope the TypeHelper to use for locating types.
+   * @param uri the URI of the Types
+   * @return a List containing instances of Type, null if uri is not found.
+   */
+  public List getTypes(TypeHelper scope, String uri);
+
+  /**
+   * Gets the open content subset of the specified DataObject's instance properties.
+   * @param dataObject the DataObject instance
+   * @return a List containing any open content properties of the DataObject
+   */
+  public List getOpenContentProperties(DataObject dataObject);
+
+  /**
+   * Return true if the specified type is a special DocumentRoot Type.
+   * @param type the Type in question
+   * @return a List containing the open content properties
+   */
+  public boolean isDocumentRoot(Type type);
+  
+  /**
+   * Gets a MetaDataBuilder which can be used to programatically create SDO Types and Properties.
+   * @return a MetaDataBuilder instance
+   */
+  public MetaDataBuilder getMetaDataBuilder();
+
+  /**
+   * This interface provides methods which can be used to programatically create SDO Types and Properties.
+   * It provides a lower level and more efficient API then the DataObject-based one of TypeHelper.define().
+   */
+  public interface MetaDataBuilder
+  {
+    /**
+     * Create a Type in the specified TypeHelper scope.
+     * @return the new Type.
+     */
+    public Type createType(TypeHelper scope, String uri, String name, boolean isDataType);
+
+    /**
+     * Add a baseType to the specified type.
+     */
+    public void addBaseType(Type type, Type baseType);
+
+    /**
+     * Add an aliasName to the specified type.
+     */
+    public void addAliasName(Type type, String aliasName);
+
+    /**
+     * Set the isOpen value of the specified type.
+     */
+    public void setOpen(Type type, boolean isOpen);
+
+    /**
+     * Set the isSequenced value of the specified type.
+     */
+    public void setSequenced(Type type, boolean isSequenced);
+
+    /**
+     * Set the isAbstract value of the specified type.
+     */
+    public void setAbstract(Type type, boolean isAbstract);
+
+    /**
+     * Set the isAbstract value of the specified type.
+     */
+    public void setJavaClassName(Type type, String javaClassName);
+
+    /**
+     * Create a new property in the specified containingType.
+     */
+    public Property createProperty(Type containingType, String name, Type propertyType);
+
+    /**
+     * Create a new open content property in the specified TypeHelper scope.
+     */
+    public Property createOpenContentProperty(TypeHelper scope, String uri, String name, Type type);
+
+    /**
+     * Add an aliasName to the specified property.
+     */
+    public void addAliasName(Property property, String aliasName);
+
+    /**
+     * Set the isMany value of the specified property.
+     */
+    public void setMany(Property property, boolean isMany);
+
+    /**
+     * Set the isContainment value of the specified property.
+     */
+    public void setContainment(Property property, boolean isContainment);
+
+    /**
+     * Set the default value of the specified property.
+     */
+    public void setDefault(Property property, String defaultValue);
+
+    /**
+     * Set the isReadOnly value of the specified property.
+     */
+    public void setReadOnly(Property property, boolean isReadOnly);
+
+    /**
+     * Set the opposite value of the specified property.
+     */
+    public void setOpposite(Property property, Property opposite);
+
+    /**
+     * Add an instance property to the specified type.
+     */
+    public void addTypeInstanceProperty(Type definedType, Property instanceProperty, Object value);
+
+    /**
+     * Add anf instance property to the specified property.
+     */
+    public void addPropertyInstanceProperty(Property definedProperty, Property instanceProperty, Object value);
+  }
+
+  /**
+   * This interface contains options that can be passed to the XMLHelper load() and save() methods.
+   */
+  public interface XMLOptions
+  {
+    /**
+     * Line Break String such as "\n", "\r\n", "\r" and "", absence/null is the default (line.separator System Property)
+     */
+    final String XML_SAVE_LINE_BREAK = "LineBreak";
+
+    /**
+     * Indent String such as "\t", "", etc. absence/null is the default ("  ")
+     */
+    final String XML_SAVE_INDENT = "indent";
+
+    /**
+     * Margin String such as " ", "\t\t", etc. Absence/null/"" is the default (no margin)
+     */
+    final String XML_SAVE_MARGIN = "margin";
+
+    /**
+     * Attribute formatting that exceeds the specified width as Integer will cause a line break so that formatting will continue indented on the next line
+     */
+    final String XML_SAVE_LINE_WIDTH = "LINE_WIDTH";
+
+    /**
+     * Boolean to save a doctype declaration 
+     */
+    final String XML_SAVE_DOCTYPE = "SAVE_DOCTYPE";
+
+    /**
+     * Boolean to process the schemaLocation/noNamespaceSchemaLocation attributes occurring in the instance document to {@link XSDHelper#define convert XSD(s) to Types} 
+     */
+    final String XML_LOAD_SCHEMA = "ProcessSchemaLocations";
+
+    /**
+     * To tolerate malformed elements and attributes (default unless set by System property XML.load.form.lax). 0 not to.  
+     */
+    final String XML_LOAD_LAX_FORM = "load malform";
+  }
+
+}

Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java?view=auto&rev=537884
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java Mon May 14 08:38:08 2007
@@ -0,0 +1,377 @@
+/**
+ *
+ *  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.sdo.api;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sdo.rtlib.helper.HelperProviderBase;
+
+import commonj.sdo.DataGraph;
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Sequence;
+import commonj.sdo.Type;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.impl.HelperProvider;
+
+/**
+ * This class provides convenient static utility functions for calling the default SDOHelper.
+ */
+public final class SDOUtil
+{
+  protected static SDOHelper defaultSDOHelper = ((HelperProviderBase)HelperProvider.INSTANCE).sdoHelper();
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createDataTypeWrapper(Type, Object)}.
+   */
+  public static DataObject createDataTypeWrapper(Type dataType, Object value)
+  {
+    return defaultSDOHelper.createDataTypeWrapper(dataType, value);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createFromString(Type, String)}.
+   */
+  public static Object createFromString(Type dataType, String literal)
+  {
+    return defaultSDOHelper.createFromString(dataType, literal);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#convertToString(Type, Object)}.
+   */
+  public static String convertToString(Type dataType, Object value)
+  {
+    return defaultSDOHelper.convertToString(dataType, value);
+  }
+
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#getXSDSDOType(String)}.
+   */
+  public static Type getXSDSDOType(String xsdType)
+  {    
+    return defaultSDOHelper.getXSDSDOType(xsdType);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#getSubstitutionValues(DataObject, Property)}.
+   */
+  public static Sequence getSubstitutionValues(DataObject dataObject, Property head)
+  {
+    return defaultSDOHelper.getSubstitutionValues(dataObject, head);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#getJavaSDOType(Class)}.
+   */
+  public static Type getJavaSDOType(Class javaClass)
+  {    
+    return defaultSDOHelper.getJavaSDOType(javaClass);
+  }
+
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#isRequired(Property)}.
+   */
+  public static boolean isRequired(Property property)
+  {
+    return defaultSDOHelper.isRequired(property);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#getUpperBound(Property)}.
+   */
+  public static int getUpperBound(Property property)
+  {
+    return defaultSDOHelper.getUpperBound(property);
+  }
+
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#isMany(Property, DataObject)}.
+   */
+  public static boolean isMany(Property property, DataObject context) 
+  {
+    return defaultSDOHelper.isMany(property, context);
+  }
+
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createDataGraph}.
+   */
+  public static DataGraph createDataGraph()
+  {
+    return defaultSDOHelper.createDataGraph();
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#setRootObject(DataGraph, DataObject)}.
+   */
+  public static void setRootObject(DataGraph dataGraph, DataObject rootObject)
+  {
+    defaultSDOHelper.setRootObject(dataGraph, rootObject);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#loadDataGraph(InputStream, Map, TypeHelper)}.
+   */
+  public static DataGraph loadDataGraph(InputStream inputStream, Map options) throws IOException
+  {
+    return defaultSDOHelper.loadDataGraph(inputStream, options, null);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#loadDataGraph(InputStream, Map, TypeHelper)}.
+   */
+  public static DataGraph loadDataGraph(InputStream inputStream, Map options, TypeHelper scope) throws IOException
+  {
+    return defaultSDOHelper.loadDataGraph(inputStream, options, scope);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#saveDataGraph(DataGraph, OutputStream, Map)}.
+   */
+  public static void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, Map options) throws IOException
+  {
+    defaultSDOHelper.saveDataGraph(dataGraph, outputStream, options);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#registerDataGraphTypes(DataGraph, List)}.
+   */
+  public static void registerDataGraphTypes(DataGraph dataGraph, List/*Type*/ types)
+  {
+    defaultSDOHelper.registerDataGraphTypes(dataGraph, types);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createHelperContext(boolean)}.
+   */
+  public static HelperContext createHelperContext(boolean extensibleNamespaces)
+  {
+    return defaultSDOHelper.createHelperContext(extensibleNamespaces);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createHelperContext}.
+   */
+  public static HelperContext createHelperContext()
+  {
+    return defaultSDOHelper.createHelperContext();
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createCrossScopeCopyHelper(TypeHelper)}.
+   */
+  public static CopyHelper createCrossScopeCopyHelper(TypeHelper targetScope) 
+  {
+    return defaultSDOHelper.createCrossScopeCopyHelper(targetScope); 
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createXMLStreamHelper(TypeHelper)}.
+   */
+  public static XMLStreamHelper createXMLStreamHelper(TypeHelper scope)
+  {
+    return defaultSDOHelper.createXMLStreamHelper(scope);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createObjectInputStream(InputStream, HelperContext)}.
+   */
+  public static ObjectInputStream createObjectInputStream(InputStream inputStream, HelperContext helperContext) throws IOException
+  {
+    return defaultSDOHelper.createObjectInputStream(inputStream, helperContext);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createObjectOutputStream(OutputStream, HelperContext)}.
+   */
+  public static ObjectOutputStream createObjectOutputStream(OutputStream outputStream, HelperContext helperContext) throws IOException
+  {
+    return defaultSDOHelper.createObjectOutputStream(outputStream, helperContext);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#getTypes(TypeHelper, String)}.
+   */
+  public static List getTypes(TypeHelper scope, String uri) {
+
+    return defaultSDOHelper.getTypes(scope, uri);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#getOpenContentProperties(DataObject)}.
+   */
+  public static List getOpenContentProperties(DataObject dataObject)
+  {
+    return defaultSDOHelper.getOpenContentProperties(dataObject);
+  }
+
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#isDocumentRoot(Type)}.
+   */
+  public static boolean isDocumentRoot(Type type)
+  {
+    return defaultSDOHelper.isDocumentRoot(type);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#createType(TypeHelper, String, String, boolean)}.
+   */
+  public static Type createType(TypeHelper scope, String uri, String name, boolean isDataType)
+  {
+    return defaultSDOHelper.getMetaDataBuilder().createType(scope, uri, name, isDataType);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#addBaseType(Type, Type)}.
+   */
+  public static void addBaseType(Type type, Type baseType)
+  {
+    defaultSDOHelper.getMetaDataBuilder().addBaseType(type, baseType);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#addAliasName(Type, String)}.
+   */
+  public static void addAliasName(Type type, String aliasName)
+  {
+    defaultSDOHelper.getMetaDataBuilder().addAliasName(type, aliasName);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setOpen(Type, boolean)}.
+   */
+  public static void setOpen(Type type, boolean isOpen)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setOpen(type, isOpen);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setSequenced(Type, boolean)}.
+   */
+  public static void setSequenced(Type type, boolean isSequenced)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setSequenced(type, isSequenced);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setAbstract(Type, boolean)}.
+   */
+  public static void setAbstract(Type type, boolean isAbstract)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setAbstract(type, isAbstract);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setJavaClassName(Type, String)}.
+   */
+  public static void setJavaClassName(Type type, String javaClassName)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setJavaClassName(type, javaClassName);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#createProperty(Type, String, Type)}.
+   */
+  public static Property createProperty(Type containingType, String name, Type propertyType)
+  {
+    return defaultSDOHelper.getMetaDataBuilder().createProperty(containingType, name, propertyType);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#createOpenContentProperty(TypeHelper, String, String, Type)}.
+   */
+  public static Property createOpenContentProperty(TypeHelper scope, String uri, String name, Type type)
+  {
+    return defaultSDOHelper.getMetaDataBuilder().createOpenContentProperty(scope, uri, name, type);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#addAliasName(Property, String)}.
+   */
+  public static void addAliasName(Property property, String aliasName)
+  {
+    defaultSDOHelper.getMetaDataBuilder().addAliasName(property, aliasName);
+  }
+ 
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setMany(Property, boolean)}.
+   */
+  public static void setMany(Property property, boolean isMany)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setMany(property, isMany);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setContainment(Property, boolean)}.
+   */
+  public static void setContainment(Property property, boolean isContainment)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setContainment(property, isContainment);
+  }
+
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setDefault(Property, String)}.
+   */
+  public static void setDefault(Property property, String defaultValue)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setDefault(property, defaultValue);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setReadOnly(Property, boolean)}.
+   */
+  public static void setReadOnly(Property property, boolean isReadOnly)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setReadOnly(property, isReadOnly);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#setOpposite(Property, Property)}.
+   */
+  public static void setOpposite(Property property, Property opposite)
+  {
+    defaultSDOHelper.getMetaDataBuilder().setOpposite(property, opposite);
+  }
+  
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#addTypeInstanceProperty(Type, Property, Object)}.
+   */
+  public static void addTypeInstanceProperty(Type definedType, Property property, Object value)
+  {
+    defaultSDOHelper.getMetaDataBuilder().addTypeInstanceProperty(definedType, property, value);
+  }
+
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper.MetaDataBuilder#addPropertyInstanceProperty(Property, Property, Object)}.
+   */
+  public static void addPropertyInstanceProperty(Property definedProperty, Property property, Object value)
+  {
+    defaultSDOHelper.getMetaDataBuilder().addPropertyInstanceProperty(definedProperty, property, value);
+  }
+  
+}

Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java?view=auto&rev=537884
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java Mon May 14 08:38:08 2007
@@ -0,0 +1,113 @@
+/**
+ *
+ *  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.sdo.api;
+
+import java.util.Map;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.XMLDocument;
+
+/**
+ * Helper interface for reading and writing SDO DataObjects from XML streams (StAX).
+ *
+ * @version $Rev: 503913 $ $Date: 2007-02-05 17:53:34 -0500 (Mon, 05 Feb 2007) $
+ */
+public interface XMLStreamHelper
+{
+  /**
+   * Creates and returns an XMLDocument from an XML input stream.
+   * The reader must be positioned on a START_DOCUMENT event.
+   *
+   * @param reader the stream to read
+   * @return an XMLDocument created from the stream
+   * @throws XMLStreamException    if there was a problem reading the stream
+   * @throws IllegalStateException if the reader is not positioned on a START_DOCUMENT event
+   */
+  XMLDocument load(XMLStreamReader reader) throws XMLStreamException, IllegalStateException;
+
+  /**
+   * Save a XMLDocument to an XML stream.
+   *
+   * @param document the document to be written
+   * @param writer   the stream to write to
+   * @throws XMLStreamException if there was a problem writing to the stream
+   */
+  void save(XMLDocument document, XMLStreamWriter writer) throws XMLStreamException;
+
+  /**
+   * Creates and returns a XMLStreamReader that can be used to read an XMLDocument as a XML event stream.
+   * The reader will be positioned on a START_DOCUMENT event.
+   *
+   * @param document the XMLDocument to be read
+   * @return an XMLStreamReader that can be used to read the document
+   */
+  XMLStreamReader createXMLStreamReader(XMLDocument document) throws XMLStreamException;
+
+  /**
+   * Create a DataObject from an element in a XML stream.
+   * The reader must be positioned on a START_ELEMENT event.
+   *
+   * @param reader the stream to read
+   * @return a DataObject created from the element in the stream
+   * @throws XMLStreamException    if there was a problem reading the stream
+   * @throws IllegalStateException if the reader is not positioned on a START_ELEMENT event
+   */
+  DataObject loadObject(XMLStreamReader reader) throws XMLStreamException, IllegalStateException;
+
+  /**
+   * Default Type to load DataObject if the element is unqualified/local without xsi:type
+   * or the qualified/global element or xsi:type fail to resolve.
+   * Can be null.
+   */
+  String OPTION_DEFAULT_ROOT_TYPE = "default root type";
+
+  /**
+   * Create a DataObject from an element in a XML stream.
+   * The reader must be positioned on a START_ELEMENT event.
+   *
+   * @param reader the stream to read
+   * @param options {@link OPTION_DEFAULT_ROOT_TYPE}; can be null or empty
+   * @return a DataObject created from the element in the stream
+   * @throws XMLStreamException    if there was a problem reading the stream
+   * @throws IllegalStateException if the reader is not positioned on a START_ELEMENT event
+   */
+  DataObject loadObject(XMLStreamReader reader, Map options) throws XMLStreamException, IllegalStateException;
+
+  /**
+   * Save a DataObject to an XML stream.
+   *
+   * @param sdo    the DataObject to be written
+   * @param writer the stream to write to
+   * @throws XMLStreamException if there was a problem writing to the stream
+   */
+  void saveObject(DataObject sdo, XMLStreamWriter writer) throws XMLStreamException;
+
+  /**
+   * Creates and returns a XMLStreamReader that can be used to read a DataObject as a XML event stream.
+   * The reader will be positioned on a START_ELEMENT event.
+   *
+   * @param sdo the DataObject to be read
+   * @return an XMLStreamReader that can be used to read the DataObject
+   */
+  XMLStreamReader createXMLStreamReader(DataObject sdo);
+}

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java?view=diff&rev=537884&r1=537883&r2=537884
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java (original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java Mon May 14 08:38:08 2007
@@ -20,54 +20,17 @@
 package org.apache.tuscany.sdo.helper;
 
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.NotSerializableException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.ObjectStreamException;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
+import org.apache.tuscany.sdo.rtlib.helper.HelperProviderBase;
 
-import org.apache.tuscany.sdo.util.DataObjectUtil;
-import org.apache.tuscany.sdo.util.resource.SDOObjectInputStream;
-
-import commonj.sdo.DataGraph;
-import commonj.sdo.DataObject;
-import commonj.sdo.helper.CopyHelper;
-import commonj.sdo.helper.DataFactory;
-import commonj.sdo.helper.DataHelper;
-import commonj.sdo.helper.EqualityHelper;
 import commonj.sdo.helper.HelperContext;
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XMLDocument;
-import commonj.sdo.helper.XMLHelper;
-import commonj.sdo.helper.XSDHelper;
-import commonj.sdo.impl.HelperProvider;
-import commonj.sdo.impl.ExternalizableDelegator.Resolvable;
 
 
 /**
  * Create and manage all the default helper INSTANCEs
  */
-public class HelperProviderImpl extends HelperProvider
+public class HelperProviderImpl extends HelperProviderBase
 {
-  protected CopyHelper copyHelper;
-
-  protected DataFactory dataFactory;
-
-  protected DataHelper dataHelper;
-
-  protected EqualityHelper equalityHelper;
-
-  protected TypeHelper typeHelper;
-
-  protected XMLHelper xmlHelper;
-
-  protected XSDHelper xsdHelper;
-
-  public HelperProviderImpl()
+  public void createDefaultHelpers()
   {
     //FB HelperContext hc = SDOUtil.createHelperContext();
     //FB The defulat HelperContext must use EMF's ClassLoader-delegating EPackage.Registry.INSTANCE, until we provide
@@ -80,157 +43,7 @@
     copyHelper = new CopyHelperImpl();
     equalityHelper = new EqualityHelperImpl();
     dataHelper = new DataHelperImpl();
+    sdoHelper = new SDOHelperImpl();
   }
-
-  public CopyHelper copyHelper()
-  {
-    return copyHelper;
-  }
-
-  public DataFactory dataFactory()
-  {
-    return dataFactory;
-  }
-
-  public DataHelper dataHelper()
-  {
-    return dataHelper;
-  }
-
-  public EqualityHelper equalityHelper()
-  {
-    return equalityHelper;
-  }
-
-  public TypeHelper typeHelper()
-  {
-    return typeHelper;
-  }
-
-  public XMLHelper xmlHelper()
-  {
-    return xmlHelper;
-  }
-
-  public XSDHelper xsdHelper()
-  {
-    return xsdHelper;
-  }
-
-  public Resolvable resolvable()
-  {
-    return new ResolvableImpl();
-  }
-
-  public Resolvable resolvable(Object target)
-  {
-    return new ResolvableImpl(target);
-  }
-
-  protected class ResolvableImpl implements Resolvable
-  {
-    protected Object target;
-    
-    public ResolvableImpl(Object target) { this.target = target; }
-    
-    public ResolvableImpl() { this.target = null; }
-
-    public void writeExternal(ObjectOutput out) throws IOException
-    {
-      if (target instanceof DataObject)
-      {
-        writeDataObject((DataObject)target, out);
-      }
-      else
-      {
-        throw new NotSerializableException(); // should never happen
-      }
-    }
-
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
-    {
-      target = readDataObject(in);
-    }
-
-    public Object readResolve() throws ObjectStreamException
-    {
-      return target;
-    }
-    
-    protected void writeDataObject(DataObject dataObject, ObjectOutput objectOutput) throws IOException
-    {
-      DataGraph dataGraph = dataObject.getDataGraph();
-      if (dataGraph != null)
-      {
-        objectOutput.writeByte(0);
-        objectOutput.writeUTF(DataObjectUtil.getXPath(dataObject));
-        objectOutput.writeObject(dataGraph);
-      }
-      else if (dataObject.getContainer() != null)
-      {
-        objectOutput.writeByte(0);
-        objectOutput.writeUTF(DataObjectUtil.getXPath(dataObject));
-        objectOutput.writeObject(dataObject.getRootObject());
-      }
-      else
-      {
-        // Root object
-        objectOutput.writeByte(1);
-
-        ByteArrayOutputStream compressedByteArrayOutputStream = new ByteArrayOutputStream();
-        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(compressedByteArrayOutputStream);
-        XMLHelper xmlHelperLocal = xmlHelper;
-        if(objectOutput instanceof SDOObjectInputStream)
-        {
-            xmlHelperLocal = ((SDOObjectInputStream)objectOutput).getHelperContext().getXMLHelper();
-        }
-        xmlHelperLocal.save(dataObject, "commonj.sdo", "dataObject", gzipOutputStream);
-        gzipOutputStream.close(); // Flush the contents
-
-        byte[] byteArray = compressedByteArrayOutputStream.toByteArray();
-        objectOutput.writeInt(byteArray.length);
-        objectOutput.write(byteArray);
-      }
-    }
-
-    protected DataObject readDataObject(ObjectInput objectInput) throws IOException, ClassNotFoundException
-    {
-      boolean isRoot = objectInput.readByte() == 1;
-      if (isRoot)
-      {
-        // Root object: [rootXML] = length + XML contents
-        int length = objectInput.readInt();
-        byte[] compressedBytes = new byte [length];
-
-        int index = 0;
-        int bytesRead;
-        while (index < length) {
-            if ((bytesRead = objectInput.read(compressedBytes, index, length-index)) == -1) {
-                break;
-            }
-            index += bytesRead;
-        }
-        
-        GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedBytes));
-        XMLHelper xmlHelperLocal = xmlHelper;
-        if(objectInput instanceof SDOObjectInputStream)
-        {
-            xmlHelperLocal = ((SDOObjectInputStream)objectInput).getHelperContext().getXMLHelper();
-        }
-        XMLDocument doc = xmlHelperLocal.load(gzipInputStream);
-        gzipInputStream.close();
-
-        return doc.getRootObject();
-      }
-      else
-      {
-        // Non root object: [path] [root]
-        String xpath = objectInput.readUTF();
-        Object object = objectInput.readObject();
-        
-        DataObject root = object instanceof DataGraph ? ((DataGraph)object).getRootObject() : (DataObject)object;
-        return xpath.equals("") ? root : root.getDataObject(xpath);
-      }
-    }
-  }
+  
 }

Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java?view=auto&rev=537884
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java Mon May 14 08:38:08 2007
@@ -0,0 +1,506 @@
+/**
+ *
+ *  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.sdo.helper;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sdo.SDOExtendedMetaData;
+import org.apache.tuscany.sdo.SDOFactory;
+import org.apache.tuscany.sdo.SimpleAnyTypeDataObject;
+import org.apache.tuscany.sdo.api.SDOHelper;
+import org.apache.tuscany.sdo.impl.ClassImpl;
+import org.apache.tuscany.sdo.impl.DataGraphImpl;
+import org.apache.tuscany.sdo.impl.DynamicDataObjectImpl;
+import org.apache.tuscany.sdo.model.ModelFactory;
+import org.apache.tuscany.sdo.model.impl.ModelFactoryImpl;
+import org.apache.tuscany.sdo.rtlib.helper.SDOHelperBase;
+import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.common.util.UniqueEList;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.util.ExtendedMetaData;
+import org.eclipse.emf.ecore.util.FeatureMap;
+import org.eclipse.emf.ecore.util.FeatureMapUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+
+import commonj.sdo.DataGraph;
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Sequence;
+import commonj.sdo.Type;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+
+public class SDOHelperImpl extends SDOHelperBase implements SDOHelper, SDOHelper.MetaDataBuilder
+{
+  public DataObject createDataTypeWrapper(Type dataType, Object value)
+  {
+    SimpleAnyTypeDataObject simpleAnyType = SDOFactory.eINSTANCE.createSimpleAnyTypeDataObject();
+    simpleAnyType.setInstanceType((EDataType)dataType);
+    simpleAnyType.setValue(value);
+    return simpleAnyType;
+  }
+  
+  public Object createFromString(Type dataType, String literal)
+  {
+    return EcoreUtil.createFromString((EDataType)dataType, literal);
+  }
+  
+  public String convertToString(Type dataType, Object value)
+  {
+    return EcoreUtil.convertToString((EDataType)dataType, value);
+  }
+
+  public Type getXSDSDOType(String xsdType)
+  {    
+    Type type = null;
+    String name = (String)xsdToSdoMappings.get(xsdType);
+    if (name != null) type = (Type)((ModelFactoryImpl)ModelFactory.INSTANCE).getEClassifier(name);
+    return type;
+  }
+  
+  public Sequence getSubstitutionValues(DataObject dataObject, Property head)
+  {
+    final EStructuralFeature  group = ExtendedMetaData.INSTANCE.getGroup((EStructuralFeature)head);
+    return null == group
+      ? null
+      : (Sequence)((FeatureMap.Internal)((EObject)dataObject).eGet(group)).getWrapper();
+  }
+  
+  public Type getJavaSDOType(Class javaClass)
+  {    
+    String name = (String)javaToSdoMappings.get(javaClass);
+    if (name != null)
+    {
+      return (Type)((ModelFactoryImpl)ModelFactory.INSTANCE).getEClassifier(name);
+    }
+    return null;
+  }
+
+  public boolean isRequired(Property property)
+  {
+    return ((EStructuralFeature)property).isRequired();
+  }
+  
+  public int getUpperBound(Property property)
+  {
+    return ((EStructuralFeature) property).getUpperBound();
+  }
+
+  public boolean isMany(Property property, DataObject context) 
+  {
+    return FeatureMapUtil.isMany((EObject) context, (EStructuralFeature) property);
+  }
+
+  public DataGraph createDataGraph()
+  {
+    return SDOFactory.eINSTANCE.createDataGraph();
+  }
+  
+  public void setRootObject(DataGraph dataGraph, DataObject rootObject)
+  {
+    ((DataGraphImpl)dataGraph).setERootObject((EObject)rootObject);
+  }
+  
+  public static DataGraph loadDataGraph(InputStream inputStream, Map options) throws IOException
+  {
+    ResourceSet resourceSet = DataObjectUtil.createResourceSet();
+    Resource resource = resourceSet.createResource(URI.createURI("all.datagraph"));
+    resource.load(inputStream, options);
+    return (DataGraph)resource.getContents().get(0);
+  }
+  
+  static final Object LOADING_SCOPE = XMLResource.OPTION_EXTENDED_META_DATA;
+
+  protected void registerLoadingScope(Map options, TypeHelper scope)
+  {
+    Object extendedMetaData = ((TypeHelperImpl) scope).getExtendedMetaData();
+    options.put(LOADING_SCOPE, extendedMetaData);
+  }
+
+  public DataGraph loadDataGraph(InputStream inputStream, Map options, TypeHelper scope) throws IOException
+  {
+    DataGraph result = null;
+    if (scope == null || scope == TypeHelper.INSTANCE) {
+      result = loadDataGraph(inputStream, options);
+    } else if (options == null) {
+      options = new HashMap();
+      registerLoadingScope(options, scope);
+      result = loadDataGraph(inputStream, options);
+    } else if (options.containsKey(LOADING_SCOPE)) {
+      Object restore = options.get(LOADING_SCOPE);
+      registerLoadingScope(options, scope);
+      try
+      {
+        result = loadDataGraph(inputStream, options);
+      }
+      finally
+      {
+        options.put(LOADING_SCOPE, restore);
+      }
+    } else {
+      registerLoadingScope(options, scope);
+      try
+      {
+        result = loadDataGraph(inputStream, options);
+      }
+      finally
+      {
+        options.remove(LOADING_SCOPE);
+      }
+    }
+    return result;
+  }
+  
+  public void saveDataGraph(DataGraph dataGraph, OutputStream outputStream, Map options) throws IOException
+  {
+    ((DataGraphImpl)dataGraph).getDataGraphResource().save(outputStream, options);
+  }
+  
+  public void registerDataGraphTypes(DataGraph dataGraph, List/*Type*/ types)
+  {
+    //if (types == null)
+    //  types = SDOUtil.getDataGraphTypes(dataGraph);
+    
+    Set/*EPackage*/ packages = new HashSet(); 
+    for (final Iterator iterator = types.iterator(); iterator.hasNext(); ) {
+      EClassifier type = (EClassifier)iterator.next();  
+      packages.add(type.getEPackage());
+    }
+
+    ResourceSet resourceSet = ((DataGraphImpl)dataGraph).getResourceSet();
+
+    for (Iterator iterator = packages.iterator(); iterator.hasNext(); ) {
+      EPackage typePackage = (EPackage)iterator.next();
+      Resource resource = typePackage.eResource();
+      if (resource == null) {
+        resource = resourceSet.createResource(URI.createURI(".ecore"));
+        resource.setURI(URI.createURI(typePackage.getNsURI()));
+        resource.getContents().add(typePackage);
+      }
+      else if (resource.getResourceSet() != resourceSet)
+        resourceSet.getResources().add(resource);
+    }
+  }
+  
+  public HelperContext createHelperContext(boolean extensibleNamespaces)
+  {
+    return new HelperContextImpl(extensibleNamespaces);
+  }
+  
+  public CopyHelper createCrossScopeCopyHelper(TypeHelper targetScope) 
+  {
+    return new CrossScopeCopyHelperImpl(targetScope); 
+  }
+  
+  public XMLStreamHelper createXMLStreamHelper(TypeHelper scope)
+  {
+    return new XMLStreamHelperImpl(scope);
+  }
+  
+  public List getTypes(TypeHelper scope, String uri) {
+
+      EPackage ePackage = ((TypeHelperImpl) scope).getExtendedMetaData().getPackage(uri);
+      if (ePackage != null) {
+        return new ArrayList(ePackage.getEClassifiers());
+      }
+      return null;
+  }
+  
+  public List getOpenContentProperties(DataObject dataObject)
+  {
+    List result = new UniqueEList();
+    ((ClassImpl)dataObject.getType()).addOpenProperties((EObject)dataObject, result);
+    return result;
+  }
+
+  public boolean isDocumentRoot(Type type)
+  {
+    return "".equals(SDOExtendedMetaData.INSTANCE.getName((EClassifier)type));
+  }
+  
+  public Type createType(TypeHelper scope, String uri, String name, boolean isDataType)
+  {
+    ExtendedMetaData extendedMetaData = ((TypeHelperImpl)scope).getExtendedMetaData();
+    if ("".equals(uri)) uri = null; //FB
+    
+    EPackage ePackage = extendedMetaData.getPackage(uri);
+    if (ePackage == null)
+    {
+      ePackage = EcoreFactory.eINSTANCE.createEPackage();
+      ePackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl());
+      ePackage.setNsURI(uri);
+      String packagePrefix = uri != null ? URI.createURI(uri).trimFileExtension().lastSegment() : ""; //FB
+      ePackage.setName(packagePrefix);
+      ePackage.setNsPrefix(packagePrefix);
+      extendedMetaData.putPackage(uri, ePackage);
+    }
+
+    EClassifier eClassifier = ePackage.getEClassifier(name);
+    if (eClassifier != null) // already defined?
+    {
+      //throw new IllegalArgumentException();
+      return null;
+    }
+    
+    if (name != null)
+    { 
+      eClassifier = isDataType ? (EClassifier)SDOFactory.eINSTANCE.createDataType() : (EClassifier)SDOFactory.eINSTANCE.createClass();
+      eClassifier.setName(name);
+    }
+    else
+    {
+      eClassifier = DataObjectUtil.createDocumentRoot();
+    }
+    
+    ePackage.getEClassifiers().add(eClassifier);
+
+    return (Type)eClassifier;
+  }
+  
+  public void addBaseType(Type type, Type baseType)
+  {
+    ((EClass)type).getESuperTypes().add(baseType);
+  }
+  
+  public void addAliasName(Type type, String aliasName)
+  {
+    throw new UnsupportedOperationException(); // TODO: implement this method properly
+    //type.getAliasNames().add(aliasName);
+  }
+  
+  public void setOpen(Type type, boolean isOpen)
+  {
+    if (isOpen == type.isOpen()) return;
+
+    if (isOpen)
+    {
+      EAttribute eAttribute = (EAttribute)SDOFactory.eINSTANCE.createAttribute();
+      ((EClass)type).getEStructuralFeatures().add(eAttribute);
+
+      eAttribute.setName("any");
+      eAttribute.setUnique(false);
+      eAttribute.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
+      eAttribute.setEType(EcorePackage.eINSTANCE.getEFeatureMapEntry());
+      ExtendedMetaData.INSTANCE.setFeatureKind(eAttribute, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE);
+      ExtendedMetaData.INSTANCE.setProcessingKind(eAttribute, ExtendedMetaData.LAX_PROCESSING);
+      ExtendedMetaData.INSTANCE.setWildcards(eAttribute, Collections.singletonList("##any"));
+      
+      //FB TBD Add an "anyAttribute" EAttribute as well.
+      
+      if (type.isSequenced()) {
+        eAttribute.setDerived(true);
+        eAttribute.setTransient(true);
+        eAttribute.setVolatile(true);
+      }
+    }
+    else
+    {
+      EClass eClass = (EClass)type;
+      EAttribute any = (EAttribute)eClass.getEStructuralFeature("any");
+      eClass.getEStructuralFeatures().remove(any);  
+    }
+  }
+  
+  public void setSequenced(Type type, boolean isSequenced)
+  {
+    if (isSequenced == type.isSequenced()) return;
+    
+    // currently, we require setSequenced to be called first, before anything else is added to the type.
+    if (type.isDataType() || !type.getProperties().isEmpty())
+    {
+      if (type.getName() != "DocumentRoot") // document root is a special case
+        throw new IllegalArgumentException();
+    }
+    
+    if (isSequenced) {
+      EClass eClass = (EClass)type;
+      ExtendedMetaData.INSTANCE.setContentKind(eClass, ExtendedMetaData.MIXED_CONTENT);
+      EAttribute mixedFeature = (EAttribute)SDOFactory.eINSTANCE.createAttribute();
+      mixedFeature.setName("mixed");
+      mixedFeature.setUnique(false);
+      mixedFeature.setEType(EcorePackage.eINSTANCE.getEFeatureMapEntry());
+      mixedFeature.setLowerBound(0);
+      mixedFeature.setUpperBound(-1);
+      //eClass.getEStructuralFeatures().add(mixedFeature);
+      ((ClassImpl)eClass).setSequenceFeature(mixedFeature);
+      ExtendedMetaData.INSTANCE.setFeatureKind(mixedFeature, ExtendedMetaData.ELEMENT_WILDCARD_FEATURE);
+      ExtendedMetaData.INSTANCE.setName(mixedFeature, ":mixed"); 
+    }
+    else
+    {
+      // nothing to do, because of current restriction that setSequence must be called first.
+    }
+  }
+  
+  public void setAbstract(Type type, boolean isAbstract)
+  {
+    ((EClass)type).setAbstract(isAbstract);
+  }
+  
+  public void setJavaClassName(Type type, String javaClassName)
+  {
+    ((EClassifier)type).setInstanceClassName(javaClassName);
+  }
+  
+  public Property createProperty(Type containingType, String name, Type propertyType)
+  {
+    EStructuralFeature eStructuralFeature = 
+      propertyType.isDataType() ? 
+        (EStructuralFeature)SDOFactory.eINSTANCE.createAttribute() :
+        (EStructuralFeature)SDOFactory.eINSTANCE.createReference();
+
+    eStructuralFeature.setName(name);
+    eStructuralFeature.setEType((EClassifier)propertyType);
+    ((EClass)containingType).getEStructuralFeatures().add(eStructuralFeature);
+
+    if ("".equals(ExtendedMetaData.INSTANCE.getName((EClass)containingType))) // DocumentRoot containingType?
+    {
+      ExtendedMetaData.INSTANCE.setNamespace(eStructuralFeature, containingType.getURI());
+      //FB???eStructuralFeature.setUnique(false);
+      //FB???eStructuralFeature.setUpperBound(ETypedElement.UNSPECIFIED_MULTIPLICITY);
+    }
+    
+    if (containingType.isSequenced()) {
+      eStructuralFeature.setDerived(true);
+      eStructuralFeature.setTransient(true);
+      eStructuralFeature.setVolatile(true);
+      ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE);
+    }
+    else
+    {
+      //FB TBD ... figure out how to decide whether to use ELEMENT_FEATURE or ATTRIBUTE_FEATURE
+      //ExtendedMetaData.INSTANCE.setFeatureKind(eStructuralFeature, ExtendedMetaData.ELEMENT_FEATURE);
+    }
+    
+    return (Property)eStructuralFeature;
+  }
+  
+  public Property createOpenContentProperty(TypeHelper scope, String uri, String name, Type type)
+  {
+    ExtendedMetaData extendedMetaData = ((TypeHelperImpl)scope).getExtendedMetaData();
+
+    // get/create document root
+    EPackage ePackage = extendedMetaData.getPackage(uri);
+    Type documentRoot = ePackage != null ? (Type)extendedMetaData.getType(ePackage, "") : null;
+    if (documentRoot == null) 
+    {
+      documentRoot = createType(scope, uri, null, false);
+    }
+
+    // Determine if property already exists
+    Property newProperty = documentRoot.getProperty(name);
+    if (newProperty == null)
+    {
+      // Create the new property 'under' the document root.....
+      newProperty = createProperty(documentRoot, name, type);
+    }
+    else
+    {
+      // if property already exists, validate the expected type
+      if (!newProperty.getType().equals(type))
+        throw new IllegalArgumentException();
+    }
+    return newProperty;
+  }
+  
+  public void addAliasName(Property property, String aliasName)
+  {
+    throw new UnsupportedOperationException(); // TODO: implement this method properly
+    //property.getAliasNames().add(aliasName);
+  }
+ 
+  public void setMany(Property property, boolean isMany)
+  {
+    ((EStructuralFeature)property).setUpperBound(isMany ? EStructuralFeature.UNBOUNDED_MULTIPLICITY : 1);
+  }
+  
+  public void setContainment(Property property, boolean isContainment)
+  {
+    ((EReference)property).setContainment(isContainment);
+  }
+
+  public void setDefault(Property property, String defaultValue)
+  {
+    ((EStructuralFeature)property).setDefaultValueLiteral(defaultValue);
+  }
+  
+  public void setReadOnly(Property property, boolean isReadOnly)
+  {
+    ((EStructuralFeature)property).setChangeable(!isReadOnly);
+  }
+  
+  public void setOpposite(Property property, Property opposite)
+  {
+    ((EReference)property).setEOpposite((EReference)opposite);
+  }
+  
+  public void addTypeInstanceProperty(Type definedType, Property instanceProperty, Object value)
+  {
+    addInstanceProperty((EModelElement)definedType, instanceProperty, value);
+  }
+
+  public void addPropertyInstanceProperty(Property definedProperty, Property instanceProperty, Object value)
+  {
+    addInstanceProperty((EModelElement)definedProperty, instanceProperty, value);
+  }
+  
+  protected void addInstanceProperty(EModelElement metaObject, Property property, Object value)
+  {
+    String uri = property.getContainingType().getURI();
+    EAnnotation eAnnotation = metaObject.getEAnnotation(uri);
+    if (eAnnotation == null)
+    {
+      eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
+      eAnnotation.setSource(uri);
+      metaObject.getEAnnotations().add(eAnnotation);
+    }
+    //TODO if (property.isMany()) ... // convert list of values
+    String stringValue = convertToString(property.getType(), value);
+    eAnnotation.getDetails().put(property.getName(), stringValue);
+  }
+  
+}

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLStreamHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLStreamHelper.java?view=diff&rev=537884&r1=537883&r2=537884
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLStreamHelper.java (original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/XMLStreamHelper.java Mon May 14 08:38:08 2007
@@ -19,94 +19,8 @@
  */
 package org.apache.tuscany.sdo.helper;
 
-import java.util.Map;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import commonj.sdo.DataObject;
-import commonj.sdo.helper.XMLDocument;
-
 /**
- * Helper interface for reading and writing SDO DataObjects from XML streams (StAX).
- *
- * @version $Rev$ $Date$
+ * @deprecated
  */
-public interface XMLStreamHelper {
-    /**
-     * Creates and returns an XMLDocument from an XML input stream.
-     * The reader must be positioned on a START_DOCUMENT event.
-     *
-     * @param reader the stream to read
-     * @return an XMLDocument created from the stream
-     * @throws XMLStreamException    if there was a problem reading the stream
-     * @throws IllegalStateException if the reader is not positioned on a START_DOCUMENT event
-     */
-    XMLDocument load(XMLStreamReader reader) throws XMLStreamException, IllegalStateException;
-
-    /**
-     * Save a XMLDocument to an XML stream.
-     *
-     * @param document the document to be written
-     * @param writer   the stream to write to
-     * @throws XMLStreamException if there was a problem writing to the stream
-     */
-    void save(XMLDocument document, XMLStreamWriter writer) throws XMLStreamException;
-
-    /**
-     * Creates and returns a XMLStreamReader that can be used to read an XMLDocument as a XML event stream.
-     * The reader will be positioned on a START_DOCUMENT event.
-     *
-     * @param document the XMLDocument to be read
-     * @return an XMLStreamReader that can be used to read the document
-     */
-    XMLStreamReader createXMLStreamReader(XMLDocument document) throws XMLStreamException;
-
-    /**
-     * Create a DataObject from an element in a XML stream.
-     * The reader must be positioned on a START_ELEMENT event.
-     *
-     * @param reader the stream to read
-     * @return a DataObject created from the element in the stream
-     * @throws XMLStreamException    if there was a problem reading the stream
-     * @throws IllegalStateException if the reader is not positioned on a START_ELEMENT event
-     */
-    DataObject loadObject(XMLStreamReader reader) throws XMLStreamException, IllegalStateException;
-
-    /**
-     * Default Type to load DataObject if the element is unqualified/local without xsi:type
-     * or the qualified/global element or xsi:type fail to resolve.
-     * Can be null.
-     */
-    String OPTION_DEFAULT_ROOT_TYPE = "default root type";
-    
-    /**
-     * Create a DataObject from an element in a XML stream.
-     * The reader must be positioned on a START_ELEMENT event.
-     *
-     * @param reader the stream to read
-     * @param options {@link OPTION_DEFAULT_ROOT_TYPE}; can be null or empty
-     * @return a DataObject created from the element in the stream
-     * @throws XMLStreamException    if there was a problem reading the stream
-     * @throws IllegalStateException if the reader is not positioned on a START_ELEMENT event
-     */
-    DataObject loadObject(XMLStreamReader reader, Map options) throws XMLStreamException, IllegalStateException;
-
-    /**
-     * Save a DataObject to an XML stream.
-     *
-     * @param sdo    the DataObject to be written
-     * @param writer the stream to write to
-     * @throws XMLStreamException if there was a problem writing to the stream
-     */
-    void saveObject(DataObject sdo, XMLStreamWriter writer) throws XMLStreamException;
-
-    /**
-     * Creates and returns a XMLStreamReader that can be used to read a DataObject as a XML event stream.
-     * The reader will be positioned on a START_ELEMENT event.
-     *
-     * @param sdo the DataObject to be read
-     * @return an XMLStreamReader that can be used to read the DataObject
-     */
-    XMLStreamReader createXMLStreamReader(DataObject sdo);
+public interface XMLStreamHelper extends org.apache.tuscany.sdo.api.XMLStreamHelper {
 }

Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/HelperProviderBase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/HelperProviderBase.java?view=auto&rev=537884
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/HelperProviderBase.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/HelperProviderBase.java Mon May 14 08:38:08 2007
@@ -0,0 +1,238 @@
+/**
+ *
+ *  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.sdo.rtlib.helper;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+import org.apache.tuscany.sdo.api.SDOHelper;
+import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.apache.tuscany.sdo.util.resource.SDOObjectInputStream;
+
+import commonj.sdo.DataGraph;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.DataHelper;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import commonj.sdo.impl.HelperProvider;
+import commonj.sdo.impl.ExternalizableDelegator.Resolvable;
+
+
+/**
+ * Create and manage all the default helpers
+ */
+public abstract class HelperProviderBase extends HelperProvider
+{
+  protected CopyHelper copyHelper;
+
+  protected DataFactory dataFactory;
+
+  protected DataHelper dataHelper;
+
+  protected EqualityHelper equalityHelper;
+
+  protected TypeHelper typeHelper;
+
+  protected XMLHelper xmlHelper;
+
+  protected XSDHelper xsdHelper;
+  
+  protected SDOHelper sdoHelper; // Tuscany extension APIs
+
+  /**
+   * Subclasses must implement this method to initialize the above Helper instance variables
+   */
+  protected abstract void createDefaultHelpers();
+  
+  public HelperProviderBase()
+  {
+    createDefaultHelpers();
+  }
+  
+  public SDOHelper sdoHelper()
+  {
+    return sdoHelper;
+  }
+
+  public CopyHelper copyHelper()
+  {
+    return copyHelper;
+  }
+
+  public DataFactory dataFactory()
+  {
+    return dataFactory;
+  }
+
+  public DataHelper dataHelper()
+  {
+    return dataHelper;
+  }
+
+  public EqualityHelper equalityHelper()
+  {
+    return equalityHelper;
+  }
+
+  public TypeHelper typeHelper()
+  {
+    return typeHelper;
+  }
+
+  public XMLHelper xmlHelper()
+  {
+    return xmlHelper;
+  }
+
+  public XSDHelper xsdHelper()
+  {
+    return xsdHelper;
+  }
+
+  public Resolvable resolvable()
+  {
+    return new ResolvableImpl();
+  }
+
+  public Resolvable resolvable(Object target)
+  {
+    return new ResolvableImpl(target);
+  }
+
+  protected class ResolvableImpl implements Resolvable
+  {
+    protected Object target;
+    
+    public ResolvableImpl(Object target) { this.target = target; }
+    
+    public ResolvableImpl() { this.target = null; }
+
+    public void writeExternal(ObjectOutput out) throws IOException
+    {
+      if (target instanceof DataObject)
+      {
+        writeDataObject((DataObject)target, out);
+      }
+      else
+      {
+        throw new NotSerializableException(); // should never happen
+      }
+    }
+
+    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+    {
+      target = readDataObject(in);
+    }
+
+    public Object readResolve() throws ObjectStreamException
+    {
+      return target;
+    }
+    
+    protected void writeDataObject(DataObject dataObject, ObjectOutput objectOutput) throws IOException
+    {
+      DataGraph dataGraph = dataObject.getDataGraph();
+      if (dataGraph != null)
+      {
+        objectOutput.writeByte(0);
+        objectOutput.writeUTF(DataObjectUtil.getXPath(dataObject));
+        objectOutput.writeObject(dataGraph);
+      }
+      else if (dataObject.getContainer() != null)
+      {
+        objectOutput.writeByte(0);
+        objectOutput.writeUTF(DataObjectUtil.getXPath(dataObject));
+        objectOutput.writeObject(dataObject.getRootObject());
+      }
+      else
+      {
+        // Root object
+        objectOutput.writeByte(1);
+
+        ByteArrayOutputStream compressedByteArrayOutputStream = new ByteArrayOutputStream();
+        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(compressedByteArrayOutputStream);
+        XMLHelper xmlHelperLocal = xmlHelper;
+        if(objectOutput instanceof SDOObjectInputStream)
+        {
+            xmlHelperLocal = ((SDOObjectInputStream)objectOutput).getHelperContext().getXMLHelper();
+        }
+        xmlHelperLocal.save(dataObject, "commonj.sdo", "dataObject", gzipOutputStream);
+        gzipOutputStream.close(); // Flush the contents
+
+        byte[] byteArray = compressedByteArrayOutputStream.toByteArray();
+        objectOutput.writeInt(byteArray.length);
+        objectOutput.write(byteArray);
+      }
+    }
+
+    protected DataObject readDataObject(ObjectInput objectInput) throws IOException, ClassNotFoundException
+    {
+      boolean isRoot = objectInput.readByte() == 1;
+      if (isRoot)
+      {
+        // Root object: [rootXML] = length + XML contents
+        int length = objectInput.readInt();
+        byte[] compressedBytes = new byte [length];
+
+        int index = 0;
+        int bytesRead;
+        while (index < length) {
+            if ((bytesRead = objectInput.read(compressedBytes, index, length-index)) == -1) {
+                break;
+            }
+            index += bytesRead;
+        }
+        
+        GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressedBytes));
+        XMLHelper xmlHelperLocal = xmlHelper;
+        if(objectInput instanceof SDOObjectInputStream)
+        {
+            xmlHelperLocal = ((SDOObjectInputStream)objectInput).getHelperContext().getXMLHelper();
+        }
+        XMLDocument doc = xmlHelperLocal.load(gzipInputStream);
+        gzipInputStream.close();
+
+        return doc.getRootObject();
+      }
+      else
+      {
+        // Non root object: [path] [root]
+        String xpath = objectInput.readUTF();
+        Object object = objectInput.readObject();
+        
+        DataObject root = object instanceof DataGraph ? ((DataGraph)object).getRootObject() : (DataObject)object;
+        return xpath.equals("") ? root : root.getDataObject(xpath);
+      }
+    }
+  }
+  
+}

Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/SDOHelperBase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/SDOHelperBase.java?view=auto&rev=537884
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/SDOHelperBase.java (added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/rtlib/helper/SDOHelperBase.java Mon May 14 08:38:08 2007
@@ -0,0 +1,141 @@
+/**
+ *
+ *  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.sdo.rtlib.helper;
+
+/**
+ * Base class for an implementation of the SDOHelper and SDOHelper.MetaDataBuilder interfaces.
+ */
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sdo.api.SDOHelper;
+import org.apache.tuscany.sdo.util.resource.SDOObjectInputStream;
+import org.apache.tuscany.sdo.util.resource.SDOObjectOutputStream;
+
+import commonj.sdo.helper.HelperContext;
+
+public abstract class SDOHelperBase implements SDOHelper, SDOHelper.MetaDataBuilder
+{
+  public HelperContext createHelperContext()
+  {
+    return createHelperContext(false);
+  }
+  
+  public ObjectInputStream createObjectInputStream(InputStream inputStream, HelperContext helperContext) throws IOException
+  {
+    return new SDOObjectInputStream(inputStream, helperContext);
+  }
+  
+  public ObjectOutputStream createObjectOutputStream(OutputStream outputStream, HelperContext helperContext) throws IOException
+  {
+    return new SDOObjectOutputStream(outputStream, helperContext);
+  }
+  
+  public MetaDataBuilder getMetaDataBuilder()
+  {
+    return this;
+  }
+  
+  //Java instance class to SDO mappings (section 8.1 of the SDO spec)
+  protected static Map javaToSdoMappings = new HashMap();
+  static {
+    javaToSdoMappings.put(boolean.class, "Boolean");
+    javaToSdoMappings.put(byte.class, "Byte");
+    javaToSdoMappings.put(char.class, "Character");
+    javaToSdoMappings.put(Date.class, "Date");
+    javaToSdoMappings.put(BigDecimal.class, "Decimal");
+    javaToSdoMappings.put(double.class, "Double");
+    javaToSdoMappings.put(float.class, "Float");
+    javaToSdoMappings.put(int.class, "Int");
+    javaToSdoMappings.put(BigInteger.class, "Integer");
+    javaToSdoMappings.put(long.class, "Long");
+    javaToSdoMappings.put(Object.class, "Object");
+    javaToSdoMappings.put(short.class, "Short");
+    javaToSdoMappings.put(String.class, "String");
+    javaToSdoMappings.put(Boolean.class, "BooleanObject");
+    javaToSdoMappings.put(Byte.class, "ByteObject");
+    javaToSdoMappings.put(Character.class, "CharacterObject");
+    javaToSdoMappings.put(Double.class, "DoubleObject");
+    javaToSdoMappings.put(Float.class, "FloatObject");
+    javaToSdoMappings.put(Integer.class, "IntObject");
+    javaToSdoMappings.put(Long.class, "LongObject");
+    javaToSdoMappings.put(Short.class, "ShortObject");
+  }
+
+  //XSD to SDO mappings (section 9.4 of the SDO spec)
+  protected static Map xsdToSdoMappings = new HashMap();
+  static {
+    xsdToSdoMappings.put("anySimpleType", "Object");
+    xsdToSdoMappings.put("anyType", "DataObject");
+    xsdToSdoMappings.put("anyURI", "URI");
+    xsdToSdoMappings.put("base64Binary", "Bytes");
+    xsdToSdoMappings.put("boolean", "Boolean");
+    xsdToSdoMappings.put("byte", "Byte");
+    xsdToSdoMappings.put("date", "YearMonthDay");
+    xsdToSdoMappings.put("dateTime", "DateTime");
+    xsdToSdoMappings.put("decimal", "Decimal");
+    xsdToSdoMappings.put("double", "Double");
+    xsdToSdoMappings.put("duration", "Duration");
+    xsdToSdoMappings.put("ENTITIES", "Strings");
+    xsdToSdoMappings.put("ENTITY", "String");
+    xsdToSdoMappings.put("float", "Float");
+    xsdToSdoMappings.put("gDay", "Day");
+    xsdToSdoMappings.put("gMonth", "Month");
+    xsdToSdoMappings.put("gMonthDay", "MonthDay");
+    xsdToSdoMappings.put("gYear", "Year");
+    xsdToSdoMappings.put("gYearMonth", "YearMonth");
+    xsdToSdoMappings.put("hexBinary", "Bytes");
+    xsdToSdoMappings.put("ID","String");
+    xsdToSdoMappings.put("IDREF","String");
+    xsdToSdoMappings.put("IDREFS","Strings");
+    xsdToSdoMappings.put("int","Int");
+    xsdToSdoMappings.put("integer","Integer");
+    xsdToSdoMappings.put("language","String");
+    xsdToSdoMappings.put("long","Long");
+    xsdToSdoMappings.put("Name","String");
+    xsdToSdoMappings.put("NCName","String");
+    xsdToSdoMappings.put("negativeInteger","Integer");
+    xsdToSdoMappings.put("NMTOKEN","String");
+    xsdToSdoMappings.put("NMTOKENS","Strings");
+    xsdToSdoMappings.put("nonNegativeInteger","Integer");
+    xsdToSdoMappings.put("nonPositiveInteger","Integer");
+    xsdToSdoMappings.put("normalizedString","String");
+    xsdToSdoMappings.put("NOTATION","String");
+    xsdToSdoMappings.put("positiveInteger","Integer");
+    xsdToSdoMappings.put("QName","URI");
+    xsdToSdoMappings.put("short","Short");
+    xsdToSdoMappings.put("string","String");
+    xsdToSdoMappings.put("time","Time");
+    xsdToSdoMappings.put("token","String");
+    xsdToSdoMappings.put("unsignedByte","Short");
+    xsdToSdoMappings.put("unsignedInt","Long");
+    xsdToSdoMappings.put("unsignedLong","Integer");
+    xsdToSdoMappings.put("unsignedShort","Int");
+  }
+  
+}



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