You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ke...@apache.org on 2007/07/11 16:16:55 UTC

svn commit: r555279 [2/2] - in /incubator/tuscany/branches/sdo-1.0-incubating: impl/src/main/java/org/apache/tuscany/sdo/helper/ impl/src/main/java/org/apache/tuscany/sdo/util/ impl/src/main/java/org/apache/tuscany/sdo/util/resource/ impl/src/test/java...

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/helper/XSDHelperImpl.java Wed Jul 11 07:16:50 2007
@@ -19,7 +19,6 @@
  */
 package org.apache.tuscany.sdo.helper;
 
-
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.Reader;
@@ -60,296 +59,269 @@
 
 import commonj.sdo.Property;
 import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
 import commonj.sdo.helper.TypeHelper;
 import commonj.sdo.helper.XSDHelper;
 
-
 /**
- * Provides access to additional information when the 
- * Type or Property is defined by an XML Schema (XSD).
- * Methods return null/false otherwise or if the information is unavailable.
- * Defines Types from an XSD.
+ * Provides access to additional information when the Type or Property is
+ * defined by an XML Schema (XSD). Methods return null/false otherwise or if the
+ * information is unavailable. Defines Types from an XSD.
  */
-public class XSDHelperImpl implements XSDHelper
-{
-  protected boolean extensibleNamespaces = false;
-  protected ExtendedMetaData extendedMetaData;
-  protected SDOXSDEcoreBuilder nondelegatingEcoreBuilder = null;
-  protected HashMap tcclToEcoreBuilderMap = null;
-  
-  public XSDHelperImpl(ExtendedMetaData extendedMetaData, String redefineBuiltIn, boolean extensibleNamespaces)
-  {
-    this.extendedMetaData = extendedMetaData;
-    this.extensibleNamespaces = extensibleNamespaces;
-    
-    SDOXSDEcoreBuilder ecoreBuilder = createEcoreBuilder();
-    
-    if (extendedMetaData instanceof SDOExtendedMetaDataImpl &&
-        ((SDOExtendedMetaDataImpl)extendedMetaData).getRegistry() instanceof EPackageRegistryImpl.Delegator) {
-      tcclToEcoreBuilderMap = new HashMap();
-      putTCCLEcoreBuilder(ecoreBuilder);
+public class XSDHelperImpl implements XSDHelper {
+    protected boolean extensibleNamespaces = false;
+    protected HelperContext helperContext;
+    protected SDOXSDEcoreBuilder nondelegatingEcoreBuilder = null;
+    protected HashMap tcclToEcoreBuilderMap = null;
+    private ExtendedMetaData extendedMetaData;
+
+    public XSDHelperImpl(HelperContext hc, String redefineBuiltIn, boolean extensibleNamespaces) {
+        this.helperContext = hc;
+        this.extensibleNamespaces = extensibleNamespaces;
+        extendedMetaData = ((HelperContextImpl)helperContext).extendedMetaData;
+
+        SDOXSDEcoreBuilder ecoreBuilder = createEcoreBuilder();
+
+        if (extendedMetaData instanceof SDOExtendedMetaDataImpl && ((SDOExtendedMetaDataImpl)extendedMetaData)
+            .getRegistry() instanceof EPackageRegistryImpl.Delegator) {
+            tcclToEcoreBuilderMap = new HashMap();
+            putTCCLEcoreBuilder(ecoreBuilder);
+        } else {
+            nondelegatingEcoreBuilder = ecoreBuilder;
+        }
+
+        if (redefineBuiltIn != null) { // Redefining/regenerating this built-in
+                                        // model
+            ecoreBuilder.getTargetNamespaceToEPackageMap().remove(redefineBuiltIn);
+        }
     }
-    else {
-      nondelegatingEcoreBuilder = ecoreBuilder;
+
+    public XSDHelperImpl(HelperContext hc) {
+        this(hc, null, false);
     }
-    
-    if (redefineBuiltIn != null) { // Redefining/regenerating this built-in model
-      ecoreBuilder.getTargetNamespaceToEPackageMap().remove(redefineBuiltIn);
+
+    /**
+     * Redefine/regenerating the built-in model
+     * @param redefineBuiltIn
+     */
+    public void setRedefineBuiltIn(String redefineBuiltIn) {
+        if (redefineBuiltIn != null) {
+            getEcoreBuilder().getTargetNamespaceToEPackageMap().remove(redefineBuiltIn);
+        }
     }
-  }
-  
-  public XSDHelperImpl(ExtendedMetaData extendedMetaData, String redefineBuiltIn)
-  {
-    this(extendedMetaData, redefineBuiltIn, false);
-  }
-  
-  public XSDHelperImpl(TypeHelper typeHelper, boolean extensibleNamespaces)
-  {
-    this(((TypeHelperImpl)typeHelper).extendedMetaData, null, extensibleNamespaces);
-  }
-  
-  protected SDOXSDEcoreBuilder createEcoreBuilder() {
-    SDOXSDEcoreBuilder ecoreBuilder = new SDOXSDEcoreBuilder(extendedMetaData, extensibleNamespaces);
     
-    // Add the built-in models to the targetNamespaceToEPackageMap so they can't be (re)defined/overridden
-    for (Iterator iter = TypeHelperImpl.getBuiltInModels().iterator(); iter.hasNext(); ) {
-      EPackage ePackage = (EPackage)iter.next();
-      ecoreBuilder.getTargetNamespaceToEPackageMap().put(ePackage.getNsURI(), ePackage);
+    public void setExtensibleNamespaces(boolean extensibleNamespaces) {
+        this.extensibleNamespaces = extensibleNamespaces;
     }
-    
-    return ecoreBuilder;
-  }
-  
-  protected void putTCCLEcoreBuilder(XSDEcoreBuilder ecoreBuilder) {
-    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-    if (tcclToEcoreBuilderMap.get(tccl) == null) {
-        tcclToEcoreBuilderMap.put(tccl, ecoreBuilder);
-    }
-  }
-  
-  protected SDOXSDEcoreBuilder getEcoreBuilder() {
-    if (nondelegatingEcoreBuilder != null) 
-      return nondelegatingEcoreBuilder;
-    
-    SDOXSDEcoreBuilder result = null;
-    try {
-      for (ClassLoader tccl = Thread.currentThread().getContextClassLoader(); tccl != null; tccl = tccl.getParent()) {
-        result = (SDOXSDEcoreBuilder)tcclToEcoreBuilderMap.get(tccl);
-        if (result != null)
-          return result;
-      } // for
+
+    protected SDOXSDEcoreBuilder createEcoreBuilder() {
+        SDOXSDEcoreBuilder ecoreBuilder = new SDOXSDEcoreBuilder(extendedMetaData, extensibleNamespaces);
+
+        // Add the built-in models to the targetNamespaceToEPackageMap so they
+        // can't be (re)defined/overridden
+        for (Iterator iter = TypeHelperImpl.getBuiltInModels().iterator(); iter.hasNext();) {
+            EPackage ePackage = (EPackage)iter.next();
+            ecoreBuilder.getTargetNamespaceToEPackageMap().put(ePackage.getNsURI(), ePackage);
+        }
+
+        return ecoreBuilder;
     }
-    catch (SecurityException exception) {
-      //exception.printStackTrace();
+
+    protected void putTCCLEcoreBuilder(XSDEcoreBuilder ecoreBuilder) {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        if (tcclToEcoreBuilderMap.get(tccl) == null) {
+            tcclToEcoreBuilderMap.put(tccl, ecoreBuilder);
+        }
     }
 
-    result = createEcoreBuilder();
-    putTCCLEcoreBuilder(result);
-    
-    return result;
-  }
-  
-  public String getLocalName(Type type)
-  {
-    return extendedMetaData.getName((EClassifier)type);
-  }
-
-  public String getLocalName(Property property)
-  {
-    return extendedMetaData.getName((EStructuralFeature)property);
-  }
-
-  public String getNamespaceURI(Property property)
-  {
-    return extendedMetaData.getNamespace((EStructuralFeature)property);
-  }
-
-  public boolean isAttribute(Property property)
-  {
-    return extendedMetaData.getFeatureKind((EStructuralFeature)property) == ExtendedMetaData.ATTRIBUTE_FEATURE;
-  }
-
-  public boolean isElement(Property property)
-  {
-    return extendedMetaData.getFeatureKind((EStructuralFeature)property) == ExtendedMetaData.ELEMENT_FEATURE;
-  }
-
-  public boolean isMixed(Type type)
-  {
-    if (type instanceof EClass)
-    {
-      return extendedMetaData.getContentKind((EClass)type) == ExtendedMetaData.MIXED_CONTENT;
-    }
-    else
-    {
-      return false;
-    }
-  }
-
-  public boolean isXSD(Type type)
-  {
-    return ((EModelElement)type).getEAnnotation(ExtendedMetaData.ANNOTATION_URI) != null;
-  }
-
-  public Property getGlobalProperty(String uri, String propertyName, boolean isElement)
-  {
-    if (isElement)
-    {
-      return (Property)extendedMetaData.getElement(uri, propertyName);
-    }
-    else
-    {
-      return (Property)extendedMetaData.getAttribute(uri, propertyName);
-    }
-  }
-
-  public String getAppinfo(Type type, String source)
-  {
-    return getAppinfo((EModelElement)type, source);
-  }
-
-  public String getAppinfo(Property property, String source)
-  {
-    return getAppinfo((EModelElement)property, source);
-  }
-
-  protected String getAppinfo(EModelElement eModelElement, String source)
-  {
-    return (String)eModelElement.getEAnnotation(source).getDetails().get("appinfo");
-  }
-
-  public List /*Type*/define(String xsd)
-  {
-    InputStream inputStream = new ByteArrayInputStream(xsd.getBytes());
-    return define(inputStream, "*.xsd");
-  }
-
-  public List /*Type*/define(Reader xsdReader, String schemaLocation)
-  {
-    InputSource inputSource = new InputSource(xsdReader);
-    return define(inputSource, schemaLocation);
-
-  }
-
-  public List /*Type*/define(InputStream xsdInputStream, String schemaLocation)
-  {
-    InputSource inputSource = new InputSource(xsdInputStream);
-    return define(inputSource, schemaLocation);
-  }
-
-  protected List /*Type*/define(InputSource inputSource, String schemaLocation)
-  {
-    try
-    {
-      SDOXSDEcoreBuilder ecoreBuilder = getEcoreBuilder();
-      ResourceSet resourceSet = ecoreBuilder.createResourceSet();
-      Resource model = resourceSet.createResource(URI.createURI(schemaLocation != null ? schemaLocation : "null.xsd"));
-      ((XSDResourceImpl)model).load(inputSource, null);
-      
-      List newTypes = new ArrayList();
-      for (Iterator schemaIter = model.getContents().iterator(); schemaIter.hasNext(); )
-      {
-        XSDSchema schema = (XSDSchema)schemaIter.next();    
-
-        String targetNamespace = schema.getTargetNamespace();
-		    EPackage ePackage = extendedMetaData.getPackage(targetNamespace);
-        if (extensibleNamespaces || ePackage == null || TypeHelperImpl.getBuiltInModels().contains(ePackage))
-        {
-          Map targetNamespaceToEPackageMap = ecoreBuilder.getTargetNamespaceToEPackageMap();
-          targetNamespaceToEPackageMap.remove(targetNamespace);
-          
-          Collection originalEPackages = new HashSet(targetNamespaceToEPackageMap.values());
-          ecoreBuilder.generate(schema);
-          Collection newEPackages = ecoreBuilder.getTargetNamespaceToEPackageMap().values();
-      
-          for (Iterator iter = newEPackages.iterator(); iter.hasNext();)
-          {
-            EPackage currentPackage = (EPackage)iter.next();
-            if (!originalEPackages.contains(currentPackage))
-            {
-              currentPackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl());
-              EcoreUtil.freeze(currentPackage);
-              newTypes.addAll(currentPackage.getEClassifiers());
+    protected SDOXSDEcoreBuilder getEcoreBuilder() {
+        if (nondelegatingEcoreBuilder != null)
+            return nondelegatingEcoreBuilder;
+
+        SDOXSDEcoreBuilder result = null;
+        try {
+            for (ClassLoader tccl = Thread.currentThread().getContextClassLoader(); tccl != null; tccl =
+                tccl.getParent()) {
+                result = (SDOXSDEcoreBuilder)tcclToEcoreBuilderMap.get(tccl);
+                if (result != null)
+                    return result;
+            } // for
+        } catch (SecurityException exception) {
+            // exception.printStackTrace();
+        }
+
+        result = createEcoreBuilder();
+        putTCCLEcoreBuilder(result);
+
+        return result;
+    }
+
+    public String getLocalName(Type type) {
+        return extendedMetaData.getName((EClassifier)type);
+    }
+
+    public String getLocalName(Property property) {
+        return extendedMetaData.getName((EStructuralFeature)property);
+    }
+
+    public String getNamespaceURI(Property property) {
+        return extendedMetaData.getNamespace((EStructuralFeature)property);
+    }
+
+    public boolean isAttribute(Property property) {
+        return extendedMetaData.getFeatureKind((EStructuralFeature)property) == ExtendedMetaData.ATTRIBUTE_FEATURE;
+    }
+
+    public boolean isElement(Property property) {
+        return extendedMetaData.getFeatureKind((EStructuralFeature)property) == ExtendedMetaData.ELEMENT_FEATURE;
+    }
+
+    public boolean isMixed(Type type) {
+        if (type instanceof EClass) {
+            return extendedMetaData.getContentKind((EClass)type) == ExtendedMetaData.MIXED_CONTENT;
+        } else {
+            return false;
+        }
+    }
+
+    public boolean isXSD(Type type) {
+        return ((EModelElement)type).getEAnnotation(ExtendedMetaData.ANNOTATION_URI) != null;
+    }
+
+    public Property getGlobalProperty(String uri, String propertyName, boolean isElement) {
+        if (isElement) {
+            return (Property)extendedMetaData.getElement(uri, propertyName);
+        } else {
+            return (Property)extendedMetaData.getAttribute(uri, propertyName);
+        }
+    }
+
+    public String getAppinfo(Type type, String source) {
+        return getAppinfo((EModelElement)type, source);
+    }
+
+    public String getAppinfo(Property property, String source) {
+        return getAppinfo((EModelElement)property, source);
+    }
+
+    protected String getAppinfo(EModelElement eModelElement, String source) {
+        return (String)eModelElement.getEAnnotation(source).getDetails().get("appinfo");
+    }
+
+    public List /* Type */define(String xsd) {
+        InputStream inputStream = new ByteArrayInputStream(xsd.getBytes());
+        return define(inputStream, "*.xsd");
+    }
+
+    public List /* Type */define(Reader xsdReader, String schemaLocation) {
+        InputSource inputSource = new InputSource(xsdReader);
+        return define(inputSource, schemaLocation);
+
+    }
+
+    public List /* Type */define(InputStream xsdInputStream, String schemaLocation) {
+        InputSource inputSource = new InputSource(xsdInputStream);
+        return define(inputSource, schemaLocation);
+    }
+
+    protected List /* Type */define(InputSource inputSource, String schemaLocation) {
+        try {
+            SDOXSDEcoreBuilder ecoreBuilder = getEcoreBuilder();
+            ResourceSet resourceSet = ecoreBuilder.createResourceSet();
+            Resource model =
+                resourceSet.createResource(URI.createURI(schemaLocation != null ? schemaLocation : "null.xsd"));
+            ((XSDResourceImpl)model).load(inputSource, null);
+
+            List newTypes = new ArrayList();
+            for (Iterator schemaIter = model.getContents().iterator(); schemaIter.hasNext();) {
+                XSDSchema schema = (XSDSchema)schemaIter.next();
+
+                String targetNamespace = schema.getTargetNamespace();
+                EPackage ePackage = extendedMetaData.getPackage(targetNamespace);
+                if (extensibleNamespaces || ePackage == null || TypeHelperImpl.getBuiltInModels().contains(ePackage)) {
+                    Map targetNamespaceToEPackageMap = ecoreBuilder.getTargetNamespaceToEPackageMap();
+                    targetNamespaceToEPackageMap.remove(targetNamespace);
+
+                    Collection originalEPackages = new HashSet(targetNamespaceToEPackageMap.values());
+                    ecoreBuilder.generate(schema);
+                    Collection newEPackages = ecoreBuilder.getTargetNamespaceToEPackageMap().values();
+
+                    for (Iterator iter = newEPackages.iterator(); iter.hasNext();) {
+                        EPackage currentPackage = (EPackage)iter.next();
+                        if (!originalEPackages.contains(currentPackage)) {
+                            currentPackage.setEFactoryInstance(new DynamicDataObjectImpl.FactoryImpl());
+                            EcoreUtil.freeze(currentPackage);
+                            newTypes.addAll(currentPackage.getEClassifiers());
+                        }
+                    }
+                }
             }
-          }
+
+            return newTypes;
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new IllegalArgumentException(e.getMessage());
         }
-      }
-      
-      return newTypes;
-    }
-    catch (Exception e)
-    {
-      e.printStackTrace();
-      throw new IllegalArgumentException(e.getMessage());
-    }
-  }
-
-  public String generate(List /*Type*/types) throws IllegalArgumentException
-  {
-    return generate(types, new Hashtable());
-  }
-
-  public String generate(List /*Type*/types, Map /*String, String*/namespaceToSchemaLocation) throws IllegalArgumentException
-  {
-      if ( types != null && !types.isEmpty() )
-      {
-         Hashtable schemaMap = new Hashtable();
-         Hashtable nsPrefixMap = new Hashtable();
-         TypeTable typeTable = new TypeTable();
-         
-         SchemaBuilder schemaBuilder = new SchemaBuilder( schemaMap,
-                                                          nsPrefixMap,
-                                                          typeTable,
-                                                          namespaceToSchemaLocation);
-          
-         Iterator iterator = types.iterator();
-         Type dataType = null;
-         
-         try
-         {
-             while ( iterator.hasNext() )
-             {
-                 dataType = (Type)iterator.next();
-                 schemaBuilder.buildSchema(dataType);
-             }
-             
-             XSDSchema xmlSchema = null;
-             iterator = schemaMap.values().iterator();
-             StringWriter writer = new StringWriter();
-             
-             TransformerFactory transformerFactory = TransformerFactory.newInstance();
-             Transformer transformer = transformerFactory.newTransformer();
-             transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-             transformer.setOutputProperty(OutputKeys.METHOD, "xml");
-             transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
-             
-             while ( iterator.hasNext() )
-             {
-                 xmlSchema = (XSDSchema)iterator.next();
-
-                 if(xmlSchema.getElement() == null)
-                 {
-                     xmlSchema.updateElement();
-                 }
-
-                 transformer.transform(new DOMSource(xmlSchema.getElement().getOwnerDocument()), 
-                         new StreamResult(writer));
-             }
-             writer.close();
-             return writer.getBuffer().toString();
-         }
-         catch ( Exception e )
-         {
-             //System.out.println("Unable to generate schema due to ..." + e);
-             //e.printStackTrace();
-             throw new IllegalArgumentException(e.getMessage());
-         }
-      }
-      else
-      {
-          //System.out.println("No SDO Types to generate schema ...");
-          return "";
-      }
-  }
+    }
+
+    public String generate(List /* Type */types) throws IllegalArgumentException {
+        return generate(types, new Hashtable());
+    }
+
+    public String generate(List /* Type */types, Map /* String, String */namespaceToSchemaLocation)
+        throws IllegalArgumentException {
+        if (types != null && !types.isEmpty()) {
+            Hashtable schemaMap = new Hashtable();
+            Hashtable nsPrefixMap = new Hashtable();
+            TypeTable typeTable = new TypeTable();
+
+            SchemaBuilder schemaBuilder =
+                new SchemaBuilder(schemaMap, nsPrefixMap, typeTable, namespaceToSchemaLocation);
+
+            Iterator iterator = types.iterator();
+            Type dataType = null;
+
+            try {
+                while (iterator.hasNext()) {
+                    dataType = (Type)iterator.next();
+                    schemaBuilder.buildSchema(dataType);
+                }
+
+                XSDSchema xmlSchema = null;
+                iterator = schemaMap.values().iterator();
+                StringWriter writer = new StringWriter();
+
+                TransformerFactory transformerFactory = TransformerFactory.newInstance();
+                Transformer transformer = transformerFactory.newTransformer();
+                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+                transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+                transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+
+                while (iterator.hasNext()) {
+                    xmlSchema = (XSDSchema)iterator.next();
+
+                    if (xmlSchema.getElement() == null) {
+                        xmlSchema.updateElement();
+                    }
+
+                    transformer.transform(new DOMSource(xmlSchema.getElement().getOwnerDocument()),
+                                          new StreamResult(writer));
+                }
+                writer.close();
+                return writer.getBuffer().toString();
+            } catch (Exception e) {
+                // System.out.println("Unable to generate schema due to ..." +
+                // e);
+                // e.printStackTrace();
+                throw new IllegalArgumentException(e.getMessage());
+            }
+        } else {
+            // System.out.println("No SDO Types to generate schema ...");
+            return "";
+        }
+    }
 
+    public HelperContext getHelperContext() {
+        return helperContext;
+    }
 }

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/SDOUtil.java Wed Jul 11 07:16:50 2007
@@ -33,6 +33,7 @@
 
 import org.apache.tuscany.sdo.api.SDOHelper.XMLOptions;
 import org.apache.tuscany.sdo.helper.DataFactoryImpl;
+import org.apache.tuscany.sdo.helper.HelperContextImpl;
 import org.apache.tuscany.sdo.helper.SDOExtendedMetaDataImpl;
 import org.apache.tuscany.sdo.helper.TypeHelperImpl;
 import org.apache.tuscany.sdo.helper.XMLHelperImpl;
@@ -107,7 +108,8 @@
   {
     EPackage.Registry registry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
     ExtendedMetaData extendedMetaData = new SDOExtendedMetaDataImpl(registry); //TODO create subclass that makes demand() methods synchronous
-    return new TypeHelperImpl(extendedMetaData);
+    //return new TypeHelperImpl(extendedMetaData);
+    return (new HelperContextImpl(extendedMetaData, false)).getTypeHelper();
   }
 
   /**
@@ -118,7 +120,7 @@
    */
   public static DataFactory createDataFactory(TypeHelper scope)
   {
-    return new DataFactoryImpl(scope);
+	  return ((TypeHelperImpl)scope).getHelperContext().getDataFactory();
   }
 
   /**
@@ -129,7 +131,7 @@
    */
   public static XMLHelper createXMLHelper(TypeHelper scope)
   {
-    return new XMLHelperImpl(scope);
+	  return ((TypeHelperImpl)scope).getHelperContext().getXMLHelper();
   }
   
   /**
@@ -140,7 +142,7 @@
    */
   public static XSDHelper createXSDHelper(TypeHelper scope)
   {
-    return new XSDHelperImpl(scope, false);
+	  return ((TypeHelperImpl)scope).getHelperContext().getXSDHelper();
   }
   
   /**

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamSerializer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamSerializer.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamSerializer.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/ChangeSummaryStreamSerializer.java Wed Jul 11 07:16:50 2007
@@ -32,6 +32,7 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.tuscany.sdo.SDOPackage;
+import org.apache.tuscany.sdo.helper.HelperContextImpl;
 import org.apache.tuscany.sdo.helper.SDOAnnotations;
 import org.apache.tuscany.sdo.helper.XSDHelperImpl;
 import org.apache.tuscany.sdo.impl.ChangeSummaryImpl;
@@ -529,8 +530,9 @@
             extendedMetaData = ExtendedMetaData.INSTANCE;
             xsdHelper = XSDHelper.INSTANCE;
         }
-        else
-            xsdHelper = new XSDHelperImpl(extendedMetaData, null);
+        else{
+        	xsdHelper = (new HelperContextImpl(extendedMetaData, false)).getXSDHelper();
+        }
         Property declaration = changeSummaryElementNS == null
                              ? rootObject.getType().getProperty(changeSummaryElementName)
                              : xsdHelper.getGlobalProperty(changeSummaryElementNS, changeSummaryElementName, true);

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDODeserializer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDODeserializer.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDODeserializer.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDODeserializer.java Wed Jul 11 07:16:50 2007
@@ -28,6 +28,7 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.tuscany.sdo.helper.HelperContextImpl;
 import org.apache.tuscany.sdo.helper.TypeHelperImpl;
 import org.apache.tuscany.sdo.helper.XMLStreamHelper;
 import org.apache.tuscany.sdo.helper.XMLStreamHelperImpl;
@@ -54,12 +55,14 @@
  * SDO StAX Deserializer. The instance isn't thread-safe, however it's safe to use the instance any times on the same thread.
  */
 public class SDODeserializer extends StreamDeserializer {
+	private HelperContext hc;
     protected final void initialize(XMLStreamReader stream, HelperContext scope, Object rootObject) {
+    	hc = scope;
         reader = stream;
         xsdHelper = scope.getXSDHelper();
         typeHelper = scope.getTypeHelper();
         extendedMetaData = ((TypeHelperImpl) typeHelper).getExtendedMetaData();
-        deserializer = null;
+        deserializer = (XMLStreamHelperImpl)((HelperContextImpl)scope).getXMLStreamHelper();;
         root = (EObject) rootObject;
     }
 
@@ -110,8 +113,6 @@
     TypeHelper typeHelper;
 
     protected Object load(XMLStreamReader reader, Map options) throws XMLStreamException {
-        if (deserializer == null)
-            deserializer = new XMLStreamHelperImpl(typeHelper);
         return deserializer.loadObject(reader, options);
     }
 

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOXMLResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOXMLResourceImpl.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOXMLResourceImpl.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/SDOXMLResourceImpl.java Wed Jul 11 07:16:50 2007
@@ -20,6 +20,7 @@
 package org.apache.tuscany.sdo.util.resource;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Writer;
 import java.net.URL;
 import java.security.AccessController;
@@ -31,6 +32,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.xml.XMLConstants;
 import javax.xml.namespace.NamespaceContext;
@@ -46,7 +48,8 @@
 import org.apache.tuscany.sdo.helper.SDOExtendedMetaDataImpl;
 import org.apache.tuscany.sdo.helper.XMLStreamHelper;
 import org.apache.tuscany.sdo.helper.XSDHelperImpl;
-import org.apache.tuscany.sdo.util.SDOUtil;
+import org.apache.tuscany.sdo.api.SDOHelper;
+import org.apache.tuscany.sdo.api.SDOUtil;
 import org.apache.tuscany.sdo.util.StAX2SAXAdapter;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EClassifier;
@@ -486,28 +489,31 @@
             /*
              * Tolerates element/attribute malform unless indicated not to
              */
-            Object option = options.get(SDOUtil.XML_LOAD_LaxForm);
+            Object option = options.get(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM);
             int tolerance = option == null ? loadLaxForm : ((Number) option).intValue();
             option = options.get(OPTION_EXTENDED_META_DATA);
             if (tolerance == 0) {
                 if (option instanceof SDOExtendedMetaData)
                     ((SDOExtendedMetaData) option).setFeatureNamespaceMatchingLax(false);
-            } else if (option instanceof SDOExtendedMetaData)
+            } else if (option instanceof SDOExtendedMetaData){
                 ((SDOExtendedMetaData) option).setFeatureNamespaceMatchingLax(true);
-            else
+            }
+            else{
                 options.put(OPTION_EXTENDED_META_DATA, option = new SDOExtendedMetaDataImpl()); // TODO copy (BasicExtendedMetaData)option
+            }
             /*
              * Loads schema if necessary
              */
-            if (Boolean.TRUE.equals(options.get(SDOUtil.XML_LOAD_SCHEMA))) {
+            if (Boolean.TRUE.equals(options.get(SDOHelper.XMLOptions.XML_LOAD_SCHEMA))){
                 XMLOptions xmlOptions = (XMLOptions) options.get(OPTION_XML_OPTIONS);
                 if (xmlOptions == null) {
                     xmlOptions = new XMLOptionsImpl();
                     options.put(OPTION_XML_OPTIONS, xmlOptions);
                 }
                 xmlOptions.setProcessSchemaLocations(true);
-                if (option == null)
+                if (option == null){
                     option = getDefaultLoadOptions().get(OPTION_EXTENDED_META_DATA);
+                }
                 ExtendedMetaData extendedMetaData;
                 final XSDHelper xsdHelper;
                 if (option == null) {
@@ -515,7 +521,7 @@
                     xsdHelper = XSDHelper.INSTANCE;
                 } else {
                     extendedMetaData = (ExtendedMetaData) option;
-                    xsdHelper = new XSDHelperImpl(extendedMetaData, null);
+                    xsdHelper = (new HelperContextImpl(extendedMetaData, false)).getXSDHelper();
                 }
                 xmlOptions.setEcoreBuilder(new DefaultEcoreBuilder(extendedMetaData) {
                     public Collection generate(Map targetNamespaceToURI) throws IOException {
@@ -633,27 +639,27 @@
         protected void init(XMLResource resource, Map options) {
             super.init(resource, options);
             int unformat = 0;
-            String lineBreak = (String) options.get(SDOUtil.XML_SAVE_LineBreak);
+            String lineBreak = (String) options.get(SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK);
             if (lineBreak == null)
-                changeSummaryOptions.put(SDOUtil.XML_SAVE_LineBreak, LINE_BREAK);
+                changeSummaryOptions.put(SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK);
             else if (lineBreak.length() == 0)
                 ++unformat;
             else {
-                changeSummaryOptions.put(SDOUtil.XML_SAVE_LineBreak, LINE_BREAK);
+                changeSummaryOptions.put(SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK);
                 if (lineBreak.equals(LINE_SEPARATOR))
                     lineBreak = null;
             }
-            String indent = (String) options.get(SDOUtil.XML_SAVE_INDENT);
+            String indent = (String) options.get(SDOHelper.XMLOptions.XML_SAVE_INDENT);
             if (indent == null)
-                changeSummaryOptions.put(SDOUtil.XML_SAVE_INDENT, INDENT);
+                changeSummaryOptions.put(SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT);
             else if (indent.length() == 0)
                 ++unformat;
             else {
-                changeSummaryOptions.put(SDOUtil.XML_SAVE_INDENT, this.indent = indent);
+                changeSummaryOptions.put(SDOHelper.XMLOptions.XML_SAVE_INDENT, this.indent = indent);
                 if (indent.equals(INDENT))
                     indent = null;
             }
-            String margin = (String) options.get(SDOUtil.XML_SAVE_MARGIN);
+            String margin = (String) options.get(SDOHelper.XMLOptions.XML_SAVE_MARGIN);
             if (margin == null || margin.length() == 0) {
                 if (unformat == 2)
                     doc.setUnformatted(true);
@@ -709,7 +715,7 @@
                 StringBuffer margin = new StringBuffer(this.margin);
                 for (EObject container = o.eContainer(), grandContainer; (grandContainer = container.eContainer()) != null; container = grandContainer)
                     margin.append(indent);
-                changeSummaryOptions.put(SDOUtil.XML_SAVE_MARGIN, margin.toString());
+                changeSummaryOptions.put(SDOHelper.XMLOptions.XML_SAVE_MARGIN, margin.toString());
             }
             try {
                 if (xmlStreamWriter == null) {

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/XMLStreamSerializer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/XMLStreamSerializer.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/XMLStreamSerializer.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/main/java/org/apache/tuscany/sdo/util/resource/XMLStreamSerializer.java Wed Jul 11 07:16:50 2007
@@ -16,12 +16,16 @@
 
 package org.apache.tuscany.sdo.util.resource;
 
+import java.util.Map;
 import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.tuscany.sdo.api.SDOHelper;
+import org.apache.tuscany.sdo.api.SDOUtil;
 /**
  * The XMLStreamSerializer pulls events from the XMLStreamReader and dumps into the XMLStreamWriter
  */
@@ -52,6 +56,10 @@
         serializeNode(node, writer);
     }
 
+    public void serialize(XMLStreamReader node, XMLStreamWriter writer, Map options) throws XMLStreamException {
+    	this.options = options;
+        serializeNode(node, writer);
+    }
     /**
      * Method serializeNode.
      * 
@@ -65,7 +73,12 @@
         while (reader.hasNext()) {
             int event = reader.next();
             if (event == START_ELEMENT) {
-                serializeElement(reader, writer);
+            	if(options == null){
+            		serializeElement(reader, writer);
+            	}
+            	else{
+            		serializeElementWithOptions(reader, writer);
+            	}
                 depth++;
             } else if (event == ATTRIBUTE) {
                 serializeAttributes(reader, writer);
@@ -76,7 +89,11 @@
             } else if (event == CDATA) {
                 serializeCData(reader, writer);
             } else if (event == END_ELEMENT) {
-                serializeEndElement(writer);
+            	if(options == null){
+            		serializeEndElement(writer);
+            	}else{
+            		serializeEndElementWithOptions(writer);
+            	}
                 depth--;
             } else if (event == START_DOCUMENT) {
                 depth++; // if a start document is found then increment the depth
@@ -84,7 +101,12 @@
                 if (depth != 0)
                     depth--; // for the end document - reduce the depth
                 try {
-                    serializeEndElement(writer);
+                	if(options == null){
+                		serializeEndElement(writer);
+                	}
+                	else{
+                		serializeEndElementWithOptions(writer);	
+                	}                    
                 } catch (Exception e) {
                     // TODO: log exceptions
                 }
@@ -137,7 +159,71 @@
         serializeAttributes(reader, writer);
 
     }
+    /**
+     * @param reader
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeElementWithOptions(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+    	++nest;
+    	boolean brk=false;
+    	if(oldNest != nest){
+    		if(oldNest < nest) brk = true;
+    		oldNest = nest;    		
+    	}
+    	startElement(writer);
+        String prefix = reader.getPrefix();
+        String nameSpaceName = reader.getNamespaceURI();
+        if (nameSpaceName != null) {
+            String writer_prefix = writer.getPrefix(nameSpaceName);
+            
+            if (writer_prefix != null) {
+                if(brk && nest != 1){
+                	breakLine(writer, true, true);
+                }
+                else{
+                	breakLine(writer, false, true);
+                }
+
+                writer.writeStartElement(nameSpaceName, reader.getLocalName());                
+            } else {
+                if (prefix != null) {
+                    if(brk && nest == 1){
+                    	breakLine(writer, false, true);
+                    }                    
+                    writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName);
+                    writer.writeNamespace(prefix, nameSpaceName);
+                    writer.setPrefix(prefix, nameSpaceName);
+                } else {
+                    if(brk && nest == 1){
+                    	breakLine(writer, false, true);
+                    }                                    	
+                    writer.writeStartElement(nameSpaceName, reader.getLocalName());
+                    writer.writeDefaultNamespace(nameSpaceName);
+                    writer.setDefaultNamespace(nameSpaceName);
+                    if(brk && nest == 1){
+                    	breakLine(writer, false, true);
+                    }                    
+                }
+            }
+        } else {
+            writer.writeStartElement(reader.getLocalName());
+        }
+ 
+        // add the namespaces
+        int count = reader.getNamespaceCount();
+        String namespacePrefix;
+        for (int i = 0; i < count; i++) {
+            namespacePrefix = reader.getNamespacePrefix(i);
+            if (namespacePrefix != null && namespacePrefix.length() == 0)
+                continue;
 
+            serializeNamespace(namespacePrefix, reader.getNamespaceURI(i), writer);
+        }
+
+        // add attributes
+        serializeAttributes(reader, writer);    	
+    }
     /**
      * Method serializeEndElement.
      * 
@@ -149,6 +235,26 @@
     }
 
     /**
+     * Method serializeEndElement.
+     * 
+     * @param writer
+     * @throws XMLStreamException
+     */
+    protected void serializeEndElementWithOptions(XMLStreamWriter writer) throws XMLStreamException {
+        --nest;
+        if(oldNest > nest+1){
+        	nest++;
+        	breakLine(writer, false, true);
+        	writer.writeEndElement();
+        	breakLine(writer, true, false);
+        	nest--;
+        }
+        else{
+        	writer.writeEndElement();
+        	breakLine(writer, true, false);        	
+        }
+    }
+    /**
      * @param reader
      * @param writer
      * @throws XMLStreamException
@@ -268,5 +374,41 @@
             writer.writeNamespace(prefix, URI);
             writer.setPrefix(prefix, URI);
         }
+    }
+    private String lineBreak, indent, margin = null;
+
+    private int nest;
+    private int oldNest;
+
+    private void breakLine(XMLStreamWriter writer, boolean breakLine, boolean others) throws XMLStreamException {
+        if (options == null || (lineBreak==null && indent==null && margin==null) )
+            return;    	
+   		if(breakLine) 
+   			writer.writeCharacters(lineBreak);
+
+        if (margin != null){
+            if(others)
+            	writer.writeCharacters(margin);
+        }
+
+        if (indent != null && others){
+            for (int count = nest; count != 1; --count){//!= 0
+                writer.writeCharacters(indent);
+            }
+        }
+    }
+
+    private Map options;
+
+    static private final String STRING_OPTION = "String option";
+    
+    void startElement(XMLStreamWriter writer) throws XMLStreamException {
+        if (options == null)
+            return;
+        lineBreak = (String) options.get(SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK);
+        if (lineBreak == null)
+            return;
+       	margin = (String) options.get(SDOHelper.XMLOptions.XML_SAVE_MARGIN);
+       	indent = (String) options.get(SDOHelper.XMLOptions.XML_SAVE_INDENT);
     }
 }

Modified: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java Wed Jul 11 07:16:50 2007
@@ -61,7 +61,8 @@
         suite.addTestSuite(XPathTestCase.class);
         suite.addTestSuite(XSDHelperTestCase.class);
         suite.addTestSuite(XSDQNameTestCase.class);
-
+        suite.addTestSuite(XMLLoadOptionsTestCase.class);
+        suite.addTestSuite(XMLSaveOptionsTestCase.class);
         return suite;
     }
 
@@ -74,4 +75,7 @@
         junit.textui.TestRunner.run(suite());
     }
 }
+
+
+
 

Added: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/XMLLoadOptionsTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/XMLLoadOptionsTestCase.java?view=auto&rev=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/XMLLoadOptionsTestCase.java (added)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/XMLLoadOptionsTestCase.java Wed Jul 11 07:16:50 2007
@@ -0,0 +1,196 @@
+/**
+ *
+ *  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.test;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.SDOPackage;
+import org.apache.tuscany.sdo.api.SDOHelper;
+import org.apache.tuscany.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.api.XMLStreamHelper;
+import org.eclipse.emf.ecore.resource.Resource;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+
+public class XMLLoadOptionsTestCase extends TestCase {
+    XMLHelper xmlHelper;
+    Map options;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+    
+	//SDOUtil->SDOHelper->SDOHelperImpl->HelperContextImpl->XMLHelperImpl
+    public void testXMLOptionsSchema1() throws IOException{
+    	String TEST_XML_DOCUMENT = "/SchemaLocationTestCase.xml";
+    	
+    	options = new HashMap();
+    	options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.TRUE);
+    	
+    	XMLHelper xmlHelper = SDOUtil.createHelperContext(true, options).getXMLHelper();
+    	
+    	XMLDocument xmlDoc = xmlHelper.load(getClass().getResourceAsStream(TEST_XML_DOCUMENT), "whatever", null);
+    	DataObject root = xmlDoc.getRootObject();
+        assertNotSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject());   
+    }
+    
+//  SDOUtil->SDOHelper->SDOHelperImpl->HelperContextImpl->XMLHelperImpl
+    public void testXMLOptionsSchema2() throws IOException{
+    	String TEST_XML_DOCUMENT = "/SchemaLocationTestCase.xml";
+    	
+    	options = new HashMap();
+    	options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.FALSE);
+    	XMLHelper xmlHelper = SDOUtil.createHelperContext(true, options).getXMLHelper();
+    	XMLDocument xmlDoc = xmlHelper.load(getClass().getResourceAsStream(TEST_XML_DOCUMENT), "whatever", null);
+    	DataObject root = xmlDoc.getRootObject();
+        assertSame(root.getType(), SDOPackage.eINSTANCE.getAnyTypeDataObject());    
+    }
+    
+    public void testXMLOptionsLax1() throws IOException{
+    	options = new HashMap();
+    	/*
+         * turn off default behaviour of tolerating malformed xml
+         * tests using this option and bad xml should demonstrate failure to load
+         */
+    	 //SDOHelper.XMLOptions.XML_LOAD_LAX_FORM
+    	options.put(org.apache.tuscany.sdo.util.SDOUtil.XML_LOAD_LaxForm, new Integer(0));
+    	HelperContext hc = SDOUtil.createHelperContext(true, options);
+        hc.getXSDHelper().define(
+        		"<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"testNS\">"+
+        		  "<element name=\"root\">"+
+        		    "<complexType>"+
+        		      "<sequence>"+
+        		        "<element name=\"unqualifiedElement\" type=\"string\"/>"+
+        		        "<element name=\"qualifiedElement\" form=\"qualified\" type=\"string\"/>"+
+        		      "</sequence>"+
+        		      "<attribute name=\"unqualifiedAttribute\" type=\"string\"/>"+
+        		      "<attribute name=\"qualifiedAttribute\" form=\"qualified\" type=\"string\"/>"+
+        		    "</complexType>"+
+        		  "</element>"+
+        		"</schema>");   	
+
+        String xml="<p:root xmlns:p=\"testNS\">"+
+  "<p:unqualifiedElement/>"+
+"</p:root>";
+
+        /*
+         * this malformed xml will not load, as lax is forced OFF
+         * changing p:unqualifiedElement to unqualifiedElement 
+         * will work */
+      try{
+        hc.getXMLHelper().load(new StringReader(xml), null, null);
+       fail();
+    } catch (Resource.IOWrappedException featureNotFound) {
+    	assertTrue(true);
+    }
+    
+    }
+    
+    public void testXMLOptionsLax2() throws IOException{
+    	options = new HashMap();
+    	/*
+         * turn on default behaviour of tolerating malformed xml
+         * tests using this option and bad xml will load
+         */
+    	options.put(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM, new Integer(1));
+    	HelperContext hc = SDOUtil.createHelperContext(true, options);
+        hc.getXSDHelper().define(
+        		"<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"testNS\">"+
+        		"<element name=\"root\">"+
+        		"<complexType>"+
+        		  "<sequence>"+
+        		    "<element name=\"unqualifiedElement\" type=\"string\"/>"+
+        		    "<element name=\"qualifiedElement\" form=\"qualified\" type=\"string\"/>"+
+        		  "</sequence>"+
+        		  "<attribute name=\"unqualifiedAttribute\" type=\"string\"/>"+
+        		  "<attribute name=\"qualifiedAttribute\" form=\"qualified\" type=\"string\"/>"+
+        		"</complexType>"+
+        		"</element>"+
+        		"</schema>");    	
+
+        String xml="<p:root xmlns:p=\"testNS\" p:unqualifiedAttribute=\"u\" qualifiedAttribute=\"q\">"+
+        "<p:unqualifiedElement/>"+
+        "<qualifiedElement/>"+
+      "</p:root>";
+
+        /*
+         * this malformed xml will load, as lax is forced ON
+         */
+       assertNotNull(hc.getXMLHelper().load(new StringReader(xml), null, null).getRootObject());    	
+    }
+   
+    //SDOUtil->SDOHelper->SDOHelperImpl->XMLStreamHelperImpl->XMLDocumentImpl
+    public void testXMLStreamHelper() throws IOException, XMLStreamException{
+    	options = new HashMap();
+    	/*
+         * turn off default behaviour of tolerating malformed xml
+         * tests using this option and bad xml will load
+         */
+    	options.put(SDOHelper.XMLOptions.XML_LOAD_LAX_FORM, new Integer(1));
+    	HelperContext hc = SDOUtil.createHelperContext(false, options);
+    	TypeHelper th = hc.getTypeHelper();
+        XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(th, options);
+        hc.getXSDHelper().define(
+        "<schema xmlns=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"testNS\">"+
+		"<element name=\"root\">"+
+		"<complexType>"+
+		  "<sequence>"+
+		    "<element name=\"unqualifiedElement\" type=\"string\"/>"+
+		    "<element name=\"qualifiedElement\" form=\"qualified\" type=\"string\"/>"+
+		  "</sequence>"+
+		  "<attribute name=\"unqualifiedAttribute\" type=\"string\"/>"+
+		  "<attribute name=\"qualifiedAttribute\" form=\"qualified\" type=\"string\"/>"+
+		"</complexType>"+
+		"</element>"+
+		"</schema>");
+        
+        String xml="<p:root xmlns:p=\"testNS\" p:unqualifiedAttribute=\"u\" qualifiedAttribute=\"q\">"+
+        "<p:unqualifiedElement/>"+
+        "<qualifiedElement/>"+
+      "</p:root>";
+        
+        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+        XMLStreamReader reader1 = inputFactory.createXMLStreamReader(new StringReader(xml));
+        int event = reader1.getEventType();
+        while (!(event == XMLStreamConstants.START_ELEMENT)){
+        	event = reader1.next();
+        }
+        DataObject dataObject = streamHelper.loadObject(reader1);
+        /*
+         * this malformed xml will load, as lax is forced ON
+         */
+       assertNotNull(dataObject);        
+    }     
+}

Added: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java?view=auto&rev=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java (added)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java Wed Jul 11 07:16:50 2007
@@ -0,0 +1,149 @@
+/**
+ *
+ *  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.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URL;
+import java.util.HashMap;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.api.SDOHelper;
+import org.apache.tuscany.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.api.XMLStreamHelper;
+
+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;
+
+public class XMLSaveOptionsTestCase extends TestCase {
+	  HelperContext hc;
+	  private XSDHelper xsdHelper;
+	  XMLHelper xmlh;
+	  XMLStreamHelper xmlStreamHelper;
+	  static final String INDENT = " ", MARGIN = " ", LINE_BREAK = "\n";
+	  String formatted1 = 	MARGIN+  "<?xml version=\"1.0\" encoding=\"ASCII\"?>"  +LINE_BREAK+
+		MARGIN+  "<cs:stockQuote xmlns:cs=\"http://www.example.com/simpleCS\">"  +LINE_BREAK+
+		MARGIN+INDENT+  "<symbol>FBNT</symbol>"  +LINE_BREAK+
+		MARGIN+INDENT+  "<companyName>FlyByNightTechnology</companyName>"  +LINE_BREAK+
+		MARGIN+INDENT+  "<price>999.0</price>"  +LINE_BREAK+
+		MARGIN+INDENT+  "<volume>1000.0</volume>"  +LINE_BREAK+
+		MARGIN+INDENT+  "<quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+  "<price>1500.0</price>"  +LINE_BREAK+
+		MARGIN+INDENT+  "</quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+  "<quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+  "<price>2500.0</price>"  +LINE_BREAK+
+		MARGIN+INDENT+  "</quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+  "<quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+  "<price>3000.0</price>"  +LINE_BREAK+
+		MARGIN+INDENT+  "</quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+  "<quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+  "<price>4000.0</price>"  +LINE_BREAK+
+		MARGIN+INDENT+  "</quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+  "<changes create=\"#//quotes[3] #//quotes[4]\" delete=\"#//changes/stockQuote[1]/quotes[2]\" logging=\"false\" xmlns:sdo=\"commonj.sdo\">"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+  "<cs:stockQuote sdo:ref=\"#/stockQuote\" sdo:unset=\"volume\">"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+INDENT+  "<symbol>fbnt</symbol>"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+INDENT+  "<price>1000.0</price>"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+INDENT+  "<quotes sdo:ref=\"#//quotes[1]\" />"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+INDENT+  "<quotes><price>2000.0</price><quotes><price>2000.99</price></quotes></quotes>"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+INDENT+  "<quotes sdo:ref=\"#//quotes[2]\" />"  +LINE_BREAK+
+		MARGIN+INDENT+INDENT+  "</cs:stockQuote>"  +LINE_BREAK+
+		MARGIN+INDENT+  "</changes>"  +LINE_BREAK+
+		MARGIN+  "</cs:stockQuote>";
+		  
+	  String formatted2 = 	
+	   //MARGIN+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"  +LINE_BREAK+
+	   MARGIN+ "<p0:stockQuote xmlns:p0=\"http://www.example.com/simple\">"  +LINE_BREAK+
+	   MARGIN+INDENT+"<symbol>fbnt</symbol>"  +LINE_BREAK+
+	   MARGIN+INDENT+"<companyName>FlyByNightTechnology</companyName>"  +LINE_BREAK+
+	   MARGIN+INDENT+"<price>1000.0</price>"  +LINE_BREAK+
+	   MARGIN+INDENT+"<open1>1000.0</open1>"  +LINE_BREAK+
+	   MARGIN+INDENT+"<high>1000.0</high>"  +LINE_BREAK+
+	   MARGIN+INDENT+"<low>1000.0</low>"  +LINE_BREAK+
+	   MARGIN+INDENT+"<volume>1000.0</volume>"  +LINE_BREAK+
+	   MARGIN+INDENT+"<change1>1000.0</change1>"  +LINE_BREAK+
+	   MARGIN+"</p0:stockQuote>"		    +LINE_BREAK;
+	  	  
+	  void define(String model) throws IOException {
+	    // Populate the meta data for the test model
+	    URL url = getClass().getResource(model);
+	    xsdHelper.define(url.openStream(), url.toString());
+	  }
+	  
+	  protected void setUp() throws Exception {
+	    super.setUp();
+	  }
+
+	  protected void tearDown() throws Exception {
+	    super.tearDown();
+	  }
+
+	  //use XMLHelper
+	  public void testSaveXMLDocumentXMLHelper() throws IOException {
+		    HashMap options = new HashMap();
+		    options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT);
+		    options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_MARGIN, MARGIN);
+		    options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK);
+		    hc = SDOUtil.createHelperContext(false,options);
+		    xsdHelper = hc.getXSDHelper();
+		    xmlh = hc.getXMLHelper();
+  
+		    // Populate the meta data for the test (Stock Quote) model
+		    define("/simpleWithChangeSummary.xsd");
+		    XMLDocument doc = xmlh.load(getClass().getResource("/simpleWithChangeSummary.xml").openStream());
+		    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		    xmlh.save(xmlh.createDocument(doc.getRootObject(), doc.getRootElementURI(), doc.getRootElementName()), baos, null);
+		    assertEquals(formatted1, baos.toString());
+	  }
+	  
+	  //use XMLStreamHelper
+	  public void testSaveXMLDocumentXMLStreamHelper() throws Exception {	  
+		  	HashMap options = new HashMap();
+		    options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.FALSE);
+		    options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT);
+		    options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_MARGIN, MARGIN);
+		    options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK);
+		    HelperContext hc = SDOUtil.createHelperContext(false, options);
+		    TypeHelper th = hc.getTypeHelper();
+		    xmlStreamHelper = SDOUtil.createXMLStreamHelper(th, options); //both load and save options passed at same time  
+		    
+		    xsdHelper = hc.getXSDHelper();
+			define("/simple.xsd");
+	  	
+			InputStream inStrm = getClass().getResourceAsStream("/shallowquote.xml");
+		    XMLDocument document = hc.getXMLHelper().load(inStrm, null, null);
+		    
+		    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();	    
+	        StringWriter writer = new StringWriter();
+	        XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
+	        
+	        xmlStreamHelper.save(document, streamWriter, null);
+	        streamWriter.flush();
+	        assertEquals(formatted2, writer.toString());	
+	  }      
+}

Added: incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/resources/shallowquote1.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/resources/shallowquote1.xml?view=auto&rev=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/resources/shallowquote1.xml (added)
+++ incubator/tuscany/branches/sdo-1.0-incubating/impl/src/test/resources/shallowquote1.xml Wed Jul 11 07:16:50 2007
@@ -0,0 +1,11 @@
+ <?xml version="1.0" encoding="ASCII"?>
+ <simple:stockQuote xmlns:simple="http://www.example.com/simple">
+  <symbol>fbnt</symbol>
+  <companyName>FlyByNightTechnology</companyName>
+  <price>1000.0</price>
+  <open1>1000.0</open1>
+  <high>1000.0</high>
+  <low>1000.0</low>
+  <volume>1000.0</volume>
+  <change1>1000.0</change1>
+ </simple:stockQuote>

Modified: incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java Wed Jul 11 07:16:50 2007
@@ -55,6 +55,14 @@
   public HelperContext createHelperContext();
 
   /**
+   * 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.
+   * @param options Map of default XMLOptions
+   * @return the new HelperContext
+   * @see #createHelperContext(boolean)
+   */
+  public HelperContext createHelperContext(boolean extensibleNamespaces,Map options);
+  /**
    * 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
@@ -195,6 +203,13 @@
    */
   public XMLStreamHelper createXMLStreamHelper(TypeHelper scope);
   
+  /**
+   * Create a new XMLStreamHelper, with visibility to types in the specified TypeHelper scope.
+   * @param scope the TypeHelper to use for locating types.
+   * @param options Map of XMLOptions.
+   * @return the new XMLStreamHelper.
+   */
+  public XMLStreamHelper createXMLStreamHelper(TypeHelper scope, Map options);
   /**
    * Create a new ObjectInputStream in the specifice HelperContext scope.
    * @param inputStream the inputStream with which to create the ObjectInputStream.

Modified: incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java Wed Jul 11 07:16:50 2007
@@ -37,6 +37,7 @@
 import commonj.sdo.helper.CopyHelper;
 import commonj.sdo.helper.HelperContext;
 import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
 import commonj.sdo.impl.HelperProvider;
 
 /**
@@ -167,6 +168,12 @@
   }
   
   /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createHelperContext(boolean,Map)}.
+   */  
+  public static HelperContext createHelperContext(boolean extensibleNamespaces,Map options){
+	  return defaultSDOHelper.createHelperContext(extensibleNamespaces, options);
+  }
+  /**
    * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createHelperContext(boolean)}.
    */
   public static HelperContext createHelperContext(boolean extensibleNamespaces)
@@ -198,6 +205,13 @@
     return defaultSDOHelper.createXMLStreamHelper(scope);
   }
   
+  /**
+   * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createXMLStreamHelper(TypeHelper, Map)}.
+   */
+  public static XMLStreamHelper createXMLStreamHelper(TypeHelper scope, Map options)
+  {
+    return defaultSDOHelper.createXMLStreamHelper(scope, options);
+  }
   /**
    * @see {@link org.apache.tuscany.sdo.api.SDOHelper#createObjectInputStream(InputStream, HelperContext)}.
    */

Modified: incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/api/XMLStreamHelper.java Wed Jul 11 07:16:50 2007
@@ -25,89 +25,101 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
 import commonj.sdo.helper.XMLDocument;
 
 /**
- * Helper interface for reading and writing SDO DataObjects from XML streams (StAX).
- *
+ * 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);
+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;
+
+    void save(XMLDocument document, XMLStreamWriter writer, Map options) 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;
+
+    void saveObject(DataObject sdo, XMLStreamWriter writer, Map options) 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);
+
+    HelperContext getHelperContext();
 }

Modified: incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/spi/HelperProviderBase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/spi/HelperProviderBase.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/spi/HelperProviderBase.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/lib/src/main/java/org/apache/tuscany/sdo/spi/HelperProviderBase.java Wed Jul 11 07:16:50 2007
@@ -31,6 +31,7 @@
 
 import org.apache.tuscany.sdo.api.SDOHelper;
 import org.apache.tuscany.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.api.XMLStreamHelper;
 import org.apache.tuscany.sdo.lib.SDOObjectInputStream;
 
 import commonj.sdo.DataGraph;
@@ -68,6 +69,7 @@
   
   protected SDOHelper sdoHelper; // Tuscany extension APIs
 
+  protected XMLStreamHelper xmlStreamHelper;
   /**
    * Subclasses must implement this method to initialize the above Helper instance variables
    */
@@ -113,6 +115,10 @@
     return xmlHelper;
   }
 
+  public XMLStreamHelper xmlStreamHelper()
+  {
+    return xmlStreamHelper;
+  }
   public XSDHelper xsdHelper()
   {
     return xsdHelper;

Modified: incubator/tuscany/branches/sdo-1.0-incubating/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java Wed Jul 11 07:16:50 2007
@@ -33,6 +33,7 @@
 import java.util.StringTokenizer;
 
 import org.apache.tuscany.sdo.generate.adapter.SDOGenModelGeneratorAdapterFactory;
+import org.apache.tuscany.sdo.helper.HelperContextImpl;
 import org.apache.tuscany.sdo.helper.XSDHelperImpl;
 import org.apache.tuscany.sdo.impl.SDOPackageImpl;
 import org.apache.tuscany.sdo.model.ModelFactory;
@@ -308,7 +309,7 @@
     DataObjectUtil.initRuntime();
     EPackage.Registry packageRegistry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
     ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(packageRegistry);
-    XSDHelper xsdHelper = new XSDHelperImpl(extendedMetaData, null);
+    XSDHelper xsdHelper = (new HelperContextImpl(extendedMetaData, false)).getXSDHelper();
 
     try
     {

Modified: incubator/tuscany/branches/sdo-1.0-incubating/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sdo-1.0-incubating/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java?view=diff&rev=555279&r1=555278&r2=555279
==============================================================================
--- incubator/tuscany/branches/sdo-1.0-incubating/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java (original)
+++ incubator/tuscany/branches/sdo-1.0-incubating/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java Wed Jul 11 07:16:50 2007
@@ -30,6 +30,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.tuscany.sdo.helper.HelperContextImpl;
 import org.apache.tuscany.sdo.helper.XSDHelperImpl;
 import org.apache.tuscany.sdo.util.DataObjectUtil;
 import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
@@ -47,6 +48,7 @@
 import org.eclipse.emf.ecore.util.ExtendedMetaData;
 import org.eclipse.xsd.XSDSchema;
 
+import commonj.sdo.helper.HelperContext;
 import commonj.sdo.helper.XSDHelper;
 
 public class XSD2JavaGenerator extends JavaGenerator
@@ -166,7 +168,10 @@
     GenModel genModel = null;  
       
     DataObjectUtil.initRuntime();
-    XSDHelper xsdHelper = new XSDHelperImpl(extendedMetaData, regenerateBuiltIn);
+    HelperContext hc = new HelperContextImpl(extendedMetaData, false);
+    XSDHelper xsdHelper = hc.getXSDHelper();
+    ((XSDHelperImpl)xsdHelper).setRedefineBuiltIn(regenerateBuiltIn);
+    
     try
     {
       File inputFile = new File(xsdFileName).getAbsoluteFile();



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