Author: jochen
Date: Fri Aug 12 13:22:29 2005
New Revision: 232370

URL: http://svn.apache.org/viewcvs?rev=232370&view=rev
Log:
The ChoiceHandlerSG did not treat a choice
with minOccurs="0" as optional.
PR: JAXME-65

Added:
    webservices/jaxme/branches/b0_5/src/test/jaxb/jira/jaxme-65.xsd
Modified:
    
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/AllHandlerSG.java
    
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/ChoiceHandlerSG.java
    
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java
    
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SequenceHandlerSG.java
    
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java
    webservices/jaxme/branches/b0_5/status.xml

Modified: 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/AllHandlerSG.java
URL: 
http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/AllHandlerSG.java?rev=232370&r1=232369&r2=232370&view=diff
==============================================================================
--- 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/AllHandlerSG.java
 (original)
+++ 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/AllHandlerSG.java
 Fri Aug 12 13:22:29 2005
@@ -52,9 +52,9 @@
        }
 
        AllHandlerSG(GroupHandlerSG pOuterHandler, ComplexTypeSG pType,
-                                GroupSG pGroup, JavaSource pJs)
+                                ParticleSG pParticle, JavaSource pJs)
                        throws SAXException {
-               super(pOuterHandler, pType, pGroup, pJs);
+               super(pOuterHandler, pType, pParticle, pJs);
        }
 
        protected int getState(int pParticleNum) { return pParticleNum; }

Modified: 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/ChoiceHandlerSG.java
URL: 
http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/ChoiceHandlerSG.java?rev=232370&r1=232369&r2=232370&view=diff
==============================================================================
--- 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/ChoiceHandlerSG.java
 (original)
+++ 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/ChoiceHandlerSG.java
 Fri Aug 12 13:22:29 2005
@@ -19,7 +19,6 @@
 
 import org.apache.ws.jaxme.ValidationEvents;
 import org.apache.ws.jaxme.generator.sg.ComplexTypeSG;
-import org.apache.ws.jaxme.generator.sg.GroupSG;
 import org.apache.ws.jaxme.generator.sg.ParticleSG;
 import org.apache.ws.jaxme.impl.JMUnmarshallerHandlerImpl;
 import org.apache.ws.jaxme.js.DirectAccessible;
@@ -49,9 +48,9 @@
        }
 
        ChoiceHandlerSG(GroupHandlerSG pOuterHandler, ComplexTypeSG pType,
-                                       GroupSG pGroup, JavaSource pJs)
+                                       ParticleSG pParticle, JavaSource pJs)
                        throws SAXException {
-               super(pOuterHandler, pType, pGroup, pJs);
+               super(pOuterHandler, pType, pParticle, pJs);
        }
 
        protected int getState(int pParticleNum) { return pParticleNum; }
@@ -111,13 +110,7 @@
 
        public JavaMethod newIsFinishedMethod() throws SAXException {
                JavaMethod result = super.newIsFinishedMethod();
-               Object o = getStateField();
-               for (int i = 0;  i < particles.length;  i++) {
-                       if (!isRequiredParticle(particles[i])) {
-                               o = "true";
-                               break;
-                       }
-               }
+               Object o = isRequiredParticle(particle) ? (Object) 
getStateField() : "true";
                result.addLine("return ", o, ";");
                return result;
        }

Modified: 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java
URL: 
http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java?rev=232370&r1=232369&r2=232370&view=diff
==============================================================================
--- 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java
 (original)
+++ 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java
 Fri Aug 12 13:22:29 2005
@@ -58,6 +58,7 @@
  */
 public abstract class GroupHandlerSG extends HandlerSGImpl {
        protected final ComplexContentSG ccSG;
+       protected final ParticleSG particle;
        protected final GroupSG group;
        protected final ParticleSG[] particles;
        private final Map groups = new HashMap();
@@ -73,7 +74,8 @@
                super(pType, pJs);
                outerHandler = this;
                ccSG = pType.getComplexContentSG();
-               group = ccSG.getRootParticle().getGroupSG();
+               particle = ccSG.getRootParticle();
+               group = particle.getGroupSG();
                particles = group.getParticles();
                isMixed = ccSG.isMixed();
                findGroups(particles);
@@ -84,15 +86,16 @@
         * fields to the Java class <code>pJs</code>.
         */
        protected GroupHandlerSG(GroupHandlerSG pOuterHandler, ComplexTypeSG 
pType,
-                                                        GroupSG pGroup, 
JavaSource pJs) throws SAXException {
+                                                        ParticleSG pParticle, 
JavaSource pJs) throws SAXException {
                super(pType, pJs);
                outerHandler = pOuterHandler;
                if (!pJs.isInnerClass()) {
                        throw new IllegalStateException("Expected inner class");
                }
                ccSG = null;
-               group = pGroup;
-               particles = pGroup.getParticles();
+               particle = pParticle;
+               group = particle.getGroupSG();
+               particles = group.getParticles();
                isMixed = pType.getComplexContentSG().isMixed();
                findGroups(particles);
        }
@@ -110,24 +113,25 @@
                return (GroupHandlerSG) groups.get(pGroup);
        }
 
-       private GroupHandlerSG newGroupHandlerSG(GroupSG pGroup, String pName) 
throws SAXException {
+       private GroupHandlerSG newGroupHandlerSG(ParticleSG pParticle, String 
pName) throws SAXException {
                JavaSource js = getJavaSource();
                JavaInnerClass jic = js.newJavaInnerClass(pName, 
JavaSource.PUBLIC);
                jic.addExtends(JMSAXGroupParser.class);
-               if (pGroup.isSequence()) {
-                       return new SequenceHandlerSG(outerHandler, ctSG, 
pGroup, jic);
-               } else if (pGroup.isChoice()) {
-                       return new ChoiceHandlerSG(outerHandler, ctSG, pGroup, 
jic);
-               } else if (pGroup.isAll()) {
-                       return new AllHandlerSG(outerHandler, ctSG, pGroup, 
jic);
+               GroupSG group = pParticle.getGroupSG();
+               if (group.isSequence()) {
+                       return new SequenceHandlerSG(outerHandler, ctSG, 
pParticle, jic);
+               } else if (group.isChoice()) {
+                       return new ChoiceHandlerSG(outerHandler, ctSG, 
pParticle, jic);
+               } else if (group.isAll()) {
+                       return new AllHandlerSG(outerHandler, ctSG, pParticle, 
jic);
                } else {
                        throw new IllegalStateException("Invalid group type");
                }
        }
 
-       private GroupHandlerSG newGroupHandlerSG(GroupSG pGroup) throws 
SAXException {
+       private GroupHandlerSG newGroupHandlerSG(ParticleSG pParticle) throws 
SAXException {
                JavaSource js = getJavaSource();
-               String name = GroupUtil.getGroupName(pGroup);
+               String name = GroupUtil.getGroupName(pParticle.getGroupSG());
                for (int i = 0;  ;  i++) {
                        String n = name;
                        if (i > 0) {
@@ -135,7 +139,7 @@
                        }
                        n += "Handler";
                        if (js.getInnerClass(n) == null) {
-                               GroupHandlerSG result = 
newGroupHandlerSG(pGroup, n);
+                               GroupHandlerSG result = 
newGroupHandlerSG(pParticle, n);
                                result.newGetHandlerMethod(js);
                                return result;
                        }
@@ -156,7 +160,7 @@
                        if (particle.isGroup()) {
                                GroupSG group = particle.getGroupSG();
                                if (!groups.containsKey(group)) {
-                                       GroupHandlerSG handler = 
newGroupHandlerSG(group);
+                                       GroupHandlerSG handler = 
newGroupHandlerSG(particle);
                                        groups.put(group, handler);
                                }
                        } else if (particle.isElement()) {

Modified: 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SequenceHandlerSG.java
URL: 
http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SequenceHandlerSG.java?rev=232370&r1=232369&r2=232370&view=diff
==============================================================================
--- 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SequenceHandlerSG.java
 (original)
+++ 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SequenceHandlerSG.java
 Fri Aug 12 13:22:29 2005
@@ -44,9 +44,9 @@
        }
 
        SequenceHandlerSG(GroupHandlerSG pOuterHandler, ComplexTypeSG pTypeSG,
-                                         GroupSG pGroup, JavaSource pJs)
+                                         ParticleSG pParticle, JavaSource pJs)
                        throws SAXException {
-               super(pOuterHandler, pTypeSG, pGroup, pJs);
+               super(pOuterHandler, pTypeSG, pParticle, pJs);
        }
 
        protected DirectAccessible getEndElementState() throws SAXException {

Modified: 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java
URL: 
http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java?rev=232370&r1=232369&r2=232370&view=diff
==============================================================================
--- 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java
 (original)
+++ 
webservices/jaxme/branches/b0_5/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java
 Fri Aug 12 13:22:29 2005
@@ -2,6 +2,7 @@
 
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.util.List;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
@@ -21,6 +22,8 @@
 import org.apache.ws.jaxme.generator.sg.SchemaSG;
 import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader;
 import org.apache.ws.jaxme.generator.util.JavaNamer;
+import org.apache.ws.jaxme.test.jira.jaxme65.Jaxme65;
+import org.apache.ws.jaxme.test.jira.jaxme65.Jaxme65Type;
 import org.apache.ws.jaxme.test.misc.types.Jira62;
 import org.apache.ws.jaxme.test.misc.types.Row;
 import org.apache.ws.jaxme.test.misc.types.impl.RowImpl;
@@ -62,10 +65,12 @@
         unmarshalMarshalUnmarshal(TransmissionData.class, input2);
         final String input3 =
             "<TransmissionData mail-id=\"[EMAIL PROTECTED]" 
xmlns=\"http://commons.dspc.net/activitymodel\";>\n" +
-            "  <sender account-id=\"[EMAIL PROTECTED]" name=\"Joe 
Tester\"/>\n" +
+            "  <sender account-id=\"[EMAIL PROTECTED]" name=\"Joe Tester\">\n" 
+
+            "    <phone>0793041414141</phone>\n" +
+            "  </sender>\n" +
             "  <recipient account-id=\"[EMAIL PROTECTED]" name=\"Henrik 
Vendelbo\"/>\n" +
             "</TransmissionData>";
-        unmarshalMarshalUnmarshal(TransmissionData.class, input2);
+        unmarshalMarshalUnmarshal(TransmissionData.class, input3);
     }
 
     /** Test for <a 
href="http://issues.apache.org/jira/browse/JAXME-12";>JAXME-12</a>
@@ -229,5 +234,27 @@
                } catch (SAXException e) {
                        assertTrue(e.getMessage().indexOf("Model groups with 
maxOccurs > 1 are not yet supported.") != -1);
                }
+       }
+
+       /** Test for <a 
href="http://issues.apache.org/jira/browse/JAXME-65";>JAXME-65</a>.
+        */
+       public void testJAXME65() throws Exception {
+               final String xml1 =
+                       "<jaxme65 
xmlns='http://ws.apache.org/jaxme/test/jira/jaxme65'>some text<problem>here it 
is</problem>more text</jaxme65>";
+               Jaxme65 text1 = (Jaxme65) 
getJAXBContext(Jaxme65.class).createUnmarshaller().unmarshal(new 
InputSource(new StringReader(xml1)));
+               List list1 = text1.getContent();
+               assertEquals(3, list1.size());
+               assertEquals("some text", list1.get(0));
+               Object o = list1.get(1);
+               assertTrue(o instanceof Jaxme65Type.Problem);
+               Jaxme65Type.Problem problem = (Jaxme65Type.Problem) o;
+               assertEquals("here it is", problem.getValue());
+               assertEquals("more text", list1.get(2));
+               final String xml2 =
+                       "<jaxme65 
xmlns='http://ws.apache.org/jaxme/test/jira/jaxme65'>some text</jaxme65>";
+               Jaxme65 text2 = (Jaxme65) 
getJAXBContext(Jaxme65.class).createUnmarshaller().unmarshal(new 
InputSource(new StringReader(xml2)));
+               List list2 = text2.getContent();
+               assertEquals(1, list2.size());
+               assertEquals("some text", list2.get(0));
        }
 }

Added: webservices/jaxme/branches/b0_5/src/test/jaxb/jira/jaxme-65.xsd
URL: 
http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/src/test/jaxb/jira/jaxme-65.xsd?rev=232370&view=auto
==============================================================================
--- webservices/jaxme/branches/b0_5/src/test/jaxb/jira/jaxme-65.xsd (added)
+++ webservices/jaxme/branches/b0_5/src/test/jaxb/jira/jaxme-65.xsd Fri Aug 12 
13:22:29 2005
@@ -0,0 +1,15 @@
+<xs:schema targetNamespace='http://ws.apache.org/jaxme/test/jira/jaxme65'
+       elementFormDefault='qualified'
+       xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+  <xs:element name='jaxme65'>
+    <xs:complexType mixed='true'>
+      <xs:choice minOccurs='0' maxOccurs='1'>
+        <xs:element name='problem' type='xs:string'/>
+        <xs:element name='reason' type='xs:string'/>
+        <xs:element name='solution' type='xs:string'/>
+      </xs:choice>
+      <xs:attribute name='id' type='xs:string'/>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>
+

Modified: webservices/jaxme/branches/b0_5/status.xml
URL: 
http://svn.apache.org/viewcvs/webservices/jaxme/branches/b0_5/status.xml?rev=232370&r1=232369&r2=232370&view=diff
==============================================================================
--- webservices/jaxme/branches/b0_5/status.xml (original)
+++ webservices/jaxme/branches/b0_5/status.xml Fri Aug 12 13:22:29 2005
@@ -36,6 +36,10 @@
         methods signature.
                (Frederic Ahring, fahring at de.ibm.com)
       </action>
+      <action dev="JW" type="fix" context="generator">
+        The ChoiceHandlerSG did not treat a choice
+        with minOccurs="0" as optional. (JAXME-65)
+      </action>
     </release>
        <release version="0.5" date="2005-Aug-08">
       <action dev="JW" type="enhancement" context="js">



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

Reply via email to