You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2007/03/14 21:41:31 UTC

svn commit: r518315 - /xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java

Author: mrglavas
Date: Wed Mar 14 13:41:31 2007
New Revision: 518315

URL: http://svn.apache.org/viewvc?view=rev&rev=518315
Log:
Fixing JIRA Bug #1240:
http://issues.apache.org/jira/browse/XERCESJ-1240

If one (or more) of the choices is an empty sequence the CMBuilder needs to wrap the choice 
node (i.e. XSCMBinOp) in a zero-or-one (optional) node so that the content model produced will 
allow the empty sequence. This was only working for one special case: a choice between an
empty sequence and one non-empty particle. 

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java?view=diff&rev=518315&r1=518314&r2=518315
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/models/CMBuilder.java Wed Mar 14 13:41:31 2007
@@ -170,32 +170,27 @@
             // </choice>
             // ) we can't not return that one particle ("e"). instead, we should
             // treat such particle as optional ("e?").
-            // the following boolean variable is true when there are at least
-            // 2 non-empty children.
-            boolean twoChildren = false;
+            // the following int variable keeps track of the number of non-empty children
+            int count = 0;
             for (int i = 0; i < group.fParticleCount; i++) {
                 // first convert each child to a CM tree
                 temp = buildSyntaxTree(group.fParticles[i]);
                 // then combine them using binary operation
                 if (temp != null) {
+                    ++count;
                     if (nodeRet == null) {
                         nodeRet = temp;
                     }
                     else {
                         nodeRet = fNodeFactory.getCMBinOpNode(group.fCompositor, nodeRet, temp);
-                        // record the fact that there are at least 2 children
-                        twoChildren = true;
                     }
                 }
             }
             // (task 2) expand occurrence values
             if (nodeRet != null) {
-                // when the group is "choice", there is only one non-empty
-                // child, and the group had more than one children, we need
-                // to create a zero-or-one (optional) node for the non-empty
-                // particle.
-                if (group.fCompositor == XSModelGroupImpl.MODELGROUP_CHOICE &&
-                    !twoChildren && group.fParticleCount > 1) {
+                // when the group is "choice" and the group has one or more empty children, 
+                // we need to create a zero-or-one (optional) node for the non-empty particles.
+                if (group.fCompositor == XSModelGroupImpl.MODELGROUP_CHOICE && count < group.fParticleCount) {
                     nodeRet = fNodeFactory.getCMUniOpNode(XSParticleDecl.PARTICLE_ZERO_OR_ONE, nodeRet);
                 }
                 nodeRet = expandContentModel(nodeRet, minOccurs, maxOccurs);
@@ -334,31 +329,26 @@
                 // </choice>
                 // ) we can't not return that one particle ("e"). instead, we should
                 // treat such particle as optional ("e?").
-                // the following boolean variable is true when there are at least
-                // 2 non-empty children.
-                boolean twoChildren = false;
+                // the following int variable keeps track of the number of non-empty children
+                int count = 0;
                 for (int i = 0; i < group.fParticleCount; i++) {
                     // first convert each child to a CM tree
                     temp = buildCompactSyntaxTree(group.fParticles[i]);
                     // then combine them using binary operation
                     if (temp != null) {
+                        ++count;
                         if (nodeRet == null) {
                             nodeRet = temp;
                         }
                         else {
                             nodeRet = fNodeFactory.getCMBinOpNode(group.fCompositor, nodeRet, temp);
-                            // record the fact that there are at least 2 children
-                            twoChildren = true;
                         }
                     }
                 }
                 if (nodeRet != null) {
-                    // when the group is "choice", there is only one non-empty
-                    // child, and the group had more than one children, we need
-                    // to create a zero-or-one (optional) node for the non-empty
-                    // particle.
-                    if (group.fCompositor == XSModelGroupImpl.MODELGROUP_CHOICE &&
-                        !twoChildren && group.fParticleCount > 1) {
+                    // when the group is "choice" and the group has one or more empty children, 
+                    // we need to create a zero-or-one (optional) node for the non-empty particles.
+                    if (group.fCompositor == XSModelGroupImpl.MODELGROUP_CHOICE && count < group.fParticleCount) {
                         nodeRet = fNodeFactory.getCMUniOpNode(XSParticleDecl.PARTICLE_ZERO_OR_ONE, nodeRet);
                     }
                 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org