Author: knoaman
Date: Tue Oct  7 13:36:30 2008
New Revision: 702620

URL: http://svn.apache.org/viewvc?rev=702620&view=rev
Log:
Refactor wildcard constraint checking. Move isSubsetOf, performIntersectionWith 
and perfromUnionWith to XSConstraints.

Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS10Constraints.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS10Constraints.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS10Constraints.java?rev=702620&r1=702619&r2=702620&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS10Constraints.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS10Constraints.java
 Tue Oct  7 13:36:30 2008
@@ -25,7 +25,7 @@
  * @author Sandy Gao, IBM
  * @author Khaled Noaman, IBM
  *
- * @version $Id:$
+ * @version $Id$
  *
  */
 class XS10Constraints extends XSConstraints {
@@ -54,7 +54,7 @@
     public boolean overlapUPA(XSWildcardDecl wildcard1,
             XSWildcardDecl wildcard2) {
         // if the intersection of the two wildcard is not empty list
-        XSWildcardDecl intersect = 
wildcard1.performIntersectionWith(wildcard2, wildcard1.fProcessContents);
+        XSWildcardDecl intersect = performIntersectionWith(wildcard1, 
wildcard2, wildcard1.fProcessContents);
         if (intersect == null ||
                 intersect.fType != XSWildcardDecl.NSCONSTRAINT_LIST ||
                 intersect.fNamespaceList.length != 0) {

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java?rev=702620&r1=702619&r2=702620&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XS11Constraints.java
 Tue Oct  7 13:36:30 2008
@@ -24,7 +24,7 @@
  *
  * @author Khaled Noaman, IBM
  *
- * @version $Id:$
+ * @version $Id$
  *
  */
 class XS11Constraints extends XSConstraints {
@@ -43,7 +43,7 @@
             XSWildcardDecl wildcard2) {
         // if the intersection of the two wildcards is not any and
        // and the {namespaces} of such intersection is not the empty set
-        XSWildcardDecl intersect = 
wildcard1.performIntersectionWith(wildcard2, wildcard1.fProcessContents);
+        XSWildcardDecl intersect = performIntersectionWith(wildcard1, 
wildcard2, wildcard1.fProcessContents);
         if (intersect.fType != XSWildcardDecl.NSCONSTRAINT_ANY &&
                 intersect.fNamespaceList.length != 0) {
             return true;

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java?rev=702620&r1=702619&r2=702620&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java
 Tue Oct  7 13:36:30 2008
@@ -187,7 +187,6 @@
                                        return errorArgs;
                 }
 
-
                 //
                 // derivation-ok-restriction.  Constraint 2.1.3
                 //
@@ -268,7 +267,7 @@
                                errorArgs = new Object[]{typeName, 
"derivation-ok-restriction.4.1"};
                                return errorArgs;
             }
-            if (! fAttributeWC.isSubsetOf(baseGroup.fAttributeWC)) {
+            if (! xsConstraints.isSubsetOf(fAttributeWC, 
baseGroup.fAttributeWC)) {
                                errorArgs = new Object[]{typeName, 
"derivation-ok-restriction.4.2"};
                                return errorArgs;
             }

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java?rev=702620&r1=702619&r2=702620&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
 Tue Oct  7 13:36:30 2008
@@ -1136,7 +1136,7 @@
     } // checkIDConstraintRestriction
 
 
-    private static boolean checkOccurrenceRange(int min1, int max1, int min2, 
int max2) {
+    private boolean checkOccurrenceRange(int min1, int max1, int min2, int 
max2) {
 
         if ((min1 >= min2) &&
                 ((max2==SchemaSymbols.OCCURRENCE_UNBOUNDED) ||
@@ -1146,7 +1146,7 @@
             return false;
     }
 
-    private static void checkNSCompat(XSElementDecl elem, int min1, int max1,
+    private void checkNSCompat(XSElementDecl elem, int min1, int max1,
             XSWildcardDecl wildcard, int min2, int max2,
             boolean checkWCOccurrence)
         throws XMLSchemaException {
@@ -1170,7 +1170,7 @@
 
     }
 
-    private static void checkNSSubset(XSWildcardDecl dWildcard, int min1, int 
max1,
+    private void checkNSSubset(XSWildcardDecl dWildcard, int min1, int max1,
             XSWildcardDecl bWildcard, int min2, int max2)
         throws XMLSchemaException {
 
@@ -1184,7 +1184,7 @@
         }
 
         // check wildcard subset
-        if (!dWildcard.isSubsetOf(bWildcard)) {
+        if (!isSubsetOf(dWildcard, bWildcard)) {
             throw new XMLSchemaException("rcase-NSSubset.1", null);
         }
 
@@ -1480,6 +1480,371 @@
         }
     }
 
+    // TODO: define as abstract methods
+    
+    /**
+     * Wildcard constraints
+     */
+
+    /**
+     *  Schema Component Constraint: Wildcard Subset
+     *  
+     *  wildcard.isSubsetOf(superWildcard)
+     */
+    public boolean isSubsetOf(XSWildcardDecl wildcard, XSWildcardDecl 
superWildcard) {
+        // if the super is null (not expressible), return false
+        if (superWildcard == null) {
+            return false;
+        }
+
+        // For a namespace constraint (call it sub) to be an intensional 
subset of another
+        // namespace constraint (call it super) one of the following must be 
true:
+
+        // 1 super must be any.
+        if (superWildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) {
+            return true;
+        }
+
+        // 2 All of the following must be true:
+        //   2.1 sub must be a pair of not and a namespace name or absent.
+        //   2.2 super must be a pair of not and the same value.
+        //   * we can't just compare whether the namespace are the same value
+        //     since we store other as not(list)
+        if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
+            if (superWildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT &&
+                wildcard.fNamespaceList[0] == superWildcard.fNamespaceList[0]) 
{
+                return true;
+            }
+        }
+
+        // 3 All of the following must be true:
+        //   3.1 sub must be a set whose members are either namespace names or 
absent.
+        //   3.2 One of the following must be true:
+        //       3.2.1 super must be the same set or a superset thereof.
+        //       -3.2.2 super must be a pair of not and a namespace name or 
absent and
+        //              that value must not be in sub's set.
+        //       +3.2.2 super must be a pair of not and a namespace name or 
absent and
+        //              either that value or absent must not be in sub's set.
+        //       * since we store ##other as not(list), we acturally need to 
make sure
+        //         that none of the namespaces in super.list is in sub.list.
+        if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) {
+            if (superWildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST &&
+                subset2sets(wildcard.fNamespaceList, 
superWildcard.fNamespaceList)) {
+                return true;
+            }
+
+            if (superWildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT &&
+                !elementInSet(superWildcard.fNamespaceList[0], 
wildcard.fNamespaceList) &&
+                !elementInSet(XSWildcardDecl.ABSENT, wildcard.fNamespaceList)) 
{
+                return true;
+            }
+        }
+
+        // none of the above conditions applied, so return false.
+        return false;
+
+    } // isSubsetOf
+
+    /**
+     * Schema Component Constraint: Attribute Wildcard Union
+     */
+    public XSWildcardDecl performUnionWith(XSWildcardDecl wildcard,
+                                           XSWildcardDecl otherWildcard,
+                                           short processContents) {
+        // if the other wildcard is not expressible, the result is still not 
expressible
+        if (otherWildcard == null)
+            return null;
+
+        // For a wildcard's {namespace constraint} value to be the intensional 
union of two
+        // other such values (call them O1 and O2): the appropriate case among 
the following
+        // must be true:
+
+        XSWildcardDecl unionWildcard = new XSWildcardDecl();
+        unionWildcard.fProcessContents = processContents;
+
+        // 1 If O1 and O2 are the same value, then that value must be the 
value.
+        if (areSame(wildcard, otherWildcard)) {
+            unionWildcard.fType = wildcard.fType;
+            unionWildcard.fNamespaceList = wildcard.fNamespaceList;
+        }
+
+        // 2 If either O1 or O2 is any, then any must be the value.
+        else if ( (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) || 
(otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) ) {
+            unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_ANY;
+        }
+
+        // 3 If both O1 and O2 are sets of (namespace names or absent), then 
the union of
+        //   those sets must be the value.
+        else if ( (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) && 
(otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) ) {
+            unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_LIST;
+            unionWildcard.fNamespaceList = union2sets(wildcard.fNamespaceList, 
otherWildcard.fNamespaceList);
+        }
+
+        // -4 If the two are negations of different namespace names, then the 
intersection
+        //    is not expressible.
+        // +4 If the two are negations of different namespace names or absent, 
then
+        //    a pair of not and absent must be the value.
+        // * now we store ##other as not(list), the result should be
+        //   not(intersection of two lists).
+        else if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT && 
otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
+            unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_NOT;
+            unionWildcard.fNamespaceList = new String[2];
+            unionWildcard.fNamespaceList[0] = XSWildcardDecl.ABSENT;
+            unionWildcard.fNamespaceList[1] = XSWildcardDecl.ABSENT;
+        }
+
+        // 5 If either O1 or O2 is a pair of not and a namespace name and the 
other is a set of
+        //   (namespace names or absent), then The appropriate case among the 
following must be true:
+        //      -5.1 If the set includes the negated namespace name, then any 
must be the value.
+        //      -5.2 If the set does not include the negated namespace name, 
then whichever of O1 or O2
+        //           is a pair of not and a namespace name must be the value.
+        //    +5.1 If the negated value is a namespace name, then The 
appropriate case
+        //         among the following must be true:
+        //        +5.1.1 If the set includes both the namespace name and 
absent, then any
+        //               must be the value.
+        //        +5.1.2 If the set includes the namespace name but does not 
include
+        //               absent, then a pair of not and absent must be the 
value.
+        //        +5.1.3 If the set does not include the namespace name but 
includes
+        //               absent, then the union is not expressible.
+        //        +5.1.4 If the set does not include either the namespace name 
or absent,
+        //               then whichever of O1 or O2 is a pair of not and a 
namespace name must be
+        //               the value.
+        //    +5.2 If the negated value is absent, then The appropriate case 
among the
+        //         following must be true:
+        //        +5.2.1 If the set includes absent, then any must be the 
value.
+        //        +5.2.2 If the set does not include absent, then whichever of 
O1 or O2 is
+        //               a pair of not and a namespace name must be the value.
+        // * when we have not(list), the operation is just not(otherlist-list)
+        else if ( ((wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) && 
(otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST)) ||
+                  ((wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) && 
(otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT)) ) {
+            String[] local = null;
+            String[] list = null;
+
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
+                local = wildcard.fNamespaceList;
+                list = otherWildcard.fNamespaceList;
+            }
+            else {
+                local = otherWildcard.fNamespaceList;
+                list = wildcard.fNamespaceList;
+            }
+
+            boolean foundAbsent = elementInSet(XSWildcardDecl.ABSENT, list);
+
+            if (local[0] != XSWildcardDecl.ABSENT) {
+                boolean foundNS = elementInSet(local[0], list);
+                if (foundNS && foundAbsent) {
+                    unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_ANY;
+                } else if (foundNS && !foundAbsent) {
+                    unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_NOT;
+                    unionWildcard.fNamespaceList = new String[2];
+                    unionWildcard.fNamespaceList[0] = XSWildcardDecl.ABSENT;
+                    unionWildcard.fNamespaceList[1] = XSWildcardDecl.ABSENT;
+                } else if (!foundNS && foundAbsent) {
+                    return null;
+                } else { // !foundNS && !foundAbsent
+                    unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_NOT;
+                    unionWildcard.fNamespaceList = local;
+                }
+            } else { // other[0] == ABSENT
+                if (foundAbsent) {
+                    unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_ANY;
+                } else { // !foundAbsent
+                    unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_NOT;
+                    unionWildcard.fNamespaceList = local;
+                }
+            }
+        }
+
+        return unionWildcard;
+
+    } // performUnionWith
+
+    /**
+     * Schema Component Constraint: Attribute Wildcard Intersection
+     */
+    public XSWildcardDecl performIntersectionWith(XSWildcardDecl wildcard,
+                                                  XSWildcardDecl otherWildcard,
+                                                  short processContents) {
+        // if the other wildcard is not expressible, the result is still not 
expressible
+        if (otherWildcard == null)
+            return null;
+
+        // For a wildcard's {namespace constraint} value to be the intensional 
intersection of
+        // two other such values (call them O1 and O2): the appropriate case 
among the following
+        // must be true:
+
+        XSWildcardDecl intersectWildcard = new XSWildcardDecl();
+        intersectWildcard.fProcessContents = processContents;
+
+        // 1 If O1 and O2 are the same value, then that value must be the 
value.
+        if (areSame(wildcard, otherWildcard)) {
+            intersectWildcard.fType = wildcard.fType;
+            intersectWildcard.fNamespaceList = wildcard.fNamespaceList;
+        }
+
+        // 2 If either O1 or O2 is any, then the other must be the value.
+        else if ( (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) || 
(otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) ) {
+            // both cannot be ANY, if we have reached here.
+            XSWildcardDecl other = wildcard;
+
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY)
+                other = otherWildcard;
+
+            intersectWildcard.fType = other.fType;
+            intersectWildcard.fNamespaceList = other.fNamespaceList;
+        }
+
+        // -3 If either O1 or O2 is a pair of not and a namespace name and the 
other is a set of
+        //    (namespace names or absent), then that set, minus the negated 
namespace name if
+        //    it was in the set, must be the value.
+        // +3 If either O1 or O2 is a pair of not and a namespace name and the 
other
+        //    is a set of (namespace names or absent), then that set, minus 
the negated
+        //    namespace name if it was in the set, then minus absent if it was 
in the
+        //    set, must be the value.
+        // * when we have not(list), the operation is just list-otherlist
+        else if ( ((wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) && 
(otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST)) ||
+                  ((wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) && 
(otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT)) ) {
+            String[] list = null;
+            String[] other = null;
+
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
+                other = wildcard.fNamespaceList;
+                list = otherWildcard.fNamespaceList;
+            }
+            else {
+                other = otherWildcard.fNamespaceList;
+                list = wildcard.fNamespaceList;
+            }
+
+            int listSize = list.length;
+            String[] intersect = new String[listSize];
+            int newSize = 0;
+            for (int i = 0; i < listSize; i++) {
+                if (list[i] != other[0] && list[i] != XSWildcardDecl.ABSENT)
+                    intersect[newSize++] = list[i];
+            }
+
+            intersectWildcard.fType = XSWildcardDecl.NSCONSTRAINT_LIST;
+            intersectWildcard.fNamespaceList = new String[newSize];
+            System.arraycopy(intersect, 0, intersectWildcard.fNamespaceList, 
0, newSize);
+        }
+
+        // 4 If both O1 and O2 are sets of (namespace names or absent), then 
the intersection of those
+        //   sets must be the value.
+        else if ( (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) && 
(otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) ) {
+            intersectWildcard.fType = XSWildcardDecl.NSCONSTRAINT_LIST;
+            intersectWildcard.fNamespaceList = 
intersect2sets(wildcard.fNamespaceList, otherWildcard.fNamespaceList);
+        }
+
+        // -5 If the two are negations of different namespace names, then the 
intersection is not expressible.
+        // +5 If the two are negations of namespace names or absent, then The
+        //    appropriate case among the following must be true:
+        //    +5.1 If the two are negations of different namespace names, then 
the
+        //         intersection is not expressible.
+        //    +5.2 If one of the two is a pair of not and absent, the other 
must be
+        //         the value.
+        // * when we have not(list), the operation is just 
not(onelist+otherlist)
+        else if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT && 
otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
+            if (wildcard.fNamespaceList[0] != XSWildcardDecl.ABSENT && 
otherWildcard.fNamespaceList[0] != XSWildcardDecl.ABSENT)
+                return null;
+
+            XSWildcardDecl local = wildcard;
+            if (wildcard.fNamespaceList[0] == XSWildcardDecl.ABSENT)
+                local = otherWildcard;
+
+            intersectWildcard.fType = local.fType;
+            intersectWildcard.fNamespaceList = local.fNamespaceList;
+        }
+
+        return intersectWildcard;
+
+    } // performIntersectionWith
+
+    private boolean areSame(XSWildcardDecl wildcard, XSWildcardDecl 
otherWildcard) {
+        if (wildcard.fType == otherWildcard.fType) {
+            // ##any, true
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) {
+                return true;
+            }
+
+            // ##other, only check the negated value
+            // * when we support not(list), we need to check in the same way
+            //   as for NSCONSTRAINT_LIST.
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
+                return wildcard.fNamespaceList[0] == 
otherWildcard.fNamespaceList[0];
+            }
+
+            // ## list, must have the same length,
+            // and each item in one list must appear in the other one
+            // (we are assuming that there are no duplicate items in a list)
+            if (wildcard.fNamespaceList.length == 
otherWildcard.fNamespaceList.length) {
+                for (int i=0; i<wildcard.fNamespaceList.length; i++) {
+                    if (!elementInSet(wildcard.fNamespaceList[i], 
otherWildcard.fNamespaceList)) {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        }
+
+        return false;
+    } // areSame
+
+    String[] intersect2sets(String[] one, String[] theOther){
+        String[] result = new String[Math.min(one.length,theOther.length)];
+
+        // simple implemention,
+        int count = 0;
+        for (int i=0; i<one.length; i++) {
+            if (elementInSet(one[i], theOther))
+                result[count++] = one[i];
+        }
+
+        String[] result2 = new String[count];
+        System.arraycopy(result, 0, result2, 0, count);
+
+        return result2;
+    }
+
+    String[] union2sets(String[] one, String[] theOther){
+        String[] result1 = new String[one.length];
+
+        // simple implemention,
+        int count = 0;
+        for (int i=0; i<one.length; i++) {
+            if (!elementInSet(one[i], theOther))
+                result1[count++] = one[i];
+        }
+
+        String[] result2 = new String[count+theOther.length];
+        System.arraycopy(result1, 0, result2, 0, count);
+        System.arraycopy(theOther, 0, result2, count, theOther.length);
+
+        return result2;
+    }
+
+    boolean subset2sets(String[] subSet, String[] superSet){
+        for (int i=0; i<subSet.length; i++) {
+            if (!elementInSet(subSet[i], superSet))
+                return false;
+        }
+
+        return true;
+    }
+
+    boolean elementInSet(String ele, String[] set){
+        boolean found = false;
+        for (int i=0; i<set.length && !found; i++) {
+            if (ele==set[i])
+                found = true;
+        }
+
+        return found;
+    }
+    
+    // End wildcard constraints
+
     // to check whether an element overlaps with a wildcard,
     // as defined in constraint UPA
     public abstract boolean overlapUPA(XSElementDecl element,

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java?rev=702620&r1=702619&r2=702620&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSWildcardDecl.java
 Tue Oct  7 13:36:30 2008
@@ -52,7 +52,19 @@
     public String[] fNamespaceList;
 
     // optional annotation
-    public XSObjectList fAnnotations = null;  
+    public XSObjectList fAnnotations = null;
+
+    /*
+     * XML Schema 1.1
+     */
+    // disallowed names flag
+    public boolean fDisallowedNames = false;
+    // disallowed names list
+    public QName[] fDisallowedNamesList = null;
+    // ##defined {disallowed names}
+    public boolean fDisallowedDefined = false;
+    // ##definedSibling {disallowed names}
+    public boolean fDisallowedSibling = false;
 
     // I'm trying to implement the following constraint exactly as what the
     // spec describes. Sometimes it seems redundant, and sometimes there seems
@@ -123,62 +135,6 @@
     }
 
     /**
-     *  Schema Component Constraint: Wildcard Subset
-     */
-    public boolean isSubsetOf(XSWildcardDecl superWildcard) {
-        // if the super is null (not expressible), return false
-        if (superWildcard == null)
-            return false;
-
-        // For a namespace constraint (call it sub) to be an intensional 
subset of another
-        // namespace constraint (call it super) one of the following must be 
true:
-
-        // 1 super must be any.
-        if (superWildcard.fType == NSCONSTRAINT_ANY) {
-            return true;
-        }
-
-        // 2 All of the following must be true:
-        //   2.1 sub must be a pair of not and a namespace name or absent.
-        //   2.2 super must be a pair of not and the same value.
-        //   * we can't just compare whether the namespace are the same value
-        //     since we store other as not(list)
-        if (fType == NSCONSTRAINT_NOT) {
-            if (superWildcard.fType == NSCONSTRAINT_NOT &&
-                fNamespaceList[0] == superWildcard.fNamespaceList[0]) {
-                return true;
-            }
-        }
-
-        // 3 All of the following must be true:
-        //   3.1 sub must be a set whose members are either namespace names or 
absent.
-        //   3.2 One of the following must be true:
-        //       3.2.1 super must be the same set or a superset thereof.
-        //       -3.2.2 super must be a pair of not and a namespace name or 
absent and
-        //              that value must not be in sub's set.
-        //       +3.2.2 super must be a pair of not and a namespace name or 
absent and
-        //              either that value or absent must not be in sub's set.
-        //       * since we store ##other as not(list), we acturally need to 
make sure
-        //         that none of the namespaces in super.list is in sub.list.
-        if (fType == NSCONSTRAINT_LIST) {
-            if (superWildcard.fType == NSCONSTRAINT_LIST &&
-                subset2sets(fNamespaceList, superWildcard.fNamespaceList)) {
-                return true;
-            }
-
-            if (superWildcard.fType == NSCONSTRAINT_NOT &&
-                !elementInSet(superWildcard.fNamespaceList[0], fNamespaceList) 
&&
-                !elementInSet(ABSENT, fNamespaceList)) {
-                return true;
-            }
-        }
-
-        // none of the above conditions applied, so return false.
-        return false;
-
-    } // isSubsetOf
-
-    /**
      * Check whether this wildcard has a weaker process contents than the 
super.
      */
     public boolean weakerProcessContents(XSWildcardDecl superWildcard) {
@@ -189,299 +145,6 @@
     }
 
     /**
-     * Schema Component Constraint: Attribute Wildcard Union
-     */
-    public XSWildcardDecl performUnionWith(XSWildcardDecl wildcard,
-                                           short processContents) {
-        // if the other wildcard is not expressible, the result is still not 
expressible
-        if (wildcard == null)
-            return null;
-
-        // For a wildcard's {namespace constraint} value to be the intensional 
union of two
-        // other such values (call them O1 and O2): the appropriate case among 
the following
-        // must be true:
-
-        XSWildcardDecl unionWildcard = new XSWildcardDecl();
-        unionWildcard.fProcessContents = processContents;
-
-        // 1 If O1 and O2 are the same value, then that value must be the 
value.
-        if (areSame(wildcard)) {
-            unionWildcard.fType = fType;
-            unionWildcard.fNamespaceList = fNamespaceList;
-        }
-
-        // 2 If either O1 or O2 is any, then any must be the value.
-        else if ( (fType == NSCONSTRAINT_ANY) || (wildcard.fType == 
NSCONSTRAINT_ANY) ) {
-            unionWildcard.fType = NSCONSTRAINT_ANY;
-        }
-
-        // 3 If both O1 and O2 are sets of (namespace names or absent), then 
the union of
-        //   those sets must be the value.
-        else if ( (fType == NSCONSTRAINT_LIST) && (wildcard.fType == 
NSCONSTRAINT_LIST) ) {
-            unionWildcard.fType = NSCONSTRAINT_LIST;
-            unionWildcard.fNamespaceList = union2sets(fNamespaceList, 
wildcard.fNamespaceList);
-        }
-
-        // -4 If the two are negations of different namespace names, then the 
intersection
-        //    is not expressible.
-        // +4 If the two are negations of different namespace names or absent, 
then
-        //    a pair of not and absent must be the value.
-        // * now we store ##other as not(list), the result should be
-        //   not(intersection of two lists).
-        else if (fType == NSCONSTRAINT_NOT && wildcard.fType == 
NSCONSTRAINT_NOT) {
-            unionWildcard.fType = NSCONSTRAINT_NOT;
-            unionWildcard.fNamespaceList = new String[2];
-            unionWildcard.fNamespaceList[0] = ABSENT;
-            unionWildcard.fNamespaceList[1] = ABSENT;
-        }
-
-        // 5 If either O1 or O2 is a pair of not and a namespace name and the 
other is a set of
-        //   (namespace names or absent), then The appropriate case among the 
following must be true:
-        //      -5.1 If the set includes the negated namespace name, then any 
must be the value.
-        //      -5.2 If the set does not include the negated namespace name, 
then whichever of O1 or O2
-        //           is a pair of not and a namespace name must be the value.
-        //    +5.1 If the negated value is a namespace name, then The 
appropriate case
-        //         among the following must be true:
-        //        +5.1.1 If the set includes both the namespace name and 
absent, then any
-        //               must be the value.
-        //        +5.1.2 If the set includes the namespace name but does not 
include
-        //               absent, then a pair of not and absent must be the 
value.
-        //        +5.1.3 If the set does not include the namespace name but 
includes
-        //               absent, then the union is not expressible.
-        //        +5.1.4 If the set does not include either the namespace name 
or absent,
-        //               then whichever of O1 or O2 is a pair of not and a 
namespace name must be
-        //               the value.
-        //    +5.2 If the negated value is absent, then The appropriate case 
among the
-        //         following must be true:
-        //        +5.2.1 If the set includes absent, then any must be the 
value.
-        //        +5.2.2 If the set does not include absent, then whichever of 
O1 or O2 is
-        //               a pair of not and a namespace name must be the value.
-        // * when we have not(list), the operation is just not(otherlist-list)
-        else if ( ((fType == NSCONSTRAINT_NOT) && (wildcard.fType == 
NSCONSTRAINT_LIST)) ||
-                  ((fType == NSCONSTRAINT_LIST) && (wildcard.fType == 
NSCONSTRAINT_NOT)) ) {
-            String[] other = null;
-            String[] list = null;
-
-            if (fType == NSCONSTRAINT_NOT) {
-                other = fNamespaceList;
-                list = wildcard.fNamespaceList;
-            }
-            else {
-                other = wildcard.fNamespaceList;
-                list = fNamespaceList;
-            }
-
-            boolean foundAbsent = elementInSet(ABSENT, list);
-
-            if (other[0] != ABSENT) {
-                boolean foundNS = elementInSet(other[0], list);
-                if (foundNS && foundAbsent) {
-                    unionWildcard.fType = NSCONSTRAINT_ANY;
-                } else if (foundNS && !foundAbsent) {
-                    unionWildcard.fType = NSCONSTRAINT_NOT;
-                    unionWildcard.fNamespaceList = new String[2];
-                    unionWildcard.fNamespaceList[0] = ABSENT;
-                    unionWildcard.fNamespaceList[1] = ABSENT;
-                } else if (!foundNS && foundAbsent) {
-                    return null;
-                } else { // !foundNS && !foundAbsent
-                    unionWildcard.fType = NSCONSTRAINT_NOT;
-                    unionWildcard.fNamespaceList = other;
-                }
-            } else { // other[0] == ABSENT
-                if (foundAbsent) {
-                    unionWildcard.fType = NSCONSTRAINT_ANY;
-                } else { // !foundAbsent
-                    unionWildcard.fType = NSCONSTRAINT_NOT;
-                    unionWildcard.fNamespaceList = other;
-                }
-            }
-        }
-
-        return unionWildcard;
-
-    } // performUnionWith
-
-    /**
-     * Schema Component Constraint: Attribute Wildcard Intersection
-     */
-    public XSWildcardDecl performIntersectionWith(XSWildcardDecl wildcard,
-                                                  short processContents) {
-        // if the other wildcard is not expressible, the result is still not 
expressible
-        if (wildcard == null)
-            return null;
-
-        // For a wildcard's {namespace constraint} value to be the intensional 
intersection of
-        // two other such values (call them O1 and O2): the appropriate case 
among the following
-        // must be true:
-
-        XSWildcardDecl intersectWildcard = new XSWildcardDecl();
-        intersectWildcard.fProcessContents = processContents;
-
-        // 1 If O1 and O2 are the same value, then that value must be the 
value.
-        if (areSame(wildcard)) {
-            intersectWildcard.fType = fType;
-            intersectWildcard.fNamespaceList = fNamespaceList;
-        }
-
-        // 2 If either O1 or O2 is any, then the other must be the value.
-        else if ( (fType == NSCONSTRAINT_ANY) || (wildcard.fType == 
NSCONSTRAINT_ANY) ) {
-            // both cannot be ANY, if we have reached here.
-            XSWildcardDecl other = this;
-
-            if (fType == NSCONSTRAINT_ANY)
-                other = wildcard;
-
-            intersectWildcard.fType = other.fType;
-            intersectWildcard.fNamespaceList = other.fNamespaceList;
-        }
-
-        // -3 If either O1 or O2 is a pair of not and a namespace name and the 
other is a set of
-        //    (namespace names or absent), then that set, minus the negated 
namespace name if
-        //    it was in the set, must be the value.
-        // +3 If either O1 or O2 is a pair of not and a namespace name and the 
other
-        //    is a set of (namespace names or absent), then that set, minus 
the negated
-        //    namespace name if it was in the set, then minus absent if it was 
in the
-        //    set, must be the value.
-        // * when we have not(list), the operation is just list-otherlist
-        else if ( ((fType == NSCONSTRAINT_NOT) && (wildcard.fType == 
NSCONSTRAINT_LIST)) ||
-                  ((fType == NSCONSTRAINT_LIST) && (wildcard.fType == 
NSCONSTRAINT_NOT)) ) {
-            String[] list = null;
-            String[] other = null;
-
-            if (fType == NSCONSTRAINT_NOT) {
-                other = fNamespaceList;
-                list = wildcard.fNamespaceList;
-            }
-            else {
-                other = wildcard.fNamespaceList;
-                list = fNamespaceList;
-            }
-
-            int listSize = list.length;
-            String[] intersect = new String[listSize];
-            int newSize = 0;
-            for (int i = 0; i < listSize; i++) {
-                if (list[i] != other[0] && list[i] != ABSENT)
-                    intersect[newSize++] = list[i];
-            }
-
-            intersectWildcard.fType = NSCONSTRAINT_LIST;
-            intersectWildcard.fNamespaceList = new String[newSize];
-            System.arraycopy(intersect, 0, intersectWildcard.fNamespaceList, 
0, newSize);
-        }
-
-        // 4 If both O1 and O2 are sets of (namespace names or absent), then 
the intersection of those
-        //   sets must be the value.
-        else if ( (fType == NSCONSTRAINT_LIST) && (wildcard.fType == 
NSCONSTRAINT_LIST) ) {
-            intersectWildcard.fType = NSCONSTRAINT_LIST;
-            intersectWildcard.fNamespaceList = intersect2sets(fNamespaceList, 
wildcard.fNamespaceList);
-        }
-
-        // -5 If the two are negations of different namespace names, then the 
intersection is not expressible.
-        // +5 If the two are negations of namespace names or absent, then The
-        //    appropriate case among the following must be true:
-        //    +5.1 If the two are negations of different namespace names, then 
the
-        //         intersection is not expressible.
-        //    +5.2 If one of the two is a pair of not and absent, the other 
must be
-        //         the value.
-        // * when we have not(list), the operation is just 
not(onelist+otherlist)
-        else if (fType == NSCONSTRAINT_NOT && wildcard.fType == 
NSCONSTRAINT_NOT) {
-            if (fNamespaceList[0] != ABSENT && wildcard.fNamespaceList[0] != 
ABSENT)
-                return null;
-
-            XSWildcardDecl other = this;
-            if (fNamespaceList[0] == ABSENT)
-                other = wildcard;
-
-            intersectWildcard.fType = other.fType;
-            intersectWildcard.fNamespaceList = other.fNamespaceList;
-        }
-
-        return intersectWildcard;
-
-    } // performIntersectionWith
-
-    private boolean areSame(XSWildcardDecl wildcard) {
-        if (fType == wildcard.fType) {
-            // ##any, true
-            if (fType == NSCONSTRAINT_ANY)
-                return true;
-
-            // ##other, only check the negated value
-            // * when we support not(list), we need to check in the same way
-            //   as for NSCONSTRAINT_LIST.
-            if (fType == NSCONSTRAINT_NOT)
-                return fNamespaceList[0] == wildcard.fNamespaceList[0];
-
-            // ## list, must have the same length,
-            // and each item in one list must appear in the other one
-            // (we are assuming that there are no duplicate items in a list)
-            if (fNamespaceList.length == wildcard.fNamespaceList.length) {
-                for (int i=0; i<fNamespaceList.length; i++) {
-                    if (!elementInSet(fNamespaceList[i], 
wildcard.fNamespaceList))
-                        return false;
-                }
-                return true;
-            }
-        }
-
-        return false;
-    } // areSame
-
-    String[] intersect2sets(String[] one, String[] theOther){
-        String[] result = new String[Math.min(one.length,theOther.length)];
-
-        // simple implemention,
-        int count = 0;
-        for (int i=0; i<one.length; i++) {
-            if (elementInSet(one[i], theOther))
-                result[count++] = one[i];
-        }
-
-        String[] result2 = new String[count];
-        System.arraycopy(result, 0, result2, 0, count);
-
-        return result2;
-    }
-
-    String[] union2sets(String[] one, String[] theOther){
-        String[] result1 = new String[one.length];
-
-        // simple implemention,
-        int count = 0;
-        for (int i=0; i<one.length; i++) {
-            if (!elementInSet(one[i], theOther))
-                result1[count++] = one[i];
-        }
-
-        String[] result2 = new String[count+theOther.length];
-        System.arraycopy(result1, 0, result2, 0, count);
-        System.arraycopy(theOther, 0, result2, count, theOther.length);
-
-        return result2;
-    }
-
-    boolean subset2sets(String[] subSet, String[] superSet){
-        for (int i=0; i<subSet.length; i++) {
-            if (!elementInSet(subSet[i], superSet))
-                return false;
-        }
-
-        return true;
-    }
-
-    boolean elementInSet(String ele, String[] set){
-        boolean found = false;
-        for (int i=0; i<set.length && !found; i++) {
-            if (ele==set[i])
-                found = true;
-        }
-
-        return found;
-    }
-
-    /**
      * get the string description of this wildcard
      */
     private String fDescription = null;

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java?rev=702620&r1=702619&r2=702620&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
 Tue Oct  7 13:36:30 2008
@@ -690,8 +690,8 @@
                     }
                     // perform intersection of attribute wildcard
                     else {
-                        attrGrp.fAttributeWC = attrGrp.fAttributeWC.
-                        performIntersectionWith(tempAttrGrp.fAttributeWC, 
attrGrp.fAttributeWC.fProcessContents);
+                        attrGrp.fAttributeWC = fSchemaHandler.fXSConstraints.
+                        performIntersectionWith(attrGrp.fAttributeWC, 
tempAttrGrp.fAttributeWC, attrGrp.fAttributeWC.fProcessContents);
                         if (attrGrp.fAttributeWC == null) {
                             String code = (enclosingCT == null) ? 
"src-attribute_group.2" : "src-ct.4";
                             String name = (enclosingCT == null) ? 
attrGrp.fName : enclosingCT.getName();
@@ -714,8 +714,8 @@
                 }
                 // perform intersection of attribute wildcard
                 else {
-                    attrGrp.fAttributeWC = tempAttrWC.
-                    performIntersectionWith(attrGrp.fAttributeWC, 
tempAttrWC.fProcessContents);
+                    attrGrp.fAttributeWC = fSchemaHandler.fXSConstraints.
+                    performIntersectionWith(tempAttrWC, attrGrp.fAttributeWC, 
tempAttrWC.fProcessContents);
                     if (attrGrp.fAttributeWC == null) {
                         String code = (enclosingCT == null) ? 
"src-attribute_group.2" : "src-ct.4";
                         String name = (enclosingCT == null) ? attrGrp.fName : 
enclosingCT.getName();

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java?rev=702620&r1=702619&r2=702620&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
 Tue Oct  7 13:36:30 2008
@@ -1114,7 +1114,7 @@
                         }
 
                         // 1.4.3.2.2.4
-                        if 
(!baseOpenContent.fWildcard.isSubsetOf(fOpenContent.fWildcard)) {
+                        if 
(!fSchemaHandler.fXSConstraints.isSubsetOf(baseOpenContent.fWildcard, 
fOpenContent.fWildcard)) {
                             
fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
                             
fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
                             throw new 
ComplexTypeRecoverableError("cos-ct-extends.1.4.3.2.2.3.4",
@@ -1171,7 +1171,7 @@
                 toAttrGrp.fAttributeWC = fromAttrGrp.fAttributeWC;
             }
             else if (fromAttrGrp.fAttributeWC != null) {
-                toAttrGrp.fAttributeWC = 
toAttrGrp.fAttributeWC.performUnionWith(fromAttrGrp.fAttributeWC, 
toAttrGrp.fAttributeWC.fProcessContents);
+                toAttrGrp.fAttributeWC = 
fSchemaHandler.fXSConstraints.performUnionWith(toAttrGrp.fAttributeWC, 
fromAttrGrp.fAttributeWC, toAttrGrp.fAttributeWC.fProcessContents);
                 if (toAttrGrp.fAttributeWC == null) {
                     // REVISIT: XML Schema 1.0 2nd edition doesn't actually 
specify this constraint. It's a bug in the spec
                     // which will eventually be fixed. We're just guessing 
what the error code will be. If it turns out to be



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

Reply via email to