Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Java-SDO-Next
-
None
Description
Namespace "http://www.example.com/substitutionEV" includes two complex type with simple content named CommentType and MyCommentType. MyCommentType restricts CommentType with facet maxLength="40". This maxLength facet does not appear to exist in the SDO metadata. The sample test case named testComplexTypeWithSimpleContentExtension() is included 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="id" type="sev:IdType" />
<element ref="sev:result" minOccurs="0"
maxOccurs="unbounded" />
<element name="comment" type="sev:CommentType" />
</sequence>
</complexType>
<complexType name="ResultType">
<sequence>
<element name="id" type="sev:IdType" />
<element name="name" type="string" />
<element name="value" type="sev:CommentType" />
</sequence>
</complexType>
<complexType name="MyResultType">
<complexContent>
<extension base="sev:ResultType" />
</complexContent>
</complexType>
<simpleType name="IdType">
<restriction base="sev:AsciiStringType">
<maxLength value="32" />
<pattern value="[0-9a-fA-F]*" />
</restriction>
</simpleType>
<simpleType name="AsciiStringType">
<restriction base="string">
<pattern value="\p
*" />
</restriction>
</simpleType>
<complexType name="CommentType">
<simpleContent>
<extension base="sev:AsciiStringType">
<attribute name="language" use="optional">
<simpleType>
<restriction base="string">
<enumeration value="English" />
<enumeration value="French" />
<enumeration value="Spanish" />
</restriction>
</simpleType>
</attribute>
</extension>
</simpleContent>
</complexType>
<complexType name="MyCommentType">
<simpleContent>
<restriction base="sev:CommentType">
<minLength value="0" />
<maxLength value="40" />
</restriction>
</simpleContent>
</complexType>
</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="id" type="sev2:Id2Type" />
<element name="results" minOccurs="0" maxOccurs="unbounded"
type="sev2:Results2Type" />
<element name="comment" type="sev2:Comment2Type" />
</sequence>
</complexType>
<complexType name="Results2Type">
<complexContent>
<extension base="sev:ResultsType"></extension>
</complexContent>
</complexType>
<simpleType name="Id2Type">
<restriction base="sev:IdType">
<maxLength value="10" />
</restriction>
</simpleType>
<complexType name="Comment2Type">
<simpleContent>
<restriction base="sev:CommentType">
<minLength value="0" />
<maxLength value="20" />
</restriction>
</simpleContent>
</complexType>
</schema>
==============================
substitutionWithExtensionValues1.xml
==============================
<?xml version="1.0" encoding="ASCII"?>
<sev2:allResults xmlns:sev2="http://www.example.com/substitutionEV2">
<sev2:id>ZZZZZZZZZZZZZZZZZZZZ</sev2:id>
<sev: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>value1</sev:value>
</sev:result>
<sev:myResult>
<sev:id>22222222222222222222</sev:id>
<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:id>AAAAAAAAAAAAAAAAAAAA</sev:id>
<sev:myResult>
<sev:id>BBBBBBBBBBBBBBBBBBBB</sev:id>
<sev:name>myNameB</sev:name>
<sev:value>myValueB</sev:value>
</sev:myResult>
<sev:comment>commentA</sev:comment>
</sev:results>
<sev2:comment language="English">
commentZZZZZZZZZZZZZZZZZZ
</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.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
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.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();
SEVFactory.INSTANCE.register(hc);
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(); }}
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 testComplexTypeWithSimpleContentExtension()
{ TypeHelper typeHelper = hc.getTypeHelper(); Type commentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "CommentType"); Type myCommentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "MyCommentType"); 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)); ExtendedMetaData extendedMetaData = ExtendedMetaData.INSTANCE; EStructuralFeature simpleFeature = null; EDataType commentSimpleType = null; simpleFeature = extendedMetaData.getSimpleFeature((EClass) myCommentType); commentSimpleType = (EDataType)simpleFeature.getEType(); assertEquals(40, extendedMetaData.getMaxLengthFacet(commentSimpleType)); simpleFeature = extendedMetaData.getSimpleFeature((EClass) comment2Type); commentSimpleType = (EDataType)simpleFeature.getEType(); assertEquals(20, extendedMetaData.getMaxLengthFacet(commentSimpleType)); }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)); Diagnostic diagnostic = Diagnostician.INSTANCE.validate((EObject) dataObject); String diagnosticMsg = diagnostic.getChildren().toString(); Type id2Type = typeHelper.getType(sev2NamespaceURI, "Id2Type"); assertTrue("Id2Type does not report IdType as a base type", id2Type.getBaseTypes().contains(idType)); assertTrue("EMF validation should have reported Id pattern match failure", diagnosticMsg.indexOf("Id") > 0); }}