Author: kelvingoodson
Date: Wed Nov 14 09:30:36 2007
New Revision: 594963

URL: http://svn.apache.org/viewvc?rev=594963&view=rev
Log:
Fix for TUSCANY-1812 (also fixes related JIRAs TUSCANY-1830 and TUSCANY-1832)

Added:
    
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues.xsd
    
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues1.xml
    
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd
    
incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java
Modified:
    
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java
    
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOExtendedMetaDataImpl.java
    
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java
    incubator/tuscany/java/sdo/tools-test/pom.xml

Modified: 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java?rev=594963&r1=594962&r2=594963&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java
 (original)
+++ 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/BaseSDOXSDEcoreBuilder.java
 Wed Nov 14 09:30:36 2007
@@ -46,12 +46,16 @@
 import org.eclipse.xsd.XSDAnnotation;
 import org.eclipse.xsd.XSDAttributeDeclaration;
 import org.eclipse.xsd.XSDAttributeUse;
+import org.eclipse.xsd.XSDComplexTypeContent;
 import org.eclipse.xsd.XSDComplexTypeDefinition;
 import org.eclipse.xsd.XSDComponent;
 import org.eclipse.xsd.XSDContentTypeCategory;
 import org.eclipse.xsd.XSDDerivationMethod;
 import org.eclipse.xsd.XSDElementDeclaration;
 import org.eclipse.xsd.XSDFeature;
+import org.eclipse.xsd.XSDLengthFacet;
+import org.eclipse.xsd.XSDMaxLengthFacet;
+import org.eclipse.xsd.XSDMinLengthFacet;
 import org.eclipse.xsd.XSDModelGroup;
 import org.eclipse.xsd.XSDModelGroupDefinition;
 import org.eclipse.xsd.XSDNamedComponent;
@@ -474,15 +478,28 @@
     if (xsdComplexTypeDefinition.getContentTypeCategory() == 
XSDContentTypeCategory.SIMPLE_LITERAL)
     {
       extendedMetaData.setContentKind(eClass, ExtendedMetaData.SIMPLE_CONTENT);
-      if (eClass.getEAllStructuralFeatures().isEmpty())
+      if (!"SimpleAnyType".equals(eClass.getName()) || 
!XMLTypePackage.eNS_URI.equals(eClass.getEPackage().getNsURI()))
       {
-        createFeature
-          (eClass,
-           "value",
-           getEClassifier(xsdComplexTypeDefinition.getSimpleType()),
-           null,
-           0,
-           1);
+        if (eClass.getEAllStructuralFeatures().isEmpty())
+        {
+          XSDComplexTypeContent xsdComplexTypeContent = 
xsdComplexTypeDefinition.getContent();
+          String name = getEcoreAttribute(xsdComplexTypeContent, "name");
+          if (name == null)
+          {
+            name = "value";
+          }
+          createFeature
+            (eClass,
+             null,
+             name,
+             xsdComplexTypeContent,
+             false);
+        }
+        else
+        {
+          XSDSimpleTypeDefinition xsdSimpleTypeDefinition = 
xsdComplexTypeDefinition.getSimpleType();
+          getEClassifier(xsdSimpleTypeDefinition);
+        }
       }
     }
     else 
@@ -1098,10 +1115,11 @@
       eReference.setUpperBound(maxOccurs);
 
       eClass.getEStructuralFeatures().add(eReference);
-      if (xsdComponent == null)
+      if (xsdComponent == null || xsdComponent instanceof 
XSDSimpleTypeDefinition)
       {
         extendedMetaData.setName(eReference, ":" + 
eClass.getEAllStructuralFeatures().indexOf(eReference));
         extendedMetaData.setFeatureKind(eReference, 
ExtendedMetaData.SIMPLE_FEATURE);
+        
eReference.setResolveProxies(!isLocalReferenceType((XSDSimpleTypeDefinition)xsdComponent));
       }
       else 
       {
@@ -1230,7 +1248,7 @@
       eAttribute.setUpperBound(maxOccurs);
       eClass.getEStructuralFeatures().add(eAttribute);
 
-      if (xsdComponent == null)
+      if (xsdComponent == null || xsdComponent instanceof 
XSDSimpleTypeDefinition)
       {
         extendedMetaData.setName(eAttribute, ":" + 
eClass.getEAllStructuralFeatures().indexOf(eAttribute));
         extendedMetaData.setFeatureKind(eAttribute, 
ExtendedMetaData.SIMPLE_FEATURE);
@@ -1365,6 +1383,12 @@
     }
   }
 
+  protected XSDTypeDefinition getEffectiveTypeDefinition(XSDComponent 
xsdComponent, XSDFeature xsdFeature) 
+  {
+    return xsdFeature == null ? 
+        ((XSDComplexTypeDefinition)xsdComponent.eContainer()).getSimpleType() 
: xsdFeature.getType();
+  }
+  
   protected EStructuralFeature createFeature
    (EClass eClass, XSDElementDeclaration xsdElementDeclaration, String name, 
XSDComponent xsdComponent, int minOccurs, int maxOccurs)
   {
@@ -1448,6 +1472,139 @@
     }
   }
 
+  protected EStructuralFeature createFeature
+    (EClass eClass, XSDAttributeDeclaration xsdAttributeDeclaration, String 
name, XSDComponent xsdComponent, boolean isRequired)
+  {
+    XSDSimpleTypeDefinition attributeTypeDefinition = 
(XSDSimpleTypeDefinition)getEffectiveTypeDefinition(xsdComponent, 
xsdAttributeDeclaration);
+    if (attributeTypeDefinition == null)
+    {
+      attributeTypeDefinition = 
xsdComponent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("anySimpleType");
+    }
+  
+    XSDTypeDefinition referenceType = getEcoreTypeQNameAttribute(xsdComponent, 
"reference");
+    if (referenceType == null && xsdAttributeDeclaration != null)
+    {
+      referenceType = getEcoreTypeQNameAttribute(xsdAttributeDeclaration, 
"reference");
+    }
+    if (referenceType != null)
+    {
+      int lowerBound = isRequired ? 1 : 0;
+      int upperBound = 1;
+      if (attributeTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL)
+      {
+        XSDLengthFacet xsdLengthFacet = 
attributeTypeDefinition.getEffectiveLengthFacet();
+        if (isRequired)
+        {
+          if (xsdLengthFacet != null)
+          {
+            lowerBound = xsdLengthFacet.getValue();
+          }
+          else
+          {
+            XSDMinLengthFacet xsdMinLengthFacet = 
attributeTypeDefinition.getEffectiveMinLengthFacet();
+            if (xsdMinLengthFacet != null)
+            {
+              lowerBound = xsdMinLengthFacet.getValue();
+            }
+          }
+        }
+        if (xsdLengthFacet != null)
+        {
+          upperBound = xsdLengthFacet.getValue();
+        }
+        else
+        {
+          XSDMaxLengthFacet xsdMaxLengthFacet = 
attributeTypeDefinition.getEffectiveMaxLengthFacet();
+          if (xsdMaxLengthFacet != null)
+          {
+            upperBound = xsdMaxLengthFacet.getValue();
+          }
+          else
+          {
+            upperBound = -1;
+          }
+        }
+      }
+  
+      EClassifier referenceClassifier = getEClassifier(referenceType);
+      EStructuralFeature result =
+        createFeature
+          (eClass,
+           name,
+           referenceClassifier,
+           xsdComponent,
+           lowerBound,
+           upperBound);
+      initialize(result, xsdAttributeDeclaration, xsdComponent);
+      return result;
+    }
+    else
+    {
+      boolean isMany = 
+          attributeTypeDefinition.getVariety() == XSDVariety.LIST_LITERAL &&
+          xsdComponent instanceof XSDAttributeUse && 
+          "true".equals(getEcoreAttribute(xsdComponent, "many"));
+      if (isMany)
+      {
+        EDataType eDataType = 
getEDataType(attributeTypeDefinition.getItemTypeDefinition());
+        XSDLengthFacet xsdLengthFacet = 
attributeTypeDefinition.getEffectiveLengthFacet();
+        int lowerBound = isRequired ? 1 : 0;
+        int upperBound = -1;
+        if (isRequired)
+        {
+          if (xsdLengthFacet != null)
+          {
+            lowerBound = xsdLengthFacet.getValue();
+          }
+          else
+          {
+            XSDMinLengthFacet xsdMinLengthFacet = 
attributeTypeDefinition.getEffectiveMinLengthFacet();
+            if (xsdMinLengthFacet != null)
+            {
+              lowerBound = xsdMinLengthFacet.getValue();
+            }
+          }
+        }
+        if (xsdLengthFacet != null)
+        {
+          upperBound = xsdLengthFacet.getValue();
+        }
+        else
+        {
+          XSDMaxLengthFacet xsdMaxLengthFacet = 
attributeTypeDefinition.getEffectiveMaxLengthFacet();
+          if (xsdMaxLengthFacet != null)
+          {
+            upperBound = xsdMaxLengthFacet.getValue();
+          }
+        }
+        EStructuralFeature result =
+          createFeature
+            (eClass,
+             name,
+             eDataType,
+             xsdComponent,
+             lowerBound,
+             upperBound);
+        initialize(result, xsdAttributeDeclaration, xsdComponent);
+        return result;
+      }
+      else
+      {
+        EDataType eDataType = getEDataType(attributeTypeDefinition);
+        EStructuralFeature result =
+          createFeature
+            (eClass,
+             name,
+             eDataType,
+             xsdComponent,
+             isRequired ? 1 : 0,
+             1);
+        initialize(result, xsdAttributeDeclaration, xsdComponent);
+        return result;
+      }
+    }
+  }
+  
   public EStructuralFeature getEStructuralFeature(XSDFeature xsdFeature)
   {
     if ("true".equals(getEcoreAttribute(xsdFeature, "ignore"))) return null;

Modified: 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOExtendedMetaDataImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOExtendedMetaDataImpl.java?rev=594963&r1=594962&r2=594963&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOExtendedMetaDataImpl.java
 (original)
+++ 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOExtendedMetaDataImpl.java
 Wed Nov 14 09:30:36 2007
@@ -20,6 +20,7 @@
 package org.apache.tuscany.sdo.helper;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
 
@@ -124,8 +125,27 @@
     return featureNamespaceMatchingLax;
   }
 
+  /*
+   * (non-Javadoc)
+   * 
+   * Eagerly pre-cache the "holder"s for static packages.
+   * 
+   * @see 
org.eclipse.emf.ecore.util.BasicExtendedMetaData#putPackage(java.lang.String,
+   *      org.eclipse.emf.ecore.EPackage)
+   */
+  public void putPackage(String namespace, EPackage ePackage) {
+    for (Iterator iterator = ePackage.eAllContents(); iterator.hasNext();) {
+      Object object = iterator.next();
+      if (object instanceof EClassifier) {
+        this.getName((EClassifier) object);
+      } else if (object instanceof EStructuralFeature) {
+        this.getName((EStructuralFeature) object);
+      }
+    }
+    super.putPackage(namespace, ePackage);
+  }
   
-  
/******************************************************************************************************
 
+       
/******************************************************************************************************
 
    * Following methods, getLocalAttribute & getLocalElement, ARE TEMPORARY 
COPIES FROM THE BASE CLASS. 
    * One line (the last line)in each method is changed to support lax 
namespace matching. 
    * DO NOT EDIT THESE METHODS. THEY WILL BE REMOVED WHEN WE MOVE TO EMF 2.3, 
WHICH FIXES THE PROBLEM.

Modified: 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java?rev=594963&r1=594962&r2=594963&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java
 (original)
+++ 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOXSDEcoreBuilder.java
 Wed Nov 14 09:30:36 2007
@@ -30,14 +30,13 @@
 import javax.xml.XMLConstants;
 
 import org.apache.tuscany.sdo.SDOExtendedMetaData;
+import org.apache.tuscany.sdo.api.SDOUtil;
 import org.apache.tuscany.sdo.impl.AttributeImpl;
 import org.apache.tuscany.sdo.impl.SDOFactoryImpl.SDOEcoreFactory;
 import org.apache.tuscany.sdo.model.ModelFactory;
-import org.apache.tuscany.sdo.api.SDOUtil;
 import org.eclipse.emf.common.notify.Adapter;
 import org.eclipse.emf.common.notify.Notifier;
 import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
-import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.ecore.EClassifier;
@@ -48,7 +47,6 @@
 import org.eclipse.emf.ecore.EReference;
 import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
-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;
@@ -64,7 +62,7 @@
 import org.eclipse.xsd.XSDSimpleTypeDefinition;
 import org.eclipse.xsd.XSDTerm;
 import org.eclipse.xsd.XSDTypeDefinition;
-import org.eclipse.xsd.ecore.EcoreXMLSchemaBuilder;
+import org.eclipse.xsd.ecore.EcoreSchemaBuilder;
 import org.eclipse.xsd.util.XSDResourceFactoryImpl;
 import org.eclipse.xsd.util.XSDResourceImpl;
 import org.eclipse.xsd.util.XSDSchemaLocator;
@@ -514,12 +512,22 @@
       if (container instanceof XSDNamedComponent)
       {
         result = getAliasName((XSDNamedComponent)container);
+        if (container instanceof XSDTypeDefinition)
+        {
+          result = "_" + result;
+        }
       }
+
     }
-    return result;
+    return result; 
   }
   
-  protected XSDTypeDefinition getEffectiveTypeDefinition(XSDComponent 
xsdComponent, XSDFeature xsdFeature) {
+  protected XSDTypeDefinition getEffectiveTypeDefinition(XSDComponent 
xsdComponent, XSDFeature xsdFeature) 
+  {
+    if (xsdFeature == null)
+    {
+      return super.getEffectiveTypeDefinition(xsdComponent, xsdFeature);
+    }
     XSDTypeDefinition typeDef = getEcoreTypeQNameAttribute(xsdComponent, 
"dataType");
 
     String isString = getEcoreAttribute(xsdComponent, xsdFeature, "string");
@@ -712,68 +720,25 @@
   private XSDSchema loadEPackage(EPackage ePackage)
   {
     XSDSchema ePackageXSDSchema = null;
-    XSDEcoreXMLSchemaBuilder xmlSchemaBuilder = new XSDEcoreXMLSchemaBuilder();
-    Collection xmlSchemas = xmlSchemaBuilder.generate(ePackage);
-    
xsdComponentToEModelElementMap.putAll(xmlSchemaBuilder.getXSDComponentToEModelElementMap());
-    for (Iterator iter = xmlSchemas.iterator(); iter.hasNext();) {
-      Object xmlSchema = (Object)iter.next();
-      if (xmlSchema instanceof XSDSchema) 
-      {
-        EPackage xmlSchemaEPackage = (EPackage) 
xsdComponentToEModelElementMap.get(xmlSchema);
-        addEPackageToXSDSchemaMapEntry(xmlSchemaEPackage, (XSDSchema) 
xmlSchema);
-        if (xmlSchemaEPackage.equals(ePackage))
-        {
-          ePackageXSDSchema = (XSDSchema) xmlSchema;
-        }
-      }
-    }
-    Map ePackageToXSDSchemaMap = xmlSchemaBuilder.getEPackageToXSDSchemaMap();
-    for (Iterator iter = ePackageToXSDSchemaMap.entrySet().iterator(); 
iter.hasNext();) {
-      Map.Entry mapEntry = (Map.Entry)iter.next();
-      EPackage xmlSchemaEPackage = (EPackage) mapEntry.getKey();
-      XSDSchema xmlSchema = (XSDSchema) mapEntry.getValue();
-      addEPackageToXSDSchemaMapEntry(xmlSchemaEPackage, xmlSchema);
-    }
-    return ePackageXSDSchema;
-  }
-  
-  private void addEPackageToXSDSchemaMapEntry(EPackage ePackage, XSDSchema 
xsdSchema)
-  {
+    XSDEcoreSchemaBuilder schemaBuilder = new 
XSDEcoreSchemaBuilder(extendedMetaData);
+    ePackageXSDSchema = schemaBuilder.getSchema(ePackage);
+    
xsdComponentToEModelElementMap.putAll(schemaBuilder.getXSDComponentToEModelElementMap());
     targetNamespaceToEPackageMap.put(ePackage.getNsURI(), ePackage);
     populateTypeToTypeObjectMap(ePackage);
-    xsdSchemas.add(xsdSchema);
+    xsdSchemas.add(ePackageXSDSchema);
+    return ePackageXSDSchema;
   }
   
-  private static class XSDEcoreXMLSchemaBuilder extends EcoreXMLSchemaBuilder
+  private static class XSDEcoreSchemaBuilder extends EcoreSchemaBuilder
   {
-    public XSDEcoreXMLSchemaBuilder() 
-       {
-      super();
-       }
-    
-    public Map getXSDComponentToEModelElementMap()
-    {
-      return xsdComponentToEModelElementMap;
-    }
-    
-    public Map getEPackageToXSDSchemaMap()
+    public XSDEcoreSchemaBuilder(ExtendedMetaData extendedMetaData) 
     {
-      return ePackageToXSDSchemaMap;
+      super(extendedMetaData);
     }
     
-    protected void additionalProcessing(EClass cls, XSDComplexTypeDefinition 
xsdCTDComplexTypeDefinition)
+    public Map getXSDComponentToEModelElementMap()
     {
-      // remove element definition
-      for(Iterator iter = 
xsdComponentToEModelElementMap.entrySet().iterator(); iter.hasNext();)
-      {
-        Map.Entry mapEntry = (Map.Entry)iter.next();
-        if (mapEntry.getValue().equals(cls) &&
-            mapEntry.getKey() instanceof XSDElementDeclaration)
-        {
-          xsdComponentToEModelElementMap.remove(mapEntry.getKey());
-          break;
-        }
-      }
+      return xsdComponentToEModelElementMap;
     }
   }
   

Modified: incubator/tuscany/java/sdo/tools-test/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/pom.xml?rev=594963&r1=594962&r2=594963&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/tools-test/pom.xml (original)
+++ incubator/tuscany/java/sdo/tools-test/pom.xml Wed Nov 14 09:30:36 2007
@@ -231,10 +231,22 @@
                                                        <goal>generate</goal>
                                                </goals>
                                        </execution>
+                                       <execution>
+                                         
<id>SubstitutionWithExtensionValues</id>
+                                         <configuration>
+                                           <schemaFile>
+                                             
${basedir}/src/main/resources/SubstitutionWithExtensionValues.xsd
+                                           </schemaFile>
+                                           <prefix>SEV</prefix>
+                                         </configuration>
+                                         <goals>
+                                           <goal>generate</goal>
+                                         </goals>
+                                       </execution>
                                </executions>
                        </plugin>
                </plugins>
        </build>
 
 
-</project>
\ No newline at end of file
+</project>

Added: 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues.xsd
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues.xsd?rev=594963&view=auto
==============================================================================
--- 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues.xsd
 (added)
+++ 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues.xsd
 Wed Nov 14 09:30:36 2007
@@ -0,0 +1,105 @@
+<xsd:schema 
+       targetNamespace="http://www.example.com/substitutionEV";
+       xmlns="http://www.example.com/substitutionEV";
+       xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+       xmlns:sev="http://www.example.com/substitutionEV";
+       elementFormDefault="qualified">
+       <!--
+               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.    
+       -->
+       <xsd:element name="results" type="sev:ResultsType" />
+
+       <xsd:element name="result" type="sev:ResultType" />
+       <xsd:element name="myResult" type="sev:MyResultType"
+               substitutionGroup="sev:result" />
+
+       <xsd:complexType name="ResultsType">
+               <xsd:sequence>
+                       <xsd:element name="id" type="sev:IdType" />
+                       <xsd:element ref="sev:result" minOccurs="0"
+                               maxOccurs="unbounded" />
+                       <xsd:element name="comment" type="sev:CommentType" />
+               </xsd:sequence>
+       </xsd:complexType>
+
+       <xsd:complexType name="ResultType">
+               <xsd:sequence>
+                       <xsd:element name="id" type="sev:IdType" />
+                       <xsd:element name="name" type="xsd:string" />
+                       <xsd:element name="value" type="sev:ValueType" />
+               </xsd:sequence>
+       </xsd:complexType>
+
+       <xsd:complexType name="MyResultType">
+               <xsd:complexContent>
+                       <xsd:extension base="sev:ResultType" />
+               </xsd:complexContent>
+       </xsd:complexType>
+
+       <xsd:simpleType name="IdType">
+               <xsd:restriction base="sev:AsciiStringType">
+                       <xsd:maxLength value="32" />
+                       <xsd:pattern value="[0-9a-fA-F]*" />
+               </xsd:restriction>
+       </xsd:simpleType>
+
+       <xsd:simpleType name="AsciiStringType">
+               <xsd:restriction base="xsd:string">
+                       <xsd:pattern value="\p{IsBasicLatin}*" />
+               </xsd:restriction>
+       </xsd:simpleType>
+ 
+       <xsd:complexType name="ValueType">
+               <xsd:simpleContent>
+                       <xsd:extension base="sev:Integer32Bit" />
+               </xsd:simpleContent>
+       </xsd:complexType>
+
+       <xsd:simpleType name="Integer32Bit">
+               <xsd:restriction base="xsd:integer">
+                       <xsd:minInclusive value="0" />
+                       <xsd:maxInclusive value="4290000000" />
+               </xsd:restriction>
+       </xsd:simpleType>
+
+       <xsd:complexType name="CommentType">
+               <xsd:simpleContent>
+                       <xsd:extension base="sev:AsciiStringType">
+                               <xsd:attribute name="language" use="optional">
+                                       <xsd:simpleType>
+                                               <xsd:restriction 
base="xsd:string">
+                                                       <xsd:enumeration 
value="English" />
+                                                       <xsd:enumeration 
value="French" />
+                                                       <xsd:enumeration 
value="Spanish" />
+                                               </xsd:restriction>
+                                       </xsd:simpleType>
+                               </xsd:attribute>
+                       </xsd:extension>
+               </xsd:simpleContent>
+       </xsd:complexType>
+
+       <xsd:complexType name="MyCommentType">
+               <xsd:simpleContent>
+                       <xsd:restriction base="sev:CommentType">
+                               <xsd:minLength value="0" />
+                               <xsd:maxLength value="40" />
+                       </xsd:restriction>
+               </xsd:simpleContent>
+       </xsd:complexType>
+
+</xsd:schema>

Added: 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues1.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues1.xml?rev=594963&view=auto
==============================================================================
--- 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues1.xml
 (added)
+++ 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues1.xml
 Wed Nov 14 09:30:36 2007
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="ASCII"?>
+<sev2:allResults xmlns:sev2="http://www.example.com/substitutionEV2";>
+       <sev2:id>ZZZZZZZZZZZZZZZZZZZZ</sev2:id>
+       <sev2:results xmlns:sev="http://www.example.com/substitutionEV";>
+               <sev:id>00000000000000000000</sev:id>
+               <sev:result>
+                       <sev:id>11111111111111111111</sev:id>
+                       <sev:name>name1</sev:name>
+                       <sev:value>1</sev:value>
+               </sev:result>
+               <sev:myResult>
+                       <sev:id>22222222222222222222</sev:id>
+                       <sev:name>myName2</sev:name>
+                       <sev:value>2</sev:value>
+               </sev:myResult>
+               <sev:comment>comment0</sev:comment>
+       </sev2:results>
+       <sev2:results xmlns:sev="http://www.example.com/substitutionEV";>
+               <sev:id>AAAAAAAAAAAAAAAAAAAA</sev:id>
+               <sev:myResult>
+                       <sev:id>BBBBBBBBBBBBBBBBBBBB</sev:id>
+                       <sev:name>myNameB</sev:name>
+                       <sev:value>11</sev:value>
+               </sev:myResult>
+               <sev:comment>commentA</sev:comment>
+       </sev2:results>
+       <sev2:comment language="English">
+               commentZZZZZZZZZZZZZZZZZZ
+       </sev2:comment>
+</sev2:allResults>

Added: 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd?rev=594963&view=auto
==============================================================================
--- 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd
 (added)
+++ 
incubator/tuscany/java/sdo/tools-test/src/main/resources/substitutionWithExtensionValues2.xsd
 Wed Nov 14 09:30:36 2007
@@ -0,0 +1,62 @@
+<xsd:schema 
+       targetNamespace="http://www.example.com/substitutionEV2";
+       xmlns="http://www.example.com/substitutionEV2";
+       xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+       xmlns:sev2="http://www.example.com/substitutionEV2";
+       xmlns:sev="http://www.example.com/substitutionEV";
+       elementFormDefault="qualified">
+       <!--
+               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.    
+       -->
+
+       <xsd:import namespace="http://www.example.com/substitutionEV";
+               schemaLocation="substitutionWithExtensionValues.xsd" />
+
+       <xsd:element name="allResults" type="sev2:AllResultsType" />
+
+       <xsd:complexType name="AllResultsType">
+               <xsd:sequence>
+                       <xsd:element name="id" type="sev2:Id2Type" />
+                       <xsd:element name="results" minOccurs="0" 
maxOccurs="unbounded"
+                               type="sev2:Results2Type" />
+                       <xsd:element name="comment" type="sev2:Comment2Type" />
+               </xsd:sequence>
+       </xsd:complexType>
+
+       <xsd:complexType name="Results2Type">
+               <xsd:complexContent>
+                       <xsd:extension base="sev:ResultsType" />
+               </xsd:complexContent>
+       </xsd:complexType>
+
+       <xsd:simpleType name="Id2Type">
+               <xsd:restriction base="sev:IdType">
+                       <xsd:maxLength value="10" />
+               </xsd:restriction>
+       </xsd:simpleType>
+
+       <xsd:complexType name="Comment2Type">
+               <xsd:simpleContent>
+                       <xsd:restriction base="sev:CommentType">
+                               <xsd:minLength value="0" />
+                               <xsd:maxLength value="20" />
+                       </xsd:restriction>
+               </xsd:simpleContent>
+       </xsd:complexType>
+
+</xsd:schema>

Added: 
incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java?rev=594963&view=auto
==============================================================================
--- 
incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java
 (added)
+++ 
incubator/tuscany/java/sdo/tools-test/src/test/java/org/apache/tuscany/sdo/test/SubstitutionWithExtensionValuesTestCase.java
 Wed Nov 14 09:30:36 2007
@@ -0,0 +1,156 @@
+/**
+ *
+ *  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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.api.SDOUtil;
+import org.eclipse.emf.ecore.EDataType;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.ExtendedMetaData;
+
+import com.example.substitution.ev.SEVFactory;
+import com.example.substitution.ev.impl.SEVFactoryImpl;
+import commonj.sdo.DataGraph;
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.impl.HelperProvider;
+
+public final class SubstitutionWithExtensionValuesTestCase extends TestCase 
+{
+  private static String sev2NamespaceURI;
+  private HelperContext hc;
+  private DataObject dataObject;
+  
+  protected void setUp() throws Exception {
+    super.setUp();
+    hc = HelperProvider.getDefaultContext();
+    registerSEV(hc, true);
+    
+    InputStream inputStream = null;
+    URL url = getClass().getResource("/substitutionWithExtensionValues2.xsd");
+    inputStream = url.openStream();
+    List sev2TypeList = hc.getXSDHelper().define(inputStream, url.toString());
+    inputStream.close();
+    
+    inputStream = 
getClass().getResourceAsStream("/substitutionWithExtensionValues1.xml");
+    dataObject = hc.getXMLHelper().load(inputStream).getRootObject();
+    inputStream.close();
+    
+    if (sev2NamespaceURI == null)
+    {
+      sev2NamespaceURI = ((Type) sev2TypeList.get(0)).getURI();
+    }
+  }
+  
+  private void registerSEV(HelperContext hc, boolean useStaticRegistration) 
throws IOException
+  {
+    if (useStaticRegistration)
+    {
+      SEVFactory.INSTANCE.register(hc);
+    }
+    else
+    {
+      InputStream inputStream = null;
+      URL url = getClass().getResource("/substitutionWithExtensionValues.xsd");
+      inputStream = url.openStream();
+      hc.getXSDHelper().define(inputStream, url.toString());
+      inputStream.close();
+    }
+  }
+
+  public void testComplexTypeWithSubstitutionExtension() throws IOException 
+  {
+    TypeHelper typeHelper = hc.getTypeHelper();
+    
+    Type resultsType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, 
"ResultsType");
+    Type results2Type = typeHelper.getType(sev2NamespaceURI, "Results2Type");
+    assertTrue("Results2 type does not report Results as a base type", 
+        results2Type.getBaseTypes().contains(resultsType));
+    
+    assertEquals("results.1/myResult.0/id has unexpected value", 
+        "BBBBBBBBBBBBBBBBBBBB", 
dataObject.getString("results.1/myResult.0/id"));
+  }
+  
+  public void testComplexTypeWithSimpleContentExtensionMetaData() 
+  {
+    TypeHelper typeHelper = hc.getTypeHelper();
+    
+    Type commentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, 
"CommentType");
+    Type myCommentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, 
"MyCommentType");
+    Type _myCommentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, 
"_MyCommentType");
+    Type comment2Type = typeHelper.getType(sev2NamespaceURI, "Comment2Type");
+    Type _comment2Type = typeHelper.getType(sev2NamespaceURI, "_Comment2Type");
+    assertTrue("MyComment type does not report Comment as a base type", 
+        myCommentType.getBaseTypes().contains(commentType));
+    assertTrue("Comment2 type does not report Comment as a base type", 
+        comment2Type.getBaseTypes().contains(commentType));
+    
+    // Test length facets - resort to EMF APIs until Tuscany SDO exposes these 
directly
+    ExtendedMetaData extendedMetaData = ExtendedMetaData.INSTANCE;
+
+    EStructuralFeature simpleFeature = null;
+    EDataType commentSimpleType = null;
+    
+    // FIXME Work-around EMF's lack of support for re-definable features - SEE 
TUSCANY-1832
+    commentSimpleType = (EDataType) _myCommentType;
+    assertEquals(40, extendedMetaData.getMaxLengthFacet(commentSimpleType));
+    
+    // FIXME Work-around EMF's lack of support for re-definable features - SEE 
TUSCANY-1832
+    commentSimpleType = (EDataType) _comment2Type;
+    assertEquals(20, extendedMetaData.getMaxLengthFacet(commentSimpleType));
+  }
+
+  // FIXME Test disable pending fix of TUSCANY-1842
+  public void dontTestComplexTypeWithSimpleContentExtensionChangeSummary() 
throws IOException 
+  {
+    DataGraph dg = SDOUtil.createDataGraph();
+    SDOUtil.setRootObject(dg, dataObject);
+    dg.getChangeSummary().beginLogging();
+    dataObject.getDataObject("results.1/myResult.0").delete();
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    SDOUtil.saveDataGraph(dg, baos, null);
+    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+    SDOUtil.loadDataGraph(bais, null, hc);
+  }    
+  
+  public void testSimpleTypeExtension() 
+  {
+    TypeHelper typeHelper = hc.getTypeHelper();
+    
+    Type asciiStringType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, 
"AsciiStringType");
+    Type idType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "IdType");
+    assertTrue("IdType does not report AsciiStringType as a base type", 
+        idType.getBaseTypes().contains(asciiStringType));
+    
+    Type id2Type = typeHelper.getType(sev2NamespaceURI, "Id2Type");
+    assertTrue("Id2Type does not report IdType as a base type", 
+        id2Type.getBaseTypes().contains(idType));
+  }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to