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 2011/08/31 20:38:10 UTC

svn commit: r1163737 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces: impl/xs/ impl/xs/traversers/ impl/xs/util/ util/

Author: knoaman
Date: Wed Aug 31 18:38:10 2011
New Revision: 1163737

URL: http://svn.apache.org/viewvc?rev=1163737&view=rev
Log:
Support additional rules for EDC - Jira 1526
https://issues.apache.org/jira/browse/XERCESJ-1526

Modified:
    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/traversers/XSAttributeChecker.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
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/DOMUtil.java

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=1163737&r1=1163736&r2=1163737&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 Wed Aug 31 18:38:10 2011
@@ -17,15 +17,24 @@
 
 package org.apache.xerces.impl.xs;
 
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Stack;
+
 import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.XMLErrorReporter;
 import org.apache.xerces.impl.dv.XSSimpleType;
+import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
 import org.apache.xerces.impl.xs.models.CMBuilder;
 import org.apache.xerces.impl.xs.models.XS11CMRestriction;
 import org.apache.xerces.impl.xs.models.XSCMValidator;
 import org.apache.xerces.impl.xs.util.SimpleLocator;
 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
+import org.apache.xerces.util.NamespaceSupport;
+import org.apache.xerces.util.SymbolHash;
 import org.apache.xerces.xni.QName;
+import org.apache.xerces.xs.XSConstants;
+import org.apache.xerces.xs.XSTypeDefinition;
 
 /**
  * XML Schema 1.1 constraints
@@ -50,6 +59,231 @@ class XS11Constraints extends XSConstrai
     }
 
     /**
+     * Check that a given particle is a valid restriction of a base particle.
+     */
+    final protected void checkElementDeclsConsistent(XSComplexTypeDecl type,
+            XSParticleDecl particle,
+            SymbolHash elemDeclHash,
+            SubstitutionGroupHandler sgHandler,
+            XSGrammarBucket grammarBucket,
+            ArrayList wcList,
+            Stack elemDeclStack) throws XMLSchemaException {
+
+        // check for elements in the tree with the same name and namespace
+        if (particle.fType == XSParticleDecl.PARTICLE_WILDCARD) {
+            return;
+        }
+
+        // clear wildcard decl list and element decl stack
+        if (wcList.size() > 0) {
+            wcList.clear();
+        }
+        
+        if (elemDeclStack.size() > 0) {
+            elemDeclStack.clear();
+        }
+
+        // check for open content
+        if (type.fOpenContent != null) {
+            final XSWildcardDecl wc = type.fOpenContent.fWildcard;
+            if (wc != null && wc.fProcessContents != XSWildcardDecl.PC_SKIP) {
+                wcList.add(wc);
+            }
+        }
+
+        if (particle.fType == XSParticleDecl.PARTICLE_ELEMENT) {
+            elemDeclStack.push((XSElementDecl)(particle.fValue));
+        }
+        else  {
+            preprocessModelGroupParticle((XSModelGroupImpl)particle.fValue, wcList, elemDeclStack);
+        }
+
+        // process element declarations
+        while (!elemDeclStack.empty()) {
+            final XSElementDecl elem = (XSElementDecl)elemDeclStack.pop();
+
+            findElemInTable(type, elem, elemDeclHash);
+
+            if (elem.fScope == XSConstants.SCOPE_GLOBAL) {
+                // Check for substitution groups.
+                XSElementDecl[] subGroup = sgHandler.getSubstitutionGroup(elem, fSchemaVersion);
+                for (int i = 0; i < subGroup.length; i++) {
+                    findElemInTable(type, subGroup[i], elemDeclHash);
+                }
+            }
+            else {
+                checkExtraEDCRules(type, elem, grammarBucket, wcList);
+            }
+        }
+    }
+
+    final public void findElemInTable(XSComplexTypeDecl type,
+            XSElementDecl elem,
+            SymbolHash elemDeclHash)
+        throws XMLSchemaException {
+
+        final XSElementDecl existingElem = findExistingElement(elem, elemDeclHash);
+
+        // First time or is same element
+        if (existingElem == null || existingElem == elem) {
+            return;
+        }
+
+        if (elem.fType != existingElem.fType) {
+            // Types are not the same
+            throw new XMLSchemaException("cos-element-consistent", new Object[] {type.fName, elem.fName});
+        }
+
+        if (!isTypeTablesEquivalent(elem, existingElem)) {
+            // Type tables are not equivalent
+            throw new XMLSchemaException("cos-element-consistent.4.b", new Object[] {type.fName, elem.fName});  
+        }
+    }
+
+    protected void preprocessModelGroupParticle(XSModelGroupImpl group, ArrayList wcList, Stack elemDeclStack) {
+        for (int i = group.fParticleCount - 1; i >=0 ; i--) {
+            final XSParticleDecl particle = group.fParticles[i];
+            final int pType = particle.fType;
+            if (pType == XSParticleDecl.PARTICLE_WILDCARD) {
+                final XSWildcardDecl wc = (XSWildcardDecl) particle.fValue;
+                if (wc.fProcessContents != XSWildcardDecl.PC_SKIP) {
+                    wcList.add(wc);
+                }
+            }
+            else if (pType == XSParticleDecl.PARTICLE_ELEMENT) {
+                elemDeclStack.push((XSElementDecl)particle.fValue);
+            }
+            else {
+                preprocessModelGroupParticle((XSModelGroupImpl)particle.fValue, wcList, elemDeclStack);
+            }
+        }
+    }
+
+    private void checkExtraEDCRules(XSComplexTypeDecl type,
+            XSElementDecl elem,
+            XSGrammarBucket grammarBucket,
+            ArrayList wcList) throws XMLSchemaException {
+        
+        // If all of the following are true:
+        //  1 The {particles} property contains (either directly, indirectly,
+        //    or implicitly) one or more element declarations with the same
+        //    expanded name Q; call these element declarations EDS.
+        //  2 At least one of the following is true
+        //    2.1 The {particles} property contains one or more strict or lax
+        //        wildcard particles which match Q.
+        //    2.2 The Model Group is the {term} of the content model of some
+        //        Complex Type Definition CTD and CTD.{content type} has an
+        //        {open content} with a strict or lax Wildcard which matches Q.
+        //  3 There exists a top-level element declaration G with the expanded
+        //    name Q.
+        //  then the {type table}s of EDS and the {type table} of G must either
+        //  all be absent or else all be present and equivalent.
+        for (int i=0; i<wcList.size(); i++) {
+            final XSWildcardDecl wc = (XSWildcardDecl) wcList.get(i);
+            if (wc.allowName(elem.fTargetNamespace, elem.fName)) {
+                final SchemaGrammar grammar = grammarBucket.getGrammar(elem.fTargetNamespace);
+                if (grammar != null) {
+                    final XSElementDecl gElem = grammar.getGlobalElementDecl(elem.fName);
+                    if (gElem != null) {
+                        if (gElem != elem && !isTypeTablesEquivalent(elem, gElem)) {
+                            // Type tables are not equivalent
+                            throw new XMLSchemaException("cos-element-consistent.4.b", new Object[] {type.fName, elem.fName});
+                        }
+                    }
+                } 
+            }
+        }
+    }
+
+    /*
+     * Check if two type tables are equivalent.
+     */
+    protected boolean isTypeTablesEquivalent(XSElementDecl elementDecl1, XSElementDecl elementDecl2) {
+        
+        final XSTypeAlternativeImpl[] typeTable1 = elementDecl1.getTypeAlternatives();
+        final XSTypeAlternativeImpl[] typeTable2 = elementDecl2.getTypeAlternatives();
+
+        // both tables are absent
+        if (typeTable1 == typeTable2) {
+            return true;
+        }
+        
+        // one of the tables is absent or has a different length
+        if (typeTable1 == null || typeTable2 == null 
+                || typeTable1.length != typeTable2.length) {
+            return false;
+        }
+
+        for (int typeAltIdx = 0; typeAltIdx < typeTable1.length; typeAltIdx++) {
+            final XSTypeAlternativeImpl typeAlt1 = typeTable1[typeAltIdx];
+            final XSTypeAlternativeImpl typeAlt2 = typeTable2[typeAltIdx];
+            if (!isTypeAlternativesEquivalent(typeAlt1, typeAlt2)) {
+                return false;
+            }
+        }
+
+        return isTypeAlternativesEquivalent(elementDecl1.getDefaultTypeDefinition(), elementDecl2.getDefaultTypeDefinition());        
+    } // isTypeTablesEquivalent
+
+    /*
+     * Check if two type alternative components are equivalent.
+     */
+    private boolean isTypeAlternativesEquivalent(XSTypeAlternativeImpl typeAlt1, XSTypeAlternativeImpl typeAlt2) {
+        
+        final String defNamespace1 = typeAlt1.getXPathDefaultNamespace();
+        final String defNamespace2 = typeAlt2.getXPathDefaultNamespace();
+        final String testStr1 = (typeAlt1.getTest() == null) ? null : typeAlt1.getTest().toString();
+        final String testStr2 = (typeAlt2.getTest() == null) ? null : typeAlt2.getTest().toString();
+        final XSTypeDefinition typeDefn1 = typeAlt1.getTypeDefinition();
+        final XSTypeDefinition typeDefn2 = typeAlt2.getTypeDefinition();
+        final String baseURI1 = typeAlt1.getBaseURI();
+        final String baseURI2 = typeAlt2.getBaseURI();
+
+        // 2 T1.{test}.{default namespace}  and T2.{test}.{default namespace}
+        //   either are both absent or have the same value.
+        // 3 T1.{test}.{base URI} and T2.{test}.{base URI} either are both
+        //   absent or have the same value.
+        // 4 T1.{test}.{expression} and T2.{test}.{expression} have the same
+        //   value.
+        // 5 T1.{type definition} and T2.{type definition} are the same type
+        //   definition. 
+        if (defNamespace1 != defNamespace2 || typeDefn1 != typeDefn2
+                || (testStr1 == null && testStr2 != null)
+                || (testStr1 != null && !testStr1.equals(testStr2))
+                || (baseURI1 == null && baseURI2 != null)
+                || (baseURI1 != null && !baseURI1.equals(baseURI2))) {
+            return false;
+        }
+        
+        // 1 T1.{test}.{namespace bindings} and T2.{test}.{namespace bindings}
+        //   have the same number of Namespace Bindings, and for each entry in
+        //   T1.{test}.{namespace bindings}  there is a corresponding entry in
+        //   T2.{test}.{namespace bindings}  with the same {prefix} and
+        //   {namespace}. 
+        final NamespaceSupport nsContext1 = typeAlt1.getNamespaceContext();
+        final NamespaceSupport nsContext2 = typeAlt2.getNamespaceContext();
+        final Enumeration prefixes1 =  nsContext1.getAllPrefixes();
+        final Enumeration prefixes2 =  nsContext2.getAllPrefixes();
+
+        // REVISIT: optimize (same number + prefix/uri mapping)
+        while (prefixes1.hasMoreElements()) {
+            if (!prefixes2.hasMoreElements()) {
+                return false;
+            }
+            
+            final String prefix1 = (String) prefixes1.nextElement();
+            final String prefix2 = (String) prefixes2.nextElement();
+
+            if (nsContext1.getURI(prefix1) != nsContext2.getURI(prefix1)
+                    || nsContext1.getURI(prefix2) != nsContext2.getURI(prefix2)) {
+                return false;
+            }
+        }
+
+        return !prefixes2.hasMoreElements();        
+    } // isTypeAlternativesEquivalent
+
+    /**
      *  Schema Component Constraint: Wildcard Subset
      */
     public boolean isSubsetOf(XSWildcardDecl wildcard, XSWildcardDecl superWildcard) {

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=1163737&r1=1163736&r2=1163737&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 Wed Aug 31 18:38:10 2011
@@ -17,6 +17,9 @@
 
 package org.apache.xerces.impl.xs;
 
+import java.util.ArrayList;
+import java.util.Stack;
+
 import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.XMLErrorReporter;
 import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
@@ -394,6 +397,8 @@ public abstract class XSConstraints {
         // i: grammar; j: type; k: error
         // for all grammars
         SymbolHash elemTable = new SymbolHash();
+        Stack stack = new Stack();
+        ArrayList wcList = (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) ? new ArrayList() : null;
         for (int i = grammars.length-1, j; i >= 0; i--) {
             // get whether to skip EDC, and types need to be checked
             keepType = 0;
@@ -410,7 +415,8 @@ public abstract class XSConstraints {
                         elemTable.clear();
                         try {
                             checkElementDeclsConsistent(types[j], types[j].fParticle,
-                                    elemTable, SGHandler);
+                                    elemTable, SGHandler, grammarBucket,
+                                    wcList, stack);
                         }
                         catch (XMLSchemaException e) {
                             reportSchemaError(errorReporter, ctLocators[j],
@@ -491,7 +497,8 @@ public abstract class XSConstraints {
     }
 
     /*
-       Check that a given particle is a valid restriction of a base particle.
+     * Check that a given particle is a valid restriction of a base particle.
+     * NOTE: deprecated
      */
     public void checkElementDeclsConsistent(XSComplexTypeDecl type,
             XSParticleDecl particle,
@@ -524,128 +531,80 @@ public abstract class XSConstraints {
             checkElementDeclsConsistent(type, group.fParticles[i], elemDeclHash, sgHandler);
     }
 
-    public void findElemInTable(XSComplexTypeDecl type, XSElementDecl elem,
-            SymbolHash elemDeclHash)
-        throws XMLSchemaException {
+    protected void checkElementDeclsConsistent(XSComplexTypeDecl type,
+            XSParticleDecl particle,
+            SymbolHash elemDeclHash,
+            SubstitutionGroupHandler sgHandler,
+            XSGrammarBucket grammarBucket,
+            ArrayList wcList,
+            Stack stack) throws XMLSchemaException {
 
-        // How can we avoid this concat?  LM.
-        String name = elem.fName + "," + elem.fTargetNamespace;
+        // check for elements in the tree with the same name and namespace
 
-        XSElementDecl existingElem = null;
-        if ((existingElem = (XSElementDecl)(elemDeclHash.get(name))) == null) {
-            // just add it in
-            elemDeclHash.put(name, elem);
-        }
-        else {
-            // If this is the same check element, we're O.K.
-            if (elem == existingElem)
-                return;
-
-            if (elem.fType != existingElem.fType) {
-                // Types are not the same
-                throw new XMLSchemaException("cos-element-consistent", new Object[] {type.fName, elem.fName});
-            }
-            else if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1 && !isTypeTablesEquivalent(elem, existingElem)) {
-                // Type tables are not equivalent
-                throw new XMLSchemaException("cos-element-consistent.4.b", new Object[] {type.fName, elem.fName});  
-            }
+        if (stack.size() > 0) {
+            stack.clear();
         }
-    }
-    
-    /*
-     * Check if two type tables are equivalent.
-     */
-    private boolean isTypeTablesEquivalent(XSElementDecl elementDecl1, XSElementDecl elementDecl2) {
-        
-        boolean isTypeTablesEquivalent = true;
-        
-        XSTypeAlternativeImpl[] typeTable1 = elementDecl1.getTypeAlternatives();
-        XSTypeAlternativeImpl[] typeTable2 = elementDecl2.getTypeAlternatives();
-        
-        if (typeTable1 != null && typeTable2 != null) {
-            if (typeTable1.length != typeTable2.length) {
-                isTypeTablesEquivalent = false; 
+
+        for (;;) {
+            final int pType = particle.fType;
+
+            if (pType == XSParticleDecl.PARTICLE_WILDCARD) {
+                // no op
             }
-            else {
-                for (int typeAltIdx = 0; typeAltIdx < typeTable1.length; typeAltIdx++) {
-                    XSTypeAlternativeImpl typeAlt1 = typeTable1[typeAltIdx];
-                    XSTypeAlternativeImpl typeAlt2 = typeTable2[typeAltIdx];
-                    if (!isTypeAlternativesEquivalent(typeAlt1, typeAlt2)) {
-                        isTypeTablesEquivalent = false;
-                        break;
+            else  if (pType == XSParticleDecl.PARTICLE_ELEMENT) {
+                XSElementDecl elem = (XSElementDecl)(particle.fValue);
+                findElemInTable(type, elem, elemDeclHash);
+
+                if (elem.fScope == XSConstants.SCOPE_GLOBAL) {
+                    // Check for subsitution groups.
+                    XSElementDecl[] subGroup = sgHandler.getSubstitutionGroup(elem, fSchemaVersion);
+                    for (int i = 0; i < subGroup.length; i++) {
+                        findElemInTable(type, subGroup[i], elemDeclHash);
                     }
                 }
             }
-            if (isTypeTablesEquivalent && !isTypeAlternativesEquivalent(elementDecl1.getDefaultTypeDefinition(), elementDecl2.getDefaultTypeDefinition())) {
-                isTypeTablesEquivalent = false; 
+            else {
+                XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue;
+                for (int i = group.fParticleCount - 1; i >= 0 ; i--)
+                    stack.push(group.fParticles[i]);
+            }
+            
+            if (stack.isEmpty()) {
+                break;
             }
+            particle = (XSParticleDecl) stack.pop();
         }
-        else if ((typeTable1 != null && typeTable2 == null) || (typeTable1 == null && typeTable2 != null)) {
-            isTypeTablesEquivalent = false;  
-        }
-        
-        return isTypeTablesEquivalent;
-        
-    } // isTypeTablesEquivalent
-    
-    /*
-     * Check if two type alternative components are equivalent.
-     */
-    private boolean isTypeAlternativesEquivalent(XSTypeAlternativeImpl typeAlt1, XSTypeAlternativeImpl typeAlt2) {
-        
-        boolean isTypeAlternativesEquivalent = false;
-        
-        String defNamespace1 = typeAlt1.getXPathDefaultNamespace();
-        String defNamespace2 = typeAlt2.getXPathDefaultNamespace();
-        String testStr1 = (typeAlt1.getTest() == null) ? null : typeAlt1.getTest().toString();
-        String testStr2 = (typeAlt2.getTest() == null) ? null : typeAlt2.getTest().toString();
-        XSTypeDefinition typeDefn1 = typeAlt1.getTypeDefinition();
-        XSTypeDefinition typeDefn2 = typeAlt2.getTypeDefinition();
-        
-        // check equivalence of defaultNamespace, test expression & type definition
-        if (((defNamespace1 == null && defNamespace2 == null) || (defNamespace1 != null && defNamespace2 != null && defNamespace1.equals(defNamespace2))) &&
-            ((testStr1 == null && testStr2 == null) || (testStr1 != null && testStr2 != null && (testStr1.trim()).equals(testStr2.trim()))) &&
-            (XSTypeHelper.isSchemaTypesIdentical(typeDefn1, typeDefn2))) {
-              isTypeAlternativesEquivalent = true;
+    }
+
+    public void findElemInTable(XSComplexTypeDecl type, XSElementDecl elem,
+            SymbolHash elemDeclHash)
+        throws XMLSchemaException {
+
+        final XSElementDecl existingElem = findExistingElement(elem, elemDeclHash);
+
+        // First time or is same element
+        if (existingElem == null || existingElem == elem) {
+            return;
         }
-        
-        // check equivalence of namespace bindings
-        if (isTypeAlternativesEquivalent) {
-            NamespaceSupport typeAlt1NamespaceContext = typeAlt1.getNamespaceContext();
-            NamespaceSupport typeAlt2NamespaceContext = typeAlt2.getNamespaceContext();
-            int nsDeclPrefixCount1 = typeAlt1NamespaceContext.getDeclaredPrefixCount();
-            if (nsDeclPrefixCount1 == typeAlt2NamespaceContext.getDeclaredPrefixCount()) {
-                for (int prefIdx1 = 0; prefIdx1 < nsDeclPrefixCount1; prefIdx1++) {
-                    String prefix1 = typeAlt1NamespaceContext.getDeclaredPrefixAt(prefIdx1);
-                    if (!(typeAlt2NamespaceContext.containsPrefix(prefix1) && (typeAlt1NamespaceContext.getURI(prefix1) == typeAlt2NamespaceContext.getURI(prefix1)))) {
-                        isTypeAlternativesEquivalent = false;
-                        break;
-                    }
-                }
-            }
-            else {
-                isTypeAlternativesEquivalent = false;  
-            }
+
+        if (elem.fType != existingElem.fType) {
+            // Types are not the same
+            throw new XMLSchemaException("cos-element-consistent", new Object[] {type.fName, elem.fName});
         }
-        
-        // check equivalence of base URIs
-        if (isTypeAlternativesEquivalent) {
-            String baseURI1 = typeAlt1.getBaseURI();
-            String baseURI2 = typeAlt2.getBaseURI();
-            if ((baseURI1 == null && baseURI2 != null) || (baseURI2 == null && baseURI1 != null)) {
-                isTypeAlternativesEquivalent = false; 
-            }
-            else if ((baseURI1 == null && baseURI2 == null) || baseURI1.equals(baseURI2)) {
-                isTypeAlternativesEquivalent = true;
-            }
-            else {
-                isTypeAlternativesEquivalent = false;
-            }
+    }
+
+    protected XSElementDecl findExistingElement(XSElementDecl elem, SymbolHash elemDeclHash) {
+        // How can we avoid this concat?  LM.
+        String name = elem.fName + "," + elem.fTargetNamespace;
+        XSElementDecl existingElem = (XSElementDecl)(elemDeclHash.get(name));
+
+        if (existingElem == null) {
+            // just add it in
+            elemDeclHash.put(name, elem);
         }
         
-        return isTypeAlternativesEquivalent;
-        
-    } // isTypeAlternativesEquivalent
+        return existingElem;
+    }
 
     // to check whether two element overlap, as defined in constraint UPA
     protected boolean overlapUPA(XSElementDecl element1,

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java?rev=1163737&r1=1163736&r2=1163737&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java Wed Aug 31 18:38:10 2011
@@ -127,14 +127,15 @@ public class XSAttributeChecker {
     public static final int ATTIDX_ISRETURNED        = ATTIDX_COUNT++;
     
     //  Schema 1.1
-    public static final int ATTIDX_APPLIESTOEMPTY    = ATTIDX_COUNT++;
-    public static final int ATTIDX_DEFAULTATTRAPPLY  = ATTIDX_COUNT++;
-    public static final int ATTIDX_DEFAULTATTRIBUTES = ATTIDX_COUNT++;    
-    public static final int ATTIDX_MODE              = ATTIDX_COUNT++;
-    public static final int ATTIDX_NOTNAMESPACE      = ATTIDX_COUNT++;
-    public static final int ATTIDX_NOTQNAME          = ATTIDX_COUNT++;
-    public static final int ATTIDX_XPATHDEFAULTNS    = ATTIDX_COUNT++;
-    public static final int ATTIDX_INHERITABLE       = ATTIDX_COUNT++;
+    public static final int ATTIDX_APPLIESTOEMPTY              = ATTIDX_COUNT++;
+    public static final int ATTIDX_DEFAULTATTRAPPLY            = ATTIDX_COUNT++;
+    public static final int ATTIDX_DEFAULTATTRIBUTES           = ATTIDX_COUNT++;    
+    public static final int ATTIDX_MODE                        = ATTIDX_COUNT++;
+    public static final int ATTIDX_NOTNAMESPACE                = ATTIDX_COUNT++;
+    public static final int ATTIDX_NOTQNAME                    = ATTIDX_COUNT++;
+    public static final int ATTIDX_XPATHDEFAULTNS              = ATTIDX_COUNT++;
+    public static final int ATTIDX_INHERITABLE                 = ATTIDX_COUNT++;
+    public static final int ATTIDX_XPATHDEFAULTNS_TWOPOUNDDFLT = ATTIDX_COUNT++;
 
     private static final XIntPool fXIntPool = new XIntPool();
     // constants to return
@@ -1403,6 +1404,20 @@ public class XSAttributeChecker {
         fNonSchemaAttrs.clear();
     }
 
+    public String checkTargetNamespace(Element element,
+            XSDocumentInfo schemaDoc) {
+        if (DOMUtil.getAttr(element, SchemaSymbols.ATT_TARGETNAMESPACE) != null) {
+            final String value = DOMUtil.getAttrValueTrimmed(element, SchemaSymbols.ATT_TARGETNAMESPACE);
+            try {
+                fExtraDVs[DT_ANYURI].validate(value, schemaDoc.fValidationContext, null);
+                return fSymbolTable.addSymbol(value);
+            } catch (InvalidDatatypeValueException ide) {
+                // REVISIT: bypass checking in checkAttributes?
+                // Ignore for now, it will be reported when we call checkAttributes
+            }
+        }
+        return null;
+    }
     /**
      * Check whether the specified element conforms to the attributes restriction.
      * an array of attribute values is returned. the caller must call
@@ -2056,6 +2071,7 @@ public class XSAttributeChecker {
                 if (retValue != null) {
                     retValue = fSymbolTable.addSymbol((String)retValue);
                 }
+                attrValues[ATTIDX_XPATHDEFAULTNS_TWOPOUNDDFLT] = Boolean.TRUE;
             } else if (!value.equals(SchemaSymbols.ATTVAL_TWOPOUNDLOCAL)){
                 // we have found namespace URI here
                 // need to add it to the symbol table
@@ -2275,6 +2291,7 @@ public class XSAttributeChecker {
         // now set it to false.
         System.arraycopy(fTempArray, 0, retArray, 0, ATTIDX_COUNT-1);
         retArray[ATTIDX_ISRETURNED] = Boolean.FALSE;
+        retArray[ATTIDX_XPATHDEFAULTNS_TWOPOUNDDFLT] = Boolean.FALSE;
 
         return retArray;
     }

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=1163737&r1=1163736&r2=1163737&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 Wed Aug 31 18:38:10 2011
@@ -43,6 +43,7 @@ import org.apache.xerces.util.DOMUtil;
 import org.apache.xerces.util.NamespaceSupport;
 import org.apache.xerces.util.SymbolTable;
 import org.apache.xerces.util.XMLChar;
+import org.apache.xerces.util.XMLSymbols;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xs.XSAttributeUse;
 import org.apache.xerces.xs.XSConstants;
@@ -470,7 +471,16 @@ abstract class XSDAbstractTraverser {
                 String test = (String) attrs[XSAttributeChecker.ATTIDX_XPATH];
                 String xpathDefaultNamespace = (String) attrs[XSAttributeChecker.ATTIDX_XPATHDEFAULTNS];
                 if (xpathDefaultNamespace == null) {
-                   xpathDefaultNamespace = schemaDoc.fXpathDefaultNamespace;    
+                    if (schemaDoc.fXpathDefaultNamespaceIs2PoundDefault) {
+                        xpathDefaultNamespace = schemaDoc.fValidationContext.getURI(XMLSymbols.EMPTY_STRING);
+                        if (xpathDefaultNamespace != null) {
+                            xpathDefaultNamespace = fSymbolTable.addSymbol(xpathDefaultNamespace);
+                            
+                        }
+                    }
+                    else {
+                        xpathDefaultNamespace = schemaDoc.fXpathDefaultNamespace;
+                    }
                 }
                 
                 if (test != null) {                    

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=1163737&r1=1163736&r2=1163737&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 Wed Aug 31 18:38:10 2011
@@ -42,6 +42,7 @@ import org.apache.xerces.impl.xs.util.XI
 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 import org.apache.xerces.util.DOMUtil;
 import org.apache.xerces.util.XMLChar;
+import org.apache.xerces.util.XMLSymbols;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xs.XSAttributeUse;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
@@ -1695,9 +1696,17 @@ class  XSDComplexTypeTraverser extends X
         String test = (String) attrValues[XSAttributeChecker.ATTIDX_XPATH];
         String xpathDefaultNamespace = (String) attrValues[XSAttributeChecker.ATTIDX_XPATHDEFAULTNS];
         if (xpathDefaultNamespace == null) {
-           xpathDefaultNamespace = schemaDoc.fXpathDefaultNamespace;    
+            if (schemaDoc.fXpathDefaultNamespaceIs2PoundDefault) {
+                xpathDefaultNamespace = schemaDoc.fValidationContext.getURI(XMLSymbols.EMPTY_STRING);
+                if (xpathDefaultNamespace != null) {
+                    xpathDefaultNamespace = fSymbolTable.addSymbol(xpathDefaultNamespace);
+                }
+            }
+            else {
+                xpathDefaultNamespace = schemaDoc.fXpathDefaultNamespace;
+            }
         }
-        
+
         if (test != null) {
             // get 'annotation'
             Element childNode = DOMUtil.getFirstChildElement(assertElement);

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java?rev=1163737&r1=1163736&r2=1163737&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java Wed Aug 31 18:38:10 2011
@@ -4605,6 +4605,10 @@ public class XSDHandler {
     public String getDocumentURI() {
         return fSchemaParser.getDocument().getDocumentURI();
     }
+    
+    public String getDocumentURI(Element ele) {
+        return doc2SystemId(ele);
+    }
 
     public short getSchemaVersion() {
         return fSchemaVersion;

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java?rev=1163737&r1=1163736&r2=1163737&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java Wed Aug 31 18:38:10 2011
@@ -32,6 +32,7 @@ import org.apache.xerces.impl.xs.util.XS
 import org.apache.xerces.impl.xs.util.XSTypeHelper;
 import org.apache.xerces.util.DOMUtil;
 import org.apache.xerces.util.NamespaceSupport;
+import org.apache.xerces.util.XMLSymbols;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xs.XSObjectList;
 import org.apache.xerces.xs.XSTypeDefinition;
@@ -61,7 +62,6 @@ import org.w3c.dom.Element;
 class XSDTypeAlternativeTraverser extends XSDAbstractTraverser {
     
     private static final XSSimpleType fErrorType;
-    private XSDHandler fXsdHandler = null;
     
     static {
         SchemaGrammar grammar = SchemaGrammar.getS4SGrammar(Constants.SCHEMA_VERSION_1_1);
@@ -70,7 +70,6 @@ class XSDTypeAlternativeTraverser extend
 
     XSDTypeAlternativeTraverser (XSDHandler handler, XSAttributeChecker attrChecker) {
         super(handler, attrChecker);
-        fXsdHandler = handler;
     }
 
     /**
@@ -211,15 +210,23 @@ class XSDTypeAlternativeTraverser extend
             typeAlternative.setNamespaceContext(new NamespaceSupport(schemaDoc.fNamespaceSupport)); 
         }
         
-        // REVISIT : is using Document.getDocumentURI() correct to retrieve base URI in every case, for type alternatives? 
-        typeAlternative.setBaseURI(fXsdHandler.getDocumentURI());
+        // REVISIT : is using Document.getDocumentURI() correct to retrieve base URI in every case, for type alternatives?
+        String baseURI = fSchemaHandler.getDocumentURI(altElement);
+        if (baseURI != null) {
+            typeAlternative.setBaseURI(baseURI);
+        }
 
         if (xpathDefaultNS == null) {
-            xpathDefaultNS = schemaDoc.fXpathDefaultNamespace;
-            if (xpathDefaultNS == null) {
-                // try to find value of xpathDefaultNamespace by resolving '##defaultNamespace'
-                xpathDefaultNS = XSTypeHelper.getDefaultNamespace(altElement, schemaDoc.fSchemaElement);
-            }            
+            if (schemaDoc.fXpathDefaultNamespaceIs2PoundDefault) {
+                xpathDefaultNS = schemaDoc.fValidationContext.getURI(XMLSymbols.EMPTY_STRING);
+                if (xpathDefaultNS != null) {
+                    xpathDefaultNS = fSymbolTable.addSymbol(xpathDefaultNS);
+                    
+                }
+            }
+            else {
+                xpathDefaultNS = schemaDoc.fXpathDefaultNamespace;
+            }          
         }
         if (xpathDefaultNS != null) {
             //set the xpathDefaultNamespace attribute value

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java?rev=1163737&r1=1163736&r2=1163737&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java Wed Aug 31 18:38:10 2011
@@ -28,9 +28,7 @@ import org.apache.xerces.impl.xs.XMLSche
 import org.apache.xerces.impl.xs.XSAttributeGroupDecl;
 import org.apache.xerces.impl.xs.XSOpenContentDecl;
 import org.apache.xerces.impl.xs.util.XInt;
-import org.apache.xerces.util.DOMUtil;
 import org.apache.xerces.util.SymbolTable;
-import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.QName;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -68,6 +66,7 @@ class XSDocumentInfo {
     
     // xpathDefaultNamespace
     String fXpathDefaultNamespace;
+    boolean fXpathDefaultNamespaceIs2PoundDefault;
 
     // represents whether this is a chameleon schema (i.e., whether its TNS is natural or comes from without)
     protected boolean fIsChameleonSchema;
@@ -121,14 +120,10 @@ class XSDocumentInfo {
             fValidationContext.setNamespaceSupport(fNamespaceSupport);
             fValidationContext.setSymbolTable(symbolTable);
             fValidationContext.setTypeValidatorHelper(typeValidatorHelper);
+
+            // get the target namespace
+            fTargetNamespace = attrChecker.checkTargetNamespace(root, this);
             
-            if (DOMUtil.getAttr(root, SchemaSymbols.ATT_TARGETNAMESPACE) != null) {
-                fTargetNamespace = XMLChar.trim(DOMUtil.getAttrValue(root, SchemaSymbols.ATT_TARGETNAMESPACE));
-                if (!"".equals(fTargetNamespace)) {
-                    fTargetNamespace = symbolTable.addSymbol(fTargetNamespace);
-                }
-            }
-                        
             fSchemaAttrs = attrChecker.checkAttributes(root, true, this);
             // schemaAttrs == null means it's not an <xsd:schema> element
             // throw an exception, but we don't know the document systemId,
@@ -143,9 +138,11 @@ class XSDocumentInfo {
             fBlockDefault =
                 ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_BLOCKDEFAULT]).shortValue();
             fFinalDefault =
-                ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_FINALDEFAULT]).shortValue();            
+                ((XInt)fSchemaAttrs[XSAttributeChecker.ATTIDX_FINALDEFAULT]).shortValue();
             fXpathDefaultNamespace = 
-                (String)fSchemaAttrs[XSAttributeChecker.ATTIDX_XPATHDEFAULTNS]; 
+                (String)fSchemaAttrs[XSAttributeChecker.ATTIDX_XPATHDEFAULTNS];
+            fXpathDefaultNamespaceIs2PoundDefault =
+                ((Boolean) fSchemaAttrs[XSAttributeChecker.ATTIDX_XPATHDEFAULTNS_TWOPOUNDDFLT]).booleanValue();
 
             fNamespaceSupportRoot = new SchemaNamespaceSupport(fNamespaceSupport);
 

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java?rev=1163737&r1=1163736&r2=1163737&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java Wed Aug 31 18:38:10 2011
@@ -32,7 +32,6 @@ import org.apache.xerces.impl.validation
 import org.apache.xerces.impl.xs.SchemaSymbols;
 import org.apache.xerces.impl.xs.XSComplexTypeDecl;
 import org.apache.xerces.impl.xs.XSMessageFormatter;
-import org.apache.xerces.util.DOMUtil;
 import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.NamespaceContext;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
@@ -43,7 +42,6 @@ import org.apache.xerces.xs.XSTypeDefini
 import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
 import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
 import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType;
-import org.w3c.dom.Element;
 
 /**
  * Class defining utility/helper methods related to XML schema types.
@@ -296,29 +294,4 @@ public class XSTypeHelper {
     } // getXPath2ResultSequence
     
     
-    /*
-     * Resolve the reference '##defaultNamespace' (currently used for "type alternative" component).
-     */
-    public static String getDefaultNamespace(Element localElement, Element schemaElement) {
-        
-        String defaultNamespace = null;
-        
-        if (DOMUtil.getAttr(localElement, SchemaSymbols.ATT_XPATH_DEFAULT_NS) != null) {
-            defaultNamespace = XMLChar.trim(DOMUtil.getAttrValue(localElement, SchemaSymbols.ATT_XPATH_DEFAULT_NS));            
-            if (SchemaSymbols.ATTVAL_TWOPOUNDDEFAULTNS.equals(defaultNamespace)) {                 
-                defaultNamespace = DOMUtil.getDefaultNamespace(localElement);
-            }
-        }
-        else if (DOMUtil.getAttr(schemaElement, SchemaSymbols.ATT_XPATH_DEFAULT_NS) != null) {
-            defaultNamespace = XMLChar.trim(DOMUtil.getAttrValue(schemaElement, SchemaSymbols.ATT_XPATH_DEFAULT_NS));
-            if (SchemaSymbols.ATTVAL_TWOPOUNDDEFAULTNS.equals(defaultNamespace)) {                 
-                defaultNamespace = DOMUtil.getDefaultNamespace(localElement);
-            }
-        }
-        
-        return defaultNamespace;
-        
-    } // getDefaultNamespace
-    
-    
 } // class XSTypeHelper

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/DOMUtil.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/DOMUtil.java?rev=1163737&r1=1163736&r2=1163737&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/DOMUtil.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/util/DOMUtil.java Wed Aug 31 18:38:10 2011
@@ -19,8 +19,6 @@ package org.apache.xerces.util;
 
 import java.util.Hashtable;
 
-import javax.xml.XMLConstants;
-
 import org.apache.xerces.dom.AttrImpl;
 import org.apache.xerces.dom.DocumentImpl;
 import org.apache.xerces.impl.xs.opti.ElementImpl;
@@ -809,6 +807,12 @@ public class DOMUtil {
     
     // return the value of the attribute of the given element
     // with the given name
+    public static String getAttrValueTrimmed(Element elem, String name) {
+        return XMLChar.trim(elem.getAttribute(name));
+    } // getAttr(Element, String):Attr
+    
+    // return the value of the attribute of the given element
+    // with the given name
     public static String getAttrValueNS(Element elem, String nsUri,
             String localName) {
         return elem.getAttributeNS(nsUri, localName);
@@ -824,24 +828,6 @@ public class DOMUtil {
         return node.getNamespaceURI();
     }
     
-    // find value of "default namespace" for an element node. does a recursive search
-    // up the DOM tree as needed, to find the appropriate in-scope "default namespace".
-    public static String getDefaultNamespace(Element element) {
-        
-        String defaultNamespace = null;
-        
-        if (getAttr(element, XMLConstants.XMLNS_ATTRIBUTE) != null) {
-            defaultNamespace = XMLChar.trim(getAttrValue(element, XMLConstants.XMLNS_ATTRIBUTE)); 
-        }
-        
-        if (defaultNamespace == null && (element.getParentNode() instanceof Element)) {
-            defaultNamespace = getDefaultNamespace((Element)element.getParentNode());  
-        }
-        
-        return defaultNamespace;
-        
-    } // getDefaultNamespace
-    
     // return annotation
     public static String getAnnotation(Node node) {
         if (node instanceof ElementImpl) {



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