SimpleType extension across mixed static/dynamic namespaces is broken
---------------------------------------------------------------------

                 Key: TUSCANY-1830
                 URL: https://issues.apache.org/jira/browse/TUSCANY-1830
             Project: Tuscany
          Issue Type: Bug
          Components: Java SDO Implementation
    Affects Versions: Java-SDO-Next
            Reporter: Ron Gavlin


I have a statically registered namespace 
"http://www.example.com/substitutionEV"; with a simpleType named UuidType with a 
pattern facet. I also have a dynamically registered namespace 
"http://www.example.com/substitutionEV2"; with a simpleType named Uuid2Type 
which is a restriction of UuidType. When I invoke uuid2Type.getBaseTypes(), the 
parent UuidType is not returned. I have included a sample test below.

==============================
substitutionWithExtensionValues.xsd
==============================

<schema xmlns="http://www.w3.org/2001/XMLSchema";
        targetNamespace="http://www.example.com/substitutionEV"; 
        xmlns:sev="http://www.example.com/substitutionEV";>
  <!--
    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.    
  -->
  <element name="results" type="sev:ResultsType"/>
  
  <element name="result" type="sev:ResultType"/>
  <element name="myResult" type="sev:MyResultType" 
substitutionGroup="sev:result"/>
  
  <complexType name="ResultsType">
    <sequence>
      <element name="uuid" type="sev:UuidType"/>
      <element ref="sev:result" minOccurs="0" maxOccurs="unbounded"/>
      <element name="comment" type="string"/>
    </sequence>
  </complexType>
  
  <complexType name="ResultType">
    <sequence>
      <element name="uuid" type="sev:UuidType"/>
      <element name="name" type="string"/>
      <element name="value" type="string"/>
    </sequence>
  </complexType>
  
  <complexType name="MyResultType">
    <complexContent>
      <extension base="sev:ResultType"/>
    </complexContent>
  </complexType>
  
  <simpleType name="UuidType">
    <restriction base="sev:AsciiStringType">
      <pattern 
value="[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-f]{12}"/>
    </restriction>
  </simpleType>
  
  <simpleType name="AsciiStringType">
    <restriction base="string">
      <pattern value="\p{IsBasicLatin}*"/>
    </restriction>
  </simpleType>
  
</schema>

==============================
substitutionWithExtensionValues2.xsd
==============================

<schema xmlns="http://www.w3.org/2001/XMLSchema";
        targetNamespace="http://www.example.com/substitutionEV2";
        xmlns:sev2="http://www.example.com/substitutionEV2";
        xmlns:sev="http://www.example.com/substitutionEV";>
        <!--
                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.    
        -->

        <import namespace="http://www.example.com/substitutionEV";
                schemaLocation="substitutionWithExtensionValues.xsd" />

        <element name="allResults" type="sev2:AllResultsType" />

        <complexType name="AllResultsType">
                <sequence>
                        <element name="uuid" type="sev2:Uuid2Type" />
                        <element name="results" minOccurs="0" 
maxOccurs="unbounded"
                                type="sev2:Results2Type" />
                        <element name="comment" type="string" />
                </sequence>
        </complexType>

        <complexType name="Results2Type">
                <complexContent>
                        <extension base="sev:ResultsType"></extension>
                </complexContent>
        </complexType>

        <simpleType name="Uuid2Type">
                <restriction base="sev:UuidType" />
        </simpleType>

</schema>

==============================
substitutionWithExtensionValues1.xml
==============================

<?xml version="1.0" encoding="ASCII"?>
<sev2:allResults xmlns:sev2="http://www.example.com/substitutionEV2";>
        <sev2:uuid>ZZZZZZZZ-ZZZZ-ZZZZ-ZZZZ-ZZZZZZZZZZZZ</sev2:uuid>
        <sev:results xmlns:sev="http://www.example.com/substitutionEV";>
    <sev:uuid>00000000-0000-0000-0000-000000000000</sev:uuid>
                <sev:result>
                        
<sev:uuid>11111111-1111-1111-1111-111111111111</sev:uuid>
                        <sev:name>name1</sev:name>
                        <sev:value>value1</sev:value>
                </sev:result>
                <sev:myResult>
                        
<sev:uuid>22222222-2222-2222-2222-222222222222</sev:uuid>
                        <sev:name>myName2</sev:name>
                        <sev:value>myValue2</sev:value>
                </sev:myResult>
                <sev:comment>comment0</sev:comment>
        </sev:results>
        <sev:results xmlns:sev="http://www.example.com/substitutionEV";>
    <sev:uuid>AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA</sev:uuid>
                <sev:myResult>
                        
<sev:uuid>BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB</sev:uuid>
                        <sev:name>myNameB</sev:name>
                        <sev:value>myValueB</sev:value>
                </sev:myResult>
                <sev:comment>commentA</sev:comment>
        </sev:results>
        <sev2:comment>commentZ</sev2:comment>
</sev2:allResults>

==============================
SubstitutionWithExtensionValuesTestCase.java
==============================

/**
 *
 *  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.InputStream;
import java.net.URL;
import java.util.List;

import junit.framework.TestCase;

import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.Diagnostician;

import com.example.substitution.ev.SEVFactory;
import com.example.substitution.ev.impl.SEVFactoryImpl;
import commonj.sdo.DataObject;
import commonj.sdo.Type;
import commonj.sdo.helper.HelperContext;
import commonj.sdo.helper.TypeHelper;
import commonj.sdo.helper.XMLHelper;
import commonj.sdo.impl.HelperProvider;

public final class SubstitutionWithExtensionValuesTestCase extends TestCase 
{
  private String sev2NamespaceURI;
  private HelperContext hc;
  
  protected void setUp() throws Exception {
    super.setUp();
    hc = HelperProvider.getDefaultContext();
    SEVFactory.INSTANCE.register(hc);
    
    URL url = getClass().getResource("/substitutionWithExtensionValues2.xsd");
    InputStream inputStream = url.openStream();
    List sev2TypeList = hc.getXSDHelper().define(inputStream, url.toString());
    inputStream.close();
    
    sev2NamespaceURI = ((Type) sev2TypeList.get(0)).getURI();
  }


  public void test() throws IOException 
  {
    
    XMLHelper xmlHelper = hc.getXMLHelper();
    DataObject dataObject = 
        
xmlHelper.load(getClass().getResourceAsStream("/substitutionWithExtensionValues1.xml")).getRootObject();

    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));
    
    Type asciiStringType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, 
"AsciiStringType");
    Type uuidType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, 
"UuidType");
    assertTrue("UuidType does not report AsciiStringType as a base type", 
        uuidType.getBaseTypes().contains(asciiStringType));
    
// Both of the following asserts currently fail because of this bug

    Type uuid2Type = typeHelper.getType(sev2NamespaceURI, "Uuid2Type");
    assertTrue("Uuid2Type does not report UuidType as a base type", 
        uuid2Type.getBaseTypes().contains(uuidType));
    Diagnostic diagnostic = Diagnostician.INSTANCE.validate((EObject) 
dataObject);
    assertEquals("EMF validation should have reported Uuid pattern match 
failure", 
        Diagnostic.ERROR, diagnostic.getSeverity());
    
  }
}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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

Reply via email to