You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2008/10/23 23:12:24 UTC

svn commit: r707475 [1/2] - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl: msg/ xs/ xs/models/ xs/traversers/

Author: knoaman
Date: Thu Oct 23 14:12:24 2008
New Revision: 707475

URL: http://svn.apache.org/viewvc?rev=707475&view=rev
Log:
Add support for enhanced wildcards

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
    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/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/models/XS11AllCM.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSDFACM.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSEmptyCM.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/XSDWildcardTraverser.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties?rev=707475&r1=707474&r2=707475&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties Thu Oct 23 14:12:24 2008
@@ -155,6 +155,7 @@
         src-union-memberTypes-or-simpleTypes = src-union-memberTypes-or-simpleTypes: A <union> element must have either a non-empty memberTypes [attribute] or at least one <simpleType> element among its [children].
         src-type-alternative.3.12.13.1 = src-type-alternative.3.12.13.1: Type atlernative has both a ''type'' attribute and a ''anonymous type'' child. Only one of these is allowed for a type alternative.
         src-type-alternative.3.12.13.2 = src-type-alternative.3.12.13.2: Type definition missing for type atlernative. A ''type'' attribute, or a ''complexType'' child element, or a ''simpleType'' child element must be present.
+        src-wildcard.1 = src-wildcard.1: The properties ''namespace'' and ''notNamespace'' cannot both be present in a wildcard declaration. Use only one of them.        
 
 #constraint valid (3.X.6)
 
@@ -277,6 +278,8 @@
         st-props-correct.2 = st-props-correct.2: Circular definitions have been detected for simple type ''{0}''. This means that ''{0}'' is contained in its own type hierarchy, which is an error.
         st-props-correct.3 = st-props-correct.3: Error for type ''{0}''. The value of '{'final'}' of the '{'base type definition'}', ''{1}'', forbids derivation by restriction.
         totalDigits-valid-restriction = totalDigits-valid-restriction: In the definition of {2}, the value ''{0}'' for the facet ''totalDigits'' is invalid, because it must be <= the value for ''totalDigits'' which was set to ''{1}'' in one of the ancestor types.
+        wc-props-correct.2 = wc-props-correct.2: When a wildcard has a {variety} of 'not, the {namespaces} has to have at least one member.
+        wc-props-correct.4 = wc-props-correct.4: The namespace ''{0}'' for disallowed name ''{1}"" is not allowed by the wildcard.
         whiteSpace-valid-restriction.1 = whiteSpace-valid-restriction.1: In the definition of {0}, the value ''{1}'' for the facet ''whitespace'' is invalid, because the value for ''whitespace'' has been set to ''collapse'' in one of the ancestor types.
         whiteSpace-valid-restriction.2 = whiteSpace-valid-restriction.2: In the definition of {0}, the value ''preserve'' for the facet ''whitespace'' is invalid, because the value for ''whitespace'' has been set to ''replace'' in one of the ancestor types.
 

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java?rev=707475&r1=707474&r2=707475&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaSymbols.java Thu Oct 23 14:12:24 2008
@@ -121,6 +121,8 @@
     public static final String ATT_NAME                   = "name".intern();
     public static final String ATT_NAMESPACE              = "namespace".intern();
     public static final String ATT_NILLABLE               = "nillable".intern();
+    public static final String ATT_NOTNAMESPACE           = "notNamespace".intern();
+    public static final String ATT_NOTQNAME               = "notQName".intern();
     public static final String ATT_PROCESSCONTENTS        = "processContents".intern();
     public static final String ATT_REF                    = "ref".intern();
     public static final String ATT_REFER                  = "refer".intern();
@@ -142,82 +144,84 @@
     public static final String ATT_MAXVERSION             = "maxVersion".intern();
 
     // all possible schema attribute values
-    public static final String ATTVAL_TWOPOUNDANY         = "##any";
-    public static final String ATTVAL_TWOPOUNDDEFAULTNS  = "##defaultNamespace";    
-    public static final String ATTVAL_TWOPOUNDLOCAL       = "##local";
-    public static final String ATTVAL_TWOPOUNDOTHER       = "##other";
-    public static final String ATTVAL_TWOPOUNDTARGETNS    = "##targetNamespace";
-    public static final String ATTVAL_POUNDALL            = "#all";
-    public static final String ATTVAL_FALSE_0             = "0";
-    public static final String ATTVAL_TRUE_1              = "1";
-    public static final String ATTVAL_ANYSIMPLETYPE       = "anySimpleType";
-    public static final String ATTVAL_ANYTYPE             = "anyType";
-    public static final String ATTVAL_ANYURI              = "anyURI";
-    public static final String ATTVAL_BASE64BINARY        = "base64Binary";
-    public static final String ATTVAL_BOOLEAN             = "boolean";
-    public static final String ATTVAL_BYTE                = "byte";
-    public static final String ATTVAL_COLLAPSE            = "collapse";
-    public static final String ATTVAL_DATE                = "date";
-    public static final String ATTVAL_DATETIME            = "dateTime";
-    public static final String ATTVAL_DAY                 = "gDay";
-    public static final String ATTVAL_DECIMAL             = "decimal";
-    public static final String ATTVAL_DOUBLE              = "double";
-    public static final String ATTVAL_DURATION            = "duration";
-    public static final String ATTVAL_ENTITY              = "ENTITY";
-    public static final String ATTVAL_ENTITIES            = "ENTITIES";
-    public static final String ATTVAL_EXTENSION           = "extension";
-    public static final String ATTVAL_FALSE               = "false";
-    public static final String ATTVAL_FLOAT               = "float";
-    public static final String ATTVAL_HEXBINARY           = "hexBinary";
-    public static final String ATTVAL_ID                  = "ID";
-    public static final String ATTVAL_IDREF               = "IDREF";
-    public static final String ATTVAL_IDREFS              = "IDREFS";
-    public static final String ATTVAL_INT                 = "int";
-    public static final String ATTVAL_INTEGER             = "integer";
-    public static final String ATTVAL_INTERLEAVE          = "interleave";    
-    public static final String ATTVAL_LANGUAGE            = "language";
-    public static final String ATTVAL_LAX                 = "lax";
-    public static final String ATTVAL_LIST                = "list";
-    public static final String ATTVAL_LONG                = "long";
-    public static final String ATTVAL_NAME                = "Name";
-    public static final String ATTVAL_NEGATIVEINTEGER     = "negativeInteger";
-    public static final String ATTVAL_MONTH               = "gMonth";
-    public static final String ATTVAL_MONTHDAY            = "gMonthDay";
-    public static final String ATTVAL_NCNAME              = "NCName";
-    public static final String ATTVAL_NMTOKEN             = "NMTOKEN";
-    public static final String ATTVAL_NMTOKENS            = "NMTOKENS";
-    public static final String ATTVAL_NONE                = "none";    
-    public static final String ATTVAL_NONNEGATIVEINTEGER  = "nonNegativeInteger";
-    public static final String ATTVAL_NONPOSITIVEINTEGER  = "nonPositiveInteger";
-    public static final String ATTVAL_NORMALIZEDSTRING    = "normalizedString";
-    public static final String ATTVAL_NOTATION            = "NOTATION";
-    public static final String ATTVAL_OPTIONAL            = "optional";
-    public static final String ATTVAL_POSITIVEINTEGER     = "positiveInteger";
-    public static final String ATTVAL_PRESERVE            = "preserve";
-    public static final String ATTVAL_PROHIBITED          = "prohibited";
-    public static final String ATTVAL_QNAME               = "QName";
-    public static final String ATTVAL_QUALIFIED           = "qualified";
-    public static final String ATTVAL_REPLACE             = "replace";
-    public static final String ATTVAL_REQUIRED            = "required";
-    public static final String ATTVAL_RESTRICTION         = "restriction";
-    public static final String ATTVAL_SHORT               = "short";
-    public static final String ATTVAL_SKIP                = "skip";
-    public static final String ATTVAL_STRICT              = "strict";
-    public static final String ATTVAL_STRING              = "string";    
-    public static final String ATTVAL_SUBSTITUTION        = "substitution";
-    public static final String ATTVAL_SUFFIX              = "suffix";
-    public static final String ATTVAL_TIME                = "time";
-    public static final String ATTVAL_TOKEN               = "token";
-    public static final String ATTVAL_TRUE                =  "true";
-    public static final String ATTVAL_UNBOUNDED           =  "unbounded";
-    public static final String ATTVAL_UNION               = "union";
-    public static final String ATTVAL_UNQUALIFIED         = "unqualified";
-    public static final String ATTVAL_UNSIGNEDBYTE        = "unsignedByte";
-    public static final String ATTVAL_UNSIGNEDINT         = "unsignedInt";
-    public static final String ATTVAL_UNSIGNEDLONG        = "unsignedLong";
-    public static final String ATTVAL_UNSIGNEDSHORT       = "unsignedShort";
-    public static final String ATTVAL_YEAR                = "gYear";
-    public static final String ATTVAL_YEARMONTH           = "gYearMonth";
+    public static final String ATTVAL_TWOPOUNDANY            = "##any";
+    public static final String ATTVAL_TWOPOUNDDEFAULTNS      = "##defaultNamespace";
+    public static final String ATTVAL_TWOPOUNDDEFINED        = "##defined";
+    public static final String ATTVAL_TWOPOUNDDEFINEDSIBLING = "##definedSibling";    
+    public static final String ATTVAL_TWOPOUNDLOCAL          = "##local";
+    public static final String ATTVAL_TWOPOUNDOTHER          = "##other";
+    public static final String ATTVAL_TWOPOUNDTARGETNS       = "##targetNamespace";    
+    public static final String ATTVAL_POUNDALL               = "#all";
+    public static final String ATTVAL_FALSE_0                = "0";
+    public static final String ATTVAL_TRUE_1                 = "1";
+    public static final String ATTVAL_ANYSIMPLETYPE          = "anySimpleType";
+    public static final String ATTVAL_ANYTYPE                = "anyType";
+    public static final String ATTVAL_ANYURI                 = "anyURI";
+    public static final String ATTVAL_BASE64BINARY           = "base64Binary";
+    public static final String ATTVAL_BOOLEAN                = "boolean";
+    public static final String ATTVAL_BYTE                   = "byte";
+    public static final String ATTVAL_COLLAPSE               = "collapse";
+    public static final String ATTVAL_DATE                   = "date";
+    public static final String ATTVAL_DATETIME               = "dateTime";
+    public static final String ATTVAL_DAY                    = "gDay";
+    public static final String ATTVAL_DECIMAL                = "decimal";
+    public static final String ATTVAL_DOUBLE                 = "double";
+    public static final String ATTVAL_DURATION               = "duration";
+    public static final String ATTVAL_ENTITY                 = "ENTITY";
+    public static final String ATTVAL_ENTITIES               = "ENTITIES";
+    public static final String ATTVAL_EXTENSION              = "extension";
+    public static final String ATTVAL_FALSE                  = "false";
+    public static final String ATTVAL_FLOAT                  = "float";
+    public static final String ATTVAL_HEXBINARY              = "hexBinary";
+    public static final String ATTVAL_ID                     = "ID";
+    public static final String ATTVAL_IDREF                  = "IDREF";
+    public static final String ATTVAL_IDREFS                 = "IDREFS";
+    public static final String ATTVAL_INT                    = "int";
+    public static final String ATTVAL_INTEGER                = "integer";
+    public static final String ATTVAL_INTERLEAVE             = "interleave";    
+    public static final String ATTVAL_LANGUAGE               = "language";
+    public static final String ATTVAL_LAX                    = "lax";
+    public static final String ATTVAL_LIST                   = "list";
+    public static final String ATTVAL_LONG                   = "long";
+    public static final String ATTVAL_NAME                   = "Name";
+    public static final String ATTVAL_NEGATIVEINTEGER        = "negativeInteger";
+    public static final String ATTVAL_MONTH                  = "gMonth";
+    public static final String ATTVAL_MONTHDAY               = "gMonthDay";
+    public static final String ATTVAL_NCNAME                 = "NCName";
+    public static final String ATTVAL_NMTOKEN                = "NMTOKEN";
+    public static final String ATTVAL_NMTOKENS               = "NMTOKENS";
+    public static final String ATTVAL_NONE                   = "none";    
+    public static final String ATTVAL_NONNEGATIVEINTEGER     = "nonNegativeInteger";
+    public static final String ATTVAL_NONPOSITIVEINTEGER     = "nonPositiveInteger";
+    public static final String ATTVAL_NORMALIZEDSTRING       = "normalizedString";
+    public static final String ATTVAL_NOTATION               = "NOTATION";
+    public static final String ATTVAL_OPTIONAL               = "optional";
+    public static final String ATTVAL_POSITIVEINTEGER        = "positiveInteger";
+    public static final String ATTVAL_PRESERVE               = "preserve";
+    public static final String ATTVAL_PROHIBITED             = "prohibited";
+    public static final String ATTVAL_QNAME                  = "QName";
+    public static final String ATTVAL_QUALIFIED              = "qualified";
+    public static final String ATTVAL_REPLACE                = "replace";
+    public static final String ATTVAL_REQUIRED               = "required";
+    public static final String ATTVAL_RESTRICTION            = "restriction";
+    public static final String ATTVAL_SHORT                  = "short";
+    public static final String ATTVAL_SKIP                   = "skip";
+    public static final String ATTVAL_STRICT                 = "strict";
+    public static final String ATTVAL_STRING                 = "string";    
+    public static final String ATTVAL_SUBSTITUTION           = "substitution";
+    public static final String ATTVAL_SUFFIX                 = "suffix";
+    public static final String ATTVAL_TIME                   = "time";
+    public static final String ATTVAL_TOKEN                  = "token";
+    public static final String ATTVAL_TRUE                   = "true";
+    public static final String ATTVAL_UNBOUNDED              = "unbounded";
+    public static final String ATTVAL_UNION                  = "union";
+    public static final String ATTVAL_UNQUALIFIED            = "unqualified";
+    public static final String ATTVAL_UNSIGNEDBYTE           = "unsignedByte";
+    public static final String ATTVAL_UNSIGNEDINT            = "unsignedInt";
+    public static final String ATTVAL_UNSIGNEDLONG           = "unsignedLong";
+    public static final String ATTVAL_UNSIGNEDSHORT          = "unsignedShort";
+    public static final String ATTVAL_YEAR                   = "gYear";
+    public static final String ATTVAL_YEARMONTH              = "gYearMonth";
 
     // form qualified/unqualified
     public static final short FORM_UNQUALIFIED = 0;

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=707475&r1=707474&r2=707475&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Thu Oct 23 14:12:24 2008
@@ -573,7 +573,7 @@
             fRootTypeQName = (javax.xml.namespace.QName)value;
         }
         else if (propertyId.equals(XML_SCHEMA_VERSION)) {
-        	// TODO: do we use fSchemaLoader.setProperty
+            // TODO: do we use fSchemaLoader.setProperty
             fSchemaLoader.setSchemaVersion((String)value);
             fSchemaVersion = fSchemaLoader.getSchemaVersion();
             fXSConstraints = fSchemaLoader.getXSConstraints();
@@ -1862,7 +1862,7 @@
         // context, instead of that of the current element.
         Object decl = null;
         if (fCurrentCM != null) {
-            decl = fCurrentCM.oneTransition(element, fCurrCMState, fSubGroupHandler);
+            decl = fCurrentCM.oneTransition(element, fCurrCMState, fSubGroupHandler, sGrammar);
             // it could be an element decl or a wildcard decl
             if (fCurrCMState[0] == XSCMValidator.FIRST_ERROR) {
                 XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType;
@@ -2187,7 +2187,7 @@
         }
 
         //process type alternatives
-        if (fTypeAlternativesChecking) {
+        if (fTypeAlternativesChecking && fCurrentElemDecl != null) {
             boolean typeSelected = false;
             XSTypeAlternativeImpl[] alternatives = fCurrentElemDecl.getTypeAlternatives();
             if (alternatives != null) {
@@ -2703,6 +2703,16 @@
         return false;
     }
 
+    boolean allowAttribute(XSWildcardDecl attrWildcard, QName name, SchemaGrammar grammar) {
+        if (attrWildcard.allowQName(name)) {
+            if (grammar == null || !attrWildcard.fDisallowedDefined) {
+                return true;
+            }
+            return (grammar.getGlobalAttributeDecl(name.localpart) == null);
+        }
+        return false;
+    }
+
     void processAttributes(QName element, XMLAttributes attributes, XSAttributeGroupDecl attrGrp) {
 
         if (DEBUG) {
@@ -2813,7 +2823,10 @@
             if (currUse == null) {
                 //if (attrWildcard == null)
                 //    reportSchemaError("cvc-complex-type.3.2.1", new Object[]{element.rawname, fTempQName.rawname});
-                if (attrWildcard == null || !attrWildcard.allowNamespace(fTempQName.uri)) {
+                SchemaGrammar grammar = (fSchemaVersion < Constants.SCHEMA_VERSION_1_1)
+                    ? null : findSchemaGrammar(
+                        XSDDescription.CONTEXT_ATTRIBUTE, fTempQName.uri, element, fTempQName, attributes);
+                if (attrWildcard == null || !allowAttribute(attrWildcard, fTempQName, grammar)) {
                     // so this attribute is not allowed
                     reportSchemaError(
                         "cvc-complex-type.3.2.2",

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=707475&r1=707474&r2=707475&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 Thu Oct 23 14:12:24 2008
@@ -63,4 +63,279 @@
 
         return false;
     }
+
+    /**
+     *  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
 }

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=707475&r1=707474&r2=707475&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 Thu Oct 23 14:12:24 2008
@@ -17,6 +17,8 @@
 
 package org.apache.xerces.impl.xs;
 
+import org.apache.xerces.xni.QName;
+
 /**
  * XML Schema 1.0 constraints
  * 
@@ -30,7 +32,7 @@
 class XS11Constraints extends XSConstraints {
 
     public XS11Constraints() {
-        super(SchemaGrammar.fAnyType); // TODO: use 1.1 specific anyType
+        super(SchemaGrammar.fAnyType);
     }
 
     public boolean overlapUPA(XSElementDecl element,
@@ -51,4 +53,348 @@
 
         return false;
     }
+
+    /**
+     *  Schema Component Constraint: Wildcard Subset
+     */
+    public boolean isSubsetOf(XSWildcardDecl wildcard, XSWildcardDecl superWildcard) {
+        // if the super is null (not expressible), return false
+        if (superWildcard == null) {
+            return false;
+        }
+
+        // sub is a wildcard subset of super if and only if one of the following is true
+        //  1 super has {variety} = any.
+        if (superWildcard.fType != XSWildcardDecl.NSCONSTRAINT_ANY) {
+
+        	// sub has a variety of enumeration
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) {
+                //  2 Both sub and super have {variety} = enumeration, and super's {namespaces} is a superset of sub's {namespaces}.
+                if (superWildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) {
+                    if (!subset2sets(wildcard.fNamespaceList, superWildcard.fNamespaceList)) {
+                        return false;
+                    }
+                }
+                //  3 The {variety} of sub is enumeration, the {variety} of super is not, and the {namespaces} of the two are disjoint.
+                else if (!disjoint2sets(wildcard.fNamespaceList, superWildcard.fNamespaceList)){
+                    return false;
+                }
+            }
+
+            // 4 Both sub and super have {variety} = not, and super's {namespaces} is a subset of sub's {namespaces}.
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
+                if (superWildcard.fType != XSWildcardDecl.NSCONSTRAINT_NOT || !subset2sets(superWildcard.fNamespaceList, wildcard.fNamespaceList)) {
+                    return false;
+                }
+            }
+        }
+
+        // And all of the following must be true:
+        //  1 Each QName member of super.{disallowed names} is not allowed by sub, as defined in Wildcard allows Expanded Name (3.10.4.2).
+        //  2 If super.{disallowed names} contains defined, then sub.{disallowed names} also contains defined.
+        //  3 If super.{disallowed names} contains sibling, then sub.{disallowed names} also contains sibling.
+        if ((superWildcard.fDisallowedDefined && !wildcard.fDisallowedDefined)
+        		|| (superWildcard.fDisallowedSibling && wildcard.fDisallowedSibling)
+        		|| (superWildcard.fDisallowedNamesList != null && allowedNames(wildcard, superWildcard))) {
+        	return false;
+        }
+
+        return true;
+    }
+
+    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;
+        }
+
+        // The {variety} and {namespaces} of O are consistent with O being the wildcard
+        // union of O1 and O2 if and only if one of the following is true
+        XSWildcardDecl unionWildcard = new XSWildcardDecl();
+        unionWildcard.fProcessContents = processContents;
+
+        // 1 O, O1, and O2 all have the same {variety} and {namespaces}.
+        if (areSame(wildcard, otherWildcard)) {
+            unionWildcard.fType = wildcard.fType;
+            unionWildcard.fNamespaceList = wildcard.fNamespaceList;
+        }
+        // 2 Either O1 or O2 has {variety} any, and O has {variety} any.
+        else if ( (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) || (otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) ) {
+            unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_ANY;
+        }
+        // 3 O, O1, and O2 all have {variety} enumeration, and O's {namespaces} is the union
+        //   of O1's {namespaces} and O2's {namespaces}.
+        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 O1 and O2 both have {variety} not, and one of the following is true
+        else if ( (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) && (otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) ) {
+            //   4.1 The intersection of the {namespaces} of O1 and O2 is the empty set, and O has {variety} = any.        	
+            String[] nsList = intersect2sets(wildcard.fNamespaceList, otherWildcard.fNamespaceList);
+            if (nsList.length == 0) {
+                unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_ANY;
+            }
+            //   4.2 O also has {variety} not, and the {namespaces} of O is the non-empty intersection of the {namespaces} of O1 and O2.            
+            else {
+                unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_NOT;
+                unionWildcard.fNamespaceList = nsList;
+            }
+        }
+        // 5 Either O1 or O2 has {variety} not and {namespaces} S1, and the other has {variety} enumeration and {namespaces} S2, and one of the following is true
+        //   5.1 The set difference S1 minus S2 is the empty set, and O has {variety} = any.
+        //   5.2 O has {variety} = not and the {namespaces} of O is the non-empty set difference S1 minus S2.
+        else {
+            String[] nsList = (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT)
+                ? difference2sets(wildcard.fNamespaceList, otherWildcard.fNamespaceList) : difference2sets(otherWildcard.fNamespaceList, wildcard.fNamespaceList);
+            if (nsList.length == 0) {
+                unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_ANY;
+            }
+            else {
+                unionWildcard.fType = XSWildcardDecl.NSCONSTRAINT_NOT;
+                unionWildcard.fNamespaceList = nsList;
+            }
+        }
+
+        // The {disallowed names} property of O is consistent with O being the wildcard union of O1 and O2
+        // if and only if O's {disallowed names} includes all and only the following:
+        // 1 QName members of O1's {disallowed names} that are not allowed by O2, as defined in Wildcard allows Expanded Name (3.10.4.2).
+        // 2 QName members of O2's {disallowed names} that are not allowed by O1.
+        unionWildcard.fDisallowedNamesList = disallowedNamesUnion(wildcard, otherWildcard);
+
+        // 3 The keyword defined if it is contained in both O1's and O2's {disallowed names}.;
+        // 4 If one {disallowed names} (assume it is from O1 without losing generality) contains defined and the other
+        //   one (from O2) does not, and there exists a namespace name or absent that is allowed by O1, as defined
+        //   in Wildcard allows Namespace Name (3.10.4.), but not by O2, then the wildcard union is not expressible.
+        unionWildcard.fDisallowedDefined = wildcard.fDisallowedDefined && otherWildcard.fDisallowedDefined;
+        if (wildcard.fDisallowedDefined != otherWildcard.fDisallowedDefined) {
+            if (wildcard.fDisallowedDefined) {
+                if (disallowedNamespaces(wildcard, otherWildcard)) {
+                    return null;
+                }
+            }
+            else if (disallowedNamespaces(otherWildcard, wildcard)){
+                return null;
+            }
+        }
+
+        return unionWildcard;
+    }
+
+    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;
+        }
+
+        // The {variety} and {namespaces} of O are consistent with O being the wildcard intersection of O1 and O2 if and only if
+        XSWildcardDecl intersectWildcard = new XSWildcardDecl();
+        intersectWildcard.fProcessContents = processContents;
+
+        // 1 O, O1, and O2 have the same {variety} and {namespaces}.
+        if (areSame(wildcard, otherWildcard)) {
+            intersectWildcard.fType = wildcard.fType;
+            intersectWildcard.fNamespaceList = wildcard.fNamespaceList;
+        }
+        // 2 Either O1 or O2 has {variety} = any and O has {variety} and {namespaces} identical to those of the other.
+        else if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY || otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) {
+            // both cannot be ANY, if we have reached here.
+            XSWildcardDecl localWildcard = wildcard;
+
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) {
+                localWildcard = otherWildcard;
+            }
+
+            intersectWildcard.fType = localWildcard.fType;
+            intersectWildcard.fNamespaceList = localWildcard.fNamespaceList;
+        }
+        // 3 O, O1, and O2 all have {variety} = enumeration, and the {namespaces} of O is the intersection of the {namespaces} of O1 and O2.
+        else if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST || otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST) {
+            intersectWildcard.fType = XSWildcardDecl.NSCONSTRAINT_LIST;
+            intersectWildcard.fNamespaceList = intersect2sets(wildcard.fNamespaceList, otherWildcard.fNamespaceList);
+        }
+        // 4 O, O1, and O2 all have {variety} not, and the {namespaces} of O is the union of the {namespaces} of O1 and O2.
+        else if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT || otherWildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
+            intersectWildcard.fType = XSWildcardDecl.NSCONSTRAINT_NOT;
+            intersectWildcard.fNamespaceList = union2sets(wildcard.fNamespaceList, otherWildcard.fNamespaceList);
+        }
+        // 5 Either O1 or O2 has {variety} = not and {namespaces} = S1 and the other has {variety} = enumeration and {namespaces} = S2, and O has {variety} = enumeration and {namespaces} = the set difference S2 minus S1.
+        else {
+            intersectWildcard.fType = XSWildcardDecl.NSCONSTRAINT_LIST;
+            intersectWildcard.fNamespaceList = (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT)
+                ? difference2sets(otherWildcard.fNamespaceList, wildcard.fNamespaceList) : difference2sets(wildcard.fNamespaceList, otherWildcard.fNamespaceList);
+        }
+
+        // The {disallowed names} property of O is consistent with O being the wildcard intersection of O1 and O2
+        // if and only if O's {disallowed names} includes all and only the following:
+        // 1 QName members of O1's {disallowed names} that are allowed by O2, as defined in Wildcard allows Expanded Name (3.10.4.2).
+        // 2 QName members of O2's {disallowed names} that are allowed by O1.
+        // 3 The intersection of O1's {disallowed names} and O2's {disallowed names}.
+        // 4 The keyword defined if it is a member of either {disallowed names}.
+        intersectWildcard.fDisallowedNamesList = disallowedNamesIntersection(wildcard, otherWildcard);
+        intersectWildcard.fDisallowedDefined = wildcard.fDisallowedDefined || otherWildcard.fDisallowedDefined;
+
+        return intersectWildcard;
+    }
+
+    /**
+     * Wildcard constraints - helper methods
+     */
+    // REVISIT: update the method in XSConstraints (remove the check for not(list))
+    boolean areSame(XSWildcardDecl wildcard, XSWildcardDecl otherWildcard) {
+        if (wildcard.fType == otherWildcard.fType) {
+            // ##any, true
+            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) {
+                return true;
+            }
+
+            // ## list [enumeration] or [not], 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
+    
+    private boolean allowedNames(XSWildcardDecl wildcard, XSWildcardDecl superWildcard) {
+        for (int i = 0; i < superWildcard.fDisallowedNamesList.length; i++) {
+            if (wildcard.allowQName(superWildcard.fDisallowedNamesList[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    // A namespace name or absent that is allowed by o1, as defined in Wildcard allows Namespace
+    // Name (3.10.4.3), but not by o2
+    private boolean disallowedNamespaces(XSWildcardDecl o1, XSWildcardDecl o2) {
+    	// o2 has variety of {any} so it allows any namesapce
+    	if (o2.fType == XSWildcardDecl.NSCONSTRAINT_ANY) {
+    		return false;
+    	}
+
+    	// o1 allows any namespace, but o2 is restrictive
+        if (o1.fType == XSWildcardDecl.NSCONSTRAINT_ANY) {
+        	return true;
+        }
+
+        // o1 allows a list of namespace, so check to see if any of the
+        // namespaces in the list is disallowed by o2
+        if (o1.fType == XSWildcardDecl.NSCONSTRAINT_LIST) {
+            for (int i = 0; i < o1.fNamespaceList.length; i++) {
+                if (!o2.allowNamespace(o1.fNamespaceList[i])) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        // o2 disallows a list of namespaces, so check to see if any
+        // of the namespaces in the list is allowed by o1
+        if (o2.fType == XSWildcardDecl.NSCONSTRAINT_NOT){
+            for (int i=0; i<o2.fNamespaceList.length; i++) {
+                if (o1.allowNamespace(o2.fNamespaceList[i])) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        // o1 is not, and o2 is enumaration, so o2 is more restrictive
+        return true;
+    }
+
+    // returns the set difference set1 minus set2
+    private String[] difference2sets(String[] set1, String[] set2) {
+        String[] result = new String[set1.length];
+
+        // simple implemention,
+        int count = 0;
+        for (int i=0; i<set1.length; i++) {
+            if (!elementInSet(set1[i], set2))
+                result[count++] = set1[i];
+        }
+
+        String[] result2 = new String[count];
+        System.arraycopy(result, 0, result2, 0, count);
+
+        return result2;
+    }
+
+    private QName[] disallowedNamesUnion(XSWildcardDecl one, XSWildcardDecl theOther) {
+    	final int len1 = (one.fDisallowedNamesList == null) ? 0 : one.fDisallowedNamesList.length;
+    	final int len2 = (theOther.fDisallowedNamesList == null) ? 0 : theOther.fDisallowedNamesList.length;
+        final QName[] result = new QName[len1 + len2];
+
+        // simple implementation
+        int count = 0;
+        for (int i=0; i<len1; i++) {
+            if (!theOther.allowQName(one.fDisallowedNamesList[i])) {
+                result[count++] = one.fDisallowedNamesList[i];
+            }
+        }
+        for (int i=0; i<len2; i++) {
+            if (!one.allowQName(theOther.fDisallowedNamesList[i])) {
+                result[count++] = theOther.fDisallowedNamesList[i];
+            }
+        }
+        QName[] result2 = new QName[count];
+        System.arraycopy(result, 0, result2, 0, count);
+        return result2;
+    }
+
+    // 1 QName members of O1's {disallowed names} that are allowed by O2, as defined in Wildcard allows Expanded Name (3.10.4).
+    // 2 QName members of O2's {disallowed names} that are allowed by O1.
+    // 3 The intersection of O1's {disallowed names} and O2's {disallowed names}.
+    private QName[] disallowedNamesIntersection(XSWildcardDecl one, XSWildcardDecl theOther) {
+    	final int len1 = (one.fDisallowedNamesList == null) ? 0 : one.fDisallowedNamesList.length;
+    	final int len2 = (theOther.fDisallowedNamesList == null) ? 0 : theOther.fDisallowedNamesList.length;
+        final QName[] result = new QName[len1 + len2];
+
+        // simple implementation
+        int count = 0;
+        for (int i=0; i<len1; i++) {
+        	final QName qname = one.fDisallowedNamesList[i];
+            if (theOther.allowQName(qname)) {
+                result[count++] = qname;
+            }
+            // intersection of O1.disallowed names and O2.disallowed names
+            else if (elementInSet(qname, theOther.fDisallowedNamesList)) {
+                result[count++] = qname;
+            }
+        }
+        for (int i=0; i<len2; i++) {
+            if (one.allowQName(theOther.fDisallowedNamesList[i])) {
+                result[count++] = theOther.fDisallowedNamesList[i];
+            }
+        }
+
+        QName[] result2 = new QName[count];
+        System.arraycopy(result, 0, result2, 0, count);
+        return result2;
+    }
+
+    private boolean elementInSet(QName ele, QName[] eleSet){
+        boolean found = false;
+        final int length = (eleSet == null) ? 0 : eleSet.length;
+        for (int i=0; i<length && !found; i++) {
+            if (ele.equals(eleSet[i])) {
+                found = true;
+            }
+        }
+
+        return found;
+    }
 }

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=707475&r1=707474&r2=707475&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 Thu Oct 23 14:12:24 2008
@@ -1479,289 +1479,11 @@
             }
         }
     }
-
-    // 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
+     * Wildcard constraints - helper methods
      */
-    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) {
+    boolean areSame(XSWildcardDecl wildcard, XSWildcardDecl otherWildcard) {
         if (wildcard.fType == otherWildcard.fType) {
             // ##any, true
             if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_ANY) {
@@ -1771,6 +1493,7 @@
             // ##other, only check the negated value
             // * when we support not(list), we need to check in the same way
             //   as for NSCONSTRAINT_LIST.
+            // not(list) is supported - no need for that check
             if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
                 return wildcard.fNamespaceList[0] == otherWildcard.fNamespaceList[0];
             }
@@ -1842,8 +1565,21 @@
 
         return found;
     }
+
+    boolean disjoint2sets(String[] one, String[] theOther) {
+        for (int i=0; i<one.length; i++) {
+            if (elementInSet(one[i], theOther))
+                return false;
+        }
+        return true;
+    }
+    
+    // End wildcard constraints - helper methods
     
-    // End wildcard constraints
+    // Wildcard constraint checking - abstract methods
+    public abstract boolean isSubsetOf(XSWildcardDecl wildcard, XSWildcardDecl superWildcard);
+    public abstract XSWildcardDecl performUnionWith(XSWildcardDecl wildcard, XSWildcardDecl otherWildcard, short processContents);
+    public abstract XSWildcardDecl performIntersectionWith(XSWildcardDecl wildcard, XSWildcardDecl otherWildcard, short processContents);
 
     // to check whether an element overlaps with a wildcard,
     // as defined in constraint UPA

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=707475&r1=707474&r2=707475&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 Thu Oct 23 14:12:24 2008
@@ -57,13 +57,11 @@
     /*
      * XML Schema 1.1
      */
-    // disallowed names flag
-    public boolean fDisallowedNames = false;
     // disallowed names list
     public QName[] fDisallowedNamesList = null;
-    // ##defined {disallowed names}
+    // ##defined
     public boolean fDisallowedDefined = false;
-    // ##definedSibling {disallowed names}
+    // ##definedSibling
     public boolean fDisallowedSibling = false;
 
     // I'm trying to implement the following constraint exactly as what the
@@ -127,11 +125,29 @@
     /**
      * XML Schema 1.1
      * 
-     * Validation Rule: Wildcard allows QName
+     * Validation Rule: Wildcard allows Name
      */
     public boolean allowQName(QName name) {
-        // TODO: apply 1.1 rules
-        return allowNamespace(name.uri);
+        // 1 The namespace name is valid with respect to C, as defined in Wildcard allows Namespace Name (3.10.4.3);
+        // 2 C.{disallowed names} does not contain E.
+        if (allowNamespace(name.uri)) {
+            if (fDisallowedNamesList == null || fDisallowedNamesList.length == 0) {
+                return true;
+            }
+            return isNameAllowed(name.uri, name.localpart);
+        }
+
+        // failed
+        return false;
+    }
+
+    private boolean isNameAllowed(String namespace, String localpart) {
+        for (int i=0; i < fDisallowedNamesList.length; i++) {
+            if (fDisallowedNamesList[i].uri == namespace && fDisallowedNamesList[i].localpart == localpart) {
+                return false;
+            }
+        }
+        return true;
     }
 
     /**
@@ -178,6 +194,26 @@
                 }
                 break;
             }
+            if (fDisallowedNamesList != null) {
+                buffer.append(", notQ(");
+                if (fDisallowedNamesList.length > 0) {
+                    buffer.append(fDisallowedNamesList[0]);
+                    for (int i = 1; i < fDisallowedNamesList.length; i++) {
+                        buffer.append(", ");
+                        buffer.append(fNamespaceList[i]);
+                    }
+                }
+                if (fDisallowedDefined) {
+                    buffer.append(", ");
+                    buffer.append(SchemaSymbols.ATTVAL_TWOPOUNDDEFINED);
+                }
+                if (fDisallowedSibling) {
+                    buffer.append(", ");
+                    buffer.append(SchemaSymbols.ATTVAL_TWOPOUNDDEFINEDSIBLING);
+                }
+                buffer.append(")");
+            }
+
             buffer.append("]");
             fDescription = buffer.toString();
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java?rev=707475&r1=707474&r2=707475&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XS11AllCM.java Thu Oct 23 14:12:24 2008
@@ -19,6 +19,7 @@
 
 import java.util.Vector;
 
+import org.apache.xerces.impl.xs.SchemaGrammar;
 import org.apache.xerces.impl.xs.SubstitutionGroupHandler;
 import org.apache.xerces.impl.xs.XMLSchemaException;
 import org.apache.xerces.impl.xs.XSConstraints;
@@ -134,6 +135,34 @@
         return matchingDecl;
     }
 
+    // convinient method: to find a matching element decl 
+    XSElementDecl findMatchingElemDecl(QName elementName, SubstitutionGroupHandler subGroupHandler) {
+        for (int i = 0; i < fNumElements; i++) {
+            final XSElementDecl matchingDecl = subGroupHandler.getMatchingElemDecl(elementName, (XSElementDecl)fAllDecls[i]);
+            if (matchingDecl != null) {
+                return matchingDecl;
+            }
+        }
+
+        return null;
+    }
+
+    private boolean allowExpandedName(XSWildcardDecl wildcard,
+                                      QName curElem,
+                                      SubstitutionGroupHandler subGroupHandler,
+                                      SchemaGrammar grammar) {
+        if (wildcard.allowQName(curElem)) {
+            if (wildcard.fDisallowedSibling && findMatchingElemDecl(curElem, subGroupHandler) != null) {
+                return false;
+            }
+            if (wildcard.fDisallowedDefined && grammar.getElementDeclaration(curElem.localpart) != null) {
+                return false;
+            }
+            return true;
+        }
+        return false;
+    }
+
     /**
      * The method corresponds to one transition in the content model.
      *
@@ -141,7 +170,7 @@
      * @param currentState  Current state
      * @return an element decl object
      */
-    public Object oneTransition (QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler) {
+    public Object oneTransition (QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler, SchemaGrammar grammar) {
         // error state
         if (currentState[0] < 0) {
             currentState[0] = XSCMValidator.SUBSEQUENT_ERROR;
@@ -150,7 +179,7 @@
 
         // open content - suffix mode
         if (currentState[0] == STATE_SUFFIX) {
-            if (fOpenContent.fWildcard.allowQName(elementName)) {
+            if (allowExpandedName(fOpenContent.fWildcard, elementName, subGroupHandler, grammar)) {
                 return fOpenContent;
             }
             else { // error
@@ -180,7 +209,7 @@
             if (currentState[i + 1] == fDeclsOccurs[declMaxOccurs]) {
                 continue;
             }
-            if (((XSWildcardDecl)fAllDecls[i]).allowQName(elementName)) {
+            if (allowExpandedName((XSWildcardDecl)fAllDecls[i], elementName, subGroupHandler, grammar)) {
                 // found the decl, mark this element as "seen".
                 ++currentState[i + 1];
                 return fAllDecls[i];
@@ -198,7 +227,8 @@
                     return findMatchingDecl(elementName, subGroupHandler);
                 }
             }
-            if (fOpenContent.fWildcard.allowQName(elementName)) {
+            if (allowExpandedName(fOpenContent.fWildcard, elementName, subGroupHandler, grammar)) {
+            //if (fOpenContent.fWildcard.allowQName(elementName)) {
                 return fOpenContent;
             }
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java?rev=707475&r1=707474&r2=707475&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSAllCM.java Thu Oct 23 14:12:24 2008
@@ -19,6 +19,7 @@
 
 import java.util.Vector;
 
+import org.apache.xerces.impl.xs.SchemaGrammar;
 import org.apache.xerces.impl.xs.SubstitutionGroupHandler;
 import org.apache.xerces.impl.xs.XMLSchemaException;
 import org.apache.xerces.impl.xs.XSConstraints;
@@ -111,7 +112,7 @@
      * @param currentState  Current state
      * @return an element decl object
      */
-    public Object oneTransition (QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler) {
+    public Object oneTransition (QName elementName, int[] currentState, SubstitutionGroupHandler subGroupHandler, SchemaGrammar grammar) {
 
         // error state
         if (currentState[0] < 0) {

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java?rev=707475&r1=707474&r2=707475&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/models/XSCMValidator.java Thu Oct 23 14:12:24 2008
@@ -19,6 +19,7 @@
 
 import java.util.Vector;
 
+import org.apache.xerces.impl.xs.SchemaGrammar;
 import org.apache.xerces.impl.xs.SubstitutionGroupHandler;
 import org.apache.xerces.impl.xs.XMLSchemaException;
 import org.apache.xerces.impl.xs.XSConstraints;
@@ -57,10 +58,11 @@
      *
      * @param elementName
      * @param state  Current state
+     * @param grammar SchemaGrammar that corresponds to the namespace of the element
      * @return element decl or wildcard decl that
      *         corresponds to the element from the Schema grammar
      */
-    public Object oneTransition (QName elementName, int[] state, SubstitutionGroupHandler subGroupHandler);
+    public Object oneTransition (QName elementName, int[] state, SubstitutionGroupHandler subGroupHandler, SchemaGrammar grammar);
 
 
     /**



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