Author: knoaman
Date: Tue Oct  7 14:41:07 2008
New Revision: 702646

URL: http://svn.apache.org/viewvc?rev=702646&view=rev
Log:
Multiple subsutition group heads - patch by John Chan

Modified:
    xerces/java/branches/xml-schema-1.1-dev/samples/xni/PSVIWriter.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SubstitutionGroupHandler.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSElementDeclaration.java

Modified: xerces/java/branches/xml-schema-1.1-dev/samples/xni/PSVIWriter.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/samples/xni/PSVIWriter.java?rev=702646&r1=702645&r2=702646&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/samples/xni/PSVIWriter.java 
(original)
+++ xerces/java/branches/xml-schema-1.1-dev/samples/xni/PSVIWriter.java Tue Oct 
 7 14:41:07 2008
@@ -1859,7 +1859,11 @@
             sendElementEvent("psv:substitutionGroupAffiliation");
         } else {
             sendIndentedElement("psv:substitutionGroupAffiliation");
-            processPSVIElementRef("psv:elementDeclaration", 
elem.getSubstitutionGroupAffiliation());
+            XSElementDeclaration[] subgroups = 
elem.getSubstitutionGroupAffiliation();
+            for (int i=0; i<subgroups.length; i++) {
+                XSElementDeclaration subgroup = subgroups[i];
+                processPSVIElementRef("psv:elementDeclaration", subgroup);
+            }
             sendUnIndentedElement("psv:substitutionGroupAffiliation");
         }
     }

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SubstitutionGroupHandler.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SubstitutionGroupHandler.java?rev=702646&r1=702645&r2=702646&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SubstitutionGroupHandler.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SubstitutionGroupHandler.java
 Tue Oct  7 14:41:07 2008
@@ -104,12 +104,8 @@
         }
 
         // 2.2 There is a chain of {substitution group affiliation}s from D to 
C, that is, either D's {substitution group affiliation} is C, or D's 
{substitution group affiliation}'s {substitution group affiliation} is C, or . 
. .
-        XSElementDecl subGroup = element.fSubGroup;
-        while (subGroup != null && subGroup != exemplar) {
-            subGroup = subGroup.fSubGroup;
-        }
-
-        if (subGroup == null) {
+        XSElementDecl[] subGroup = element.fSubGroup;
+        if (subGroup == null || !checkSubstitutionGroupAffil(subGroup, 
exemplar)) {
             return false;
         }
 
@@ -119,6 +115,18 @@
         return typeDerivationOK(element.fType, exemplar.fType, 
blockingConstraint);   
     }
     
+    // Recursively check if there is a element in substitution group matching 
exemplar
+    private boolean checkSubstitutionGroupAffil(XSElementDecl[] subGroupArray, 
XSElementDecl examplar) {
+        for (int i=0; i<subGroupArray.length; i++) {
+            XSElementDecl element = subGroupArray[i];
+            if (element == examplar) 
+                return true;
+            if (element.fSubGroup != null)
+                if (checkSubstitutionGroupAffil(element.fSubGroup, examplar)) 
return true;
+        }
+        return false;
+    }
+    
     private boolean typeDerivationOK(XSTypeDefinition derived, 
XSTypeDefinition base, short blockingConstraint) {
         
         short devMethod = 0, blockConstraint = blockingConstraint;
@@ -199,22 +207,27 @@
     /**
      * add a list of substitution group information.
      */
-    public void addSubstitutionGroup(XSElementDecl[] elements) {
-        XSElementDecl subHead, element;
+    public void addSubstitutionGroup(XSElementDecl[] elements) {        
+        XSElementDecl element;
+        XSElementDecl[] subHeads;
         Vector subGroup;
         // for all elements with substitution group affiliation
         for (int i = elements.length-1; i >= 0; i--) {
             element = elements[i];
-            subHead = element.fSubGroup;
+            subHeads = element.fSubGroup;
+
             // check whether this an entry for this element
-            subGroup = (Vector)fSubGroupsB.get(subHead);
-            if (subGroup == null) {
-                // if not, create a new one
-                subGroup = new Vector();
-                fSubGroupsB.put(subHead, subGroup);
+            for (int j=0; j<subHeads.length; j++) {
+                XSElementDecl subHead = subHeads[j];
+                subGroup = (Vector)fSubGroupsB.get(subHead);
+                if (subGroup == null) {
+                    // if not, create a new one
+                    subGroup = new Vector();
+                    fSubGroupsB.put(subHead, subGroup);
+                }
+                // add to the vector
+                subGroup.addElement(element);
             }
-            // add to the vactor
-            subGroup.addElement(element);
         }
     }
 

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java?rev=702646&r1=702645&r2=702646&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSElementDecl.java
 Tue Oct  7 14:41:07 2008
@@ -68,8 +68,8 @@
     public XSObjectList fAnnotations = null;
     // value constraint value
     public ValidatedInfo fDefault = null;
-    // the substitution group affiliation of the element
-    public XSElementDecl fSubGroup = null;
+    // the substitution groups affiliation of the element
+    public XSElementDecl[] fSubGroup = null;
     // identity constraints
     static final int INITIAL_SIZE = 2;
     int fIDCPos = 0;
@@ -137,14 +137,14 @@
      * has no test attribute)
      */
     public boolean isTypeTableOK() {
-       if (fTypeAlternativePos > 1) {
-               for (int i=0; i<fTypeAlternativePos-1; i++) {
-                       if (fTypeAlternatives[i].getTest() == null) {
-                               return false;
-                       }
-               }
-       }
-       return true;
+        if (fTypeAlternativePos > 1) {
+            for (int i=0; i<fTypeAlternativePos-1; i++) {
+                if (fTypeAlternatives[i].getTest() == null) {
+                    return false;
+                }
+            }
+        }
+        return true;
     }
 
     public void addTypeAlternative(XSTypeAlternativeImpl typeAlternative) {
@@ -345,7 +345,7 @@
      * {substitution group affiliation} Optional. A top-level element
      * definition.
      */
-    public XSElementDeclaration getSubstitutionGroupAffiliation() {
+    public XSElementDeclaration[] getSubstitutionGroupAffiliation() {
         return fSubGroup;
     }
 

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java?rev=702646&r1=702645&r2=702646&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
 Tue Oct  7 14:41:07 2008
@@ -1385,14 +1385,35 @@
                         oneAttr.dvIndex != DT_XPATH &&
                         oneAttr.dvIndex != DT_XPATH1) {
                         XSSimpleType dv = fExtraDVs[oneAttr.dvIndex];
-                        Object avalue = dv.validate(attrVal, 
schemaDoc.fValidationContext, null);
-                        // kludge to handle chameleon includes/redefines...
-                        if (oneAttr.dvIndex == DT_QNAME) {
-                            QName qname = (QName)avalue;
-                            if(qname.prefix == XMLSymbols.EMPTY_STRING && 
qname.uri == null && schemaDoc.fIsChameleonSchema)
-                                qname.uri = schemaDoc.fTargetNamespace;
+
+                        // if version 1.1 and attr is subgroup, split the 
attrVal String and perform validation on each subgroup head
+                        // will end up with multiple avalue                    
                              
+                        if (oneAttr.valueIndex == ATTIDX_SUBSGROUP) {
+                            if (attrValues[ATTIDX_SUBSGROUP] == null) {
+                                attrValues[ATTIDX_SUBSGROUP] = new Vector();
+                            }
+                            if 
(fSchemaHandler.fSchemaVersion==Constants.SCHEMA_VERSION_1_1) {
+                                StringTokenizer st = new 
StringTokenizer(attrVal, " ");
+                                while (st.hasMoreTokens()) {
+                                    Object avalue = 
dv.validate(st.nextToken(), schemaDoc.fValidationContext, null);
+                                    
((Vector)attrValues[ATTIDX_SUBSGROUP]).addElement(avalue);
+                                }
+                            }
+                            else {
+                                Object avalue = dv.validate(attrVal, 
schemaDoc.fValidationContext, null);
+                                
((Vector)attrValues[ATTIDX_SUBSGROUP]).addElement(avalue);
+                            }
+                        }
+                        else {
+                            Object avalue = dv.validate(attrVal, 
schemaDoc.fValidationContext, null);
+                            // kludge to handle chameleon includes/redefines...
+                            if (oneAttr.dvIndex == DT_QNAME) {
+                                QName qname = (QName)avalue;
+                                if(qname.prefix == XMLSymbols.EMPTY_STRING && 
qname.uri == null && schemaDoc.fIsChameleonSchema)
+                                    qname.uri = schemaDoc.fTargetNamespace;
+                            }
+                            attrValues[oneAttr.valueIndex] = avalue;
                         }
-                        attrValues[oneAttr.valueIndex] = avalue;
                     } else {
                         attrValues[oneAttr.valueIndex] = attrVal;
                     }
@@ -1990,6 +2011,9 @@
         // better clear nonschema vector
         if(attrArray[ATTIDX_NONSCHEMA] != null)
             ((Vector)attrArray[ATTIDX_NONSCHEMA]).clear();
+        // clear the subsgroup vector
+        if(attrArray[ATTIDX_SUBSGROUP] != null)
+            ((Vector)attrArray[ATTIDX_SUBSGROUP]).clear();
         // and put it into the pool
         fArrayPool[--fPoolPos] = attrArray;
     }

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java?rev=702646&r1=702645&r2=702646&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
 Tue Oct  7 14:41:07 2008
@@ -17,6 +17,8 @@
 
 package org.apache.xerces.impl.xs.traversers;
 
+import java.util.Vector;
+
 import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.dv.ValidatedInfo;
 import org.apache.xerces.impl.dv.XSSimpleType;
@@ -266,7 +268,7 @@
         XInt    formAtt      = (XInt)    
attrValues[XSAttributeChecker.ATTIDX_FORM];
         String  nameAtt      = (String)  
attrValues[XSAttributeChecker.ATTIDX_NAME];
         Boolean nillableAtt  = (Boolean) 
attrValues[XSAttributeChecker.ATTIDX_NILLABLE];
-        QName   subGroupAtt  = (QName)   
attrValues[XSAttributeChecker.ATTIDX_SUBSGROUP];
+        Vector  subGroupAtt  = (Vector)  
attrValues[XSAttributeChecker.ATTIDX_SUBSGROUP];
         QName   typeAtt      = (QName)   
attrValues[XSAttributeChecker.ATTIDX_TYPE];
         
         // Step 1: get declaration information
@@ -326,12 +328,26 @@
         } else {
             element.setConstraintType(XSConstants.VC_NONE);
         }
-        
+
         // get 'substitutionGroup affiliation'
-        if (subGroupAtt != null) {
-            element.fSubGroup = 
(XSElementDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ELEMENT_TYPE, 
subGroupAtt, elmDecl);
+        if (subGroupAtt != null && !subGroupAtt.isEmpty()) {
+            Vector elemDecl = new Vector();
+            for (int i=0; i<subGroupAtt.size(); i++) {
+                QName subGroup = (QName)subGroupAtt.get(i);
+
+                // returns null if element is already parsed
+                XSElementDecl globalDecl = 
(XSElementDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ELEMENT_TYPE, 
subGroup, elmDecl);
+                if (globalDecl != null) {
+                    elemDecl.add(globalDecl);
+                }
+            }
+
+            int validSubgroupElemDeclSize = elemDecl.size();
+            if (validSubgroupElemDeclSize > 0) {
+                element.fSubGroup = (XSElementDecl[])elemDecl.toArray(new 
XSElementDecl[validSubgroupElemDeclSize]);
+            }
         }
-        
+
         // get 'annotation'
         Element child = DOMUtil.getFirstChildElement(elmDecl);
         XSAnnotationImpl annotation = null;
@@ -382,7 +398,7 @@
         
         // Get it from the substitutionGroup declaration
         if (elementType == null && element.fSubGroup != null) {
-            elementType = element.fSubGroup.fType;
+            elementType = element.fSubGroup[0].fType;
         }
         
         if (elementType == null) {
@@ -501,8 +517,10 @@
         
         // 4 If there is an {substitution group affiliation}, the {type 
definition} of the element declaration must be validly derived from the {type 
definition} of the {substitution group affiliation}, given the value of the 
{substitution group exclusions} of the {substitution group affiliation}, as 
defined in Type Derivation OK (Complex) (3.4.6) (if the {type definition} is 
complex) or as defined in Type Derivation OK (Simple) (3.14.6) (if the {type 
definition} is simple).
         if (element.fSubGroup != null) {
-            if 
(!fSchemaHandler.fXSConstraints.checkTypeDerivationOk(element.fType, 
element.fSubGroup.fType, element.fSubGroup.fFinal)) {
-                reportSchemaError ("e-props-correct.4", new Object[]{nameAtt, 
subGroupAtt.prefix+":"+subGroupAtt.localpart}, elmDecl);
+               for (int i=0; i< element.fSubGroup.length; i++) {
+                if 
(!fSchemaHandler.fXSConstraints.checkTypeDerivationOk(element.fType, 
element.fSubGroup[i].fType, element.fSubGroup[i].fFinal)) {
+                    reportSchemaError ("e-props-correct.4", new 
Object[]{nameAtt, ((QName)subGroupAtt.get(i)).prefix 
+":"+((QName)subGroupAtt.get(i)).localpart}, elmDecl);
+                }
             }
         }
         

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSElementDeclaration.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSElementDeclaration.java?rev=702646&r1=702645&r2=702646&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSElementDeclaration.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/XSElementDeclaration.java
 Tue Oct  7 14:41:07 2008
@@ -117,7 +117,7 @@
      * [substitution group affiliation]: a top-level element definition if it 
      * exists, otherwise <code>null</code>. 
      */
-    public XSElementDeclaration getSubstitutionGroupAffiliation();
+    public XSElementDeclaration[] getSubstitutionGroupAffiliation();
 
     /**
      * Convenience method that checks if <code>exclusion</code> is a 



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

Reply via email to