Details
Description
The build.xml ant script in the attached zip file:
1. generates a java object model from the following schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="SequenceOfChoice" type="SequenceOfChoice" abstract="false" nillable="false"/>
<xs:complexType name="SequenceOfChoice" abstract="false" mixed="false">
<xs:sequence maxOccurs="unbounded">
<xs:choice>
<xs:element name="ChoiceOne" type="xs:string" nillable="false"/>
<xs:element name="ChoiceTwo" type="xs:string" nillable="false"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:schema>
2. and then runs a JUnit test that asserts that the following valid instance of the schema given above can be unmarshalled:
<?xml version="1.0" encoding="UTF-8"?>
<SequenceOfChoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..\..\model-schema.xsd">
<ChoiceTwo>String</ChoiceTwo>
<ChoiceOne>String</ChoiceOne>
</SequenceOfChoice>
Unmarshalling fails and throws the following exception:
The container object (model.SequenceOfChoiceChoice) cannot accept the child object associated with the element 'ChoiceOne' because the container is already full!
{file: [not available]; line: 4; column: 16} at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:671)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:565)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:748)
at model.SequenceOfChoiceTest.testUnmarshalSequenceOfChoice(SequenceOfChoiceTest.java:48)
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:324)
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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Caused by: ValidationException: The container object (model.SequenceOfChoiceChoice) cannot accept the child object associated with the element 'ChoiceOne' because the container is already full!
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1667)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1338)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:657)
... 18 more
Caused by: ValidationException: The container object (model.SequenceOfChoiceChoice) cannot accept the child object associated with the element 'ChoiceOne' because the container is already full!
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1667)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1338)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:657)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:565)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:748)
at model.SequenceOfChoiceTest.testUnmarshalSequenceOfChoice(SequenceOfChoiceTest.java:48)
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:324)
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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Caused by: ValidationException: The container object (model.SequenceOfChoiceChoice) cannot accept the child object associated with the element 'ChoiceOne' because the container is already full!
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1667)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1338)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:657)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:565)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:748)
at model.SequenceOfChoiceTest.testUnmarshalSequenceOfChoice(SequenceOfChoiceTest.java:48)
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:324)
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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Issue Links
- is related to
-
CASTOR-1601
Problem deriving type name in 'type' mode ....
-
1. |
Problem deriving type name in 'type' mode .... | |
|
Werner Guttmann |
|
|||||||
2. |
Additional cleanup | |
|
Werner Guttmann | ||||||||
3. |
Expose isChoice() method at XMLClassDescriptor | |
|
Unassigned |
|
A solution to this problem is to move the maxOccurs="unbounded" from the xsd:sequence to the xsd:choice. This also eliminates the need for the xsd:sequence, unless you are going to put other elements into the sequence.
<xs:complexType name="SequenceOfChoice" abstract="false" mixed="false">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="ChoiceOne" type="xs:string" nillable="false"/>
<xs:element name="ChoiceTwo" type="xs:string" nillable="false"/>
</xs:choice>
</xs:sequence>
</xs:complexType>