Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
Java-SDO-Next
-
None
-
Windows XP, Sun JDK 1.5.0_09
-
Patch Available
Description
In the test method, testComplexTypeWithSimpleContentExtensionChangeSummary() listed below, a DataGraph is created with a dataObject whose property type extends a complexType with simple integer content. After the dataObject is deleted, an attempt is made to save and load the DataGraph. While the DataGraph is being loaded, an unsuccessful attempt is made to convert a zero-length string into a BigInteger.
Any suggestions on how to best fix this are most welcome.
Thanks,
- Ron
==============================
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:ValueType" />
</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="ValueType">
<simpleContent>
<extension base="sev:Integer32Bit" />
</simpleContent>
</complexType>
<complexType name="Integer32Bit">
<simpleContent>
<restriction base="integer">
<minInclusive value="0" />
<maxInclusive value="4290000000" />
</restriction>
</simpleContent>
</complexType>
<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>
<complexType name="StringBasedCommentType">
<simpleContent>
<restriction base="string">
<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>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>
</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>11</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.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.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.DataGraph;
import commonj.sdo.DataObject;
import commonj.sdo.Property;
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)
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 stringBasedCommentType = typeHelper.getType(SEVFactoryImpl.NAMESPACE_URI, "StringBasedCommentType"); 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; simpleFeature = extendedMetaData.getSimpleFeature((EClass) stringBasedCommentType); commentSimpleType = (EDataType)simpleFeature.getEType(); assertEquals(40, extendedMetaData.getMaxLengthFacet(commentSimpleType)); // 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)); }public void testComplexTypeWithSimpleContentExtensionChangeSummary() 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)); 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); }}
STACKTRACE:
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Value '' is not legal. (file:///C:/development/working/1/tuscany-sdo/sdo/tools-test/all.datagraph, 27, 48)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:83)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:193)
at org.apache.tuscany.sdo.util.DataGraphResourceFactoryImpl$DataGraphResourceImpl$LoadImpl.load(DataGraphResourceFactoryImpl.java:455)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:179)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1094)
at org.apache.tuscany.sdo.helper.SDOHelperImpl.loadDataGraph(SDOHelperImpl.java:139)
at org.apache.tuscany.sdo.helper.SDOHelperImpl.loadDataGraph(SDOHelperImpl.java:157)
at org.apache.tuscany.sdo.api.SDOUtil.loadDataGraph(SDOUtil.java:150)
at org.apache.tuscany.sdo.test.SubstitutionWithExtensionValuesTestCase.testComplexTypeWithSimpleContentExtensionChangeSummary(SubstitutionWithExtensionValuesTestCase.java:150)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.eclipse.emf.ecore.xmi.IllegalValueException: Value '' is not legal. (file:///C:/development/working/1/tuscany-sdo/sdo/tools-test/all.datagraph, 27, 48)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2421)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2406)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.endElement(XMLHandler.java:1347)
at org.apache.tuscany.sdo.util.DataGraphResourceFactoryImpl$DataGraphResourceImpl$LoadImpl$1.endElement(DataGraphResourceFactoryImpl.java:627)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:633)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:221)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:322)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1693)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:183)
... 23 more
Caused by: java.lang.NumberFormatException: Zero length BigInteger
at java.math.BigInteger.<init>(BigInteger.java:275)
at java.math.BigInteger.<init>(BigInteger.java:447)
at org.eclipse.emf.ecore.xml.type.impl.XMLTypeFactoryImpl.createInteger(XMLTypeFactoryImpl.java:832)
at org.apache.tuscany.sdo.model.impl.ModelFactoryImpl.createIntegerFromString(ModelFactoryImpl.java:2086)
at com.example.substitution.ev.impl.SEVFactoryImpl.create_Integer32BitFromString(SEVFactoryImpl.java:754)
at com.example.substitution.ev.impl.SEVFactoryImpl.createFromString(SEVFactoryImpl.java:143)
at org.apache.tuscany.sdo.impl.FactoryBase$SDOEFactoryImpl.createFromString(FactoryBase.java:286)
at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createFromString(XMLHelperImpl.java:1489)
at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.setValue(XMLHelperImpl.java:1053)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setFeatureValue(XMLHandler.java:2416)
... 37 more
SAVED PROBLEMATIC DATA GRAPH
<?xml version="1.0" encoding="ASCII"?>
<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sdo="commonj.sdo"
xmlns:sdo_1="http://www.apache.org/tuscany/2005/SDO" xmlns:sev="http://www.example.com/substitutionEV"
xmlns:sev2="http://www.example.com/substitutionEV2">
<changeSummary xmlns=""
logging="true">
<objectChanges key="#//@eRootObject/@results.1">
<value xsi:type="sdo_1:ChangeSummarySetting" featureName="resultGroup">
<listChanges index="0">
<featureMapEntryValues featureName="myResult" referenceValue="#//@eChangeSummary/@objectsToAttach.0"/>
</listChanges>
</value>
</objectChanges>
<objectChanges key="#//@eChangeSummary/@objectsToAttach.0">
<value xsi:type="sdo_1:ChangeSummarySetting" featureName="value" set="false"
referenceValue="#//@eChangeSummary/@objectsToAttach.1"/>
<value xsi:type="sdo_1:ChangeSummarySetting" featureName="id" dataValue="BBBBBBBBBBBBBBBBBBBB"
set="false"/>
<value xsi:type="sdo_1:ChangeSummarySetting" featureName="name" dataValue="myNameB"
set="false"/>
</objectChanges>
<objectChanges key="#//@eChangeSummary/@objectsToAttach.1">
<value xsi:type="sdo_1:ChangeSummarySetting" featureName="value" dataValue="11"
set="false"/>
</objectChanges>
<objectsToAttach xsi:type="sev:MyResultType"/>
<objectsToAttach xsi:type="sev:ValueType"/>
</changeSummary>
<sev2:AllResultsType>
<id>ZZZZZZZZZZZZZZZZZZZZ</id>
<results>
<id>00000000000000000000</id>
<sev:result>
<id>11111111111111111111</id>
<name>name1</name>
<value>1</value>
</sev:result>
<sev:myResult>
<id>22222222222222222222</id>
<name>myName2</name>
<value>2</value>
</sev:myResult>
<comment>comment0</comment>
</results>
<results>
<id>AAAAAAAAAAAAAAAAAAAA</id>
<comment>commentA</comment>
</results>
<comment language="English">
commentZZZZZZZZZZZZZZZZZZ
</comment>
</sev2:AllResultsType>
</sdo:datagraph>