xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From knoa...@apache.org
Subject svn commit: r884565 [1/2] - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces: dom/ impl/ impl/dv/xs/ impl/xs/
Date Thu, 26 Nov 2009 14:28:34 GMT
Author: knoaman
Date: Thu Nov 26 14:28:33 2009
New Revision: 884565

URL: http://svn.apache.org/viewvc?rev=884565&view=rev
Log:
Synchronize the 1.1 branch with Xerces-J trunk- Part 1

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMConfigurationImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/BaseSchemaDVFactory.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaLoader.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/XSAttributeGroupDecl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSConstraints.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDeclarationPool.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSGrammarBucket.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSModelImpl.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMConfigurationImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMConfigurationImpl.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMConfigurationImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMConfigurationImpl.java Thu Nov 26 14:28:33 2009
@@ -129,6 +129,12 @@
     protected static final String WARN_ON_DUPLICATE_ATTDEF =
         Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
     
+    /** Feature identifier: namespace growth */
+    protected static final String NAMESPACE_GROWTH = 
+        Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+    
+    protected static final String TOLERATE_DUPLICATES = 
+        Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;    
     // property identifiers
 
     /** Property identifier: entity manager. */
@@ -190,6 +196,10 @@
     protected static final String SCHEMA_NONS_LOCATION =
         Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
     
+    /** Property identifier: Schema DV Factory */
+    protected static final String SCHEMA_DV_FACTORY =
+        Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
+    
     //
     // Data
     //
@@ -300,7 +310,9 @@
             DISALLOW_DOCTYPE_DECL_FEATURE,
             BALANCE_SYNTAX_TREES,
             WARN_ON_DUPLICATE_ATTDEF,
-            PARSER_SETTINGS
+            PARSER_SETTINGS,
+            NAMESPACE_GROWTH,
+            TOLERATE_DUPLICATES
         };
         addRecognizedFeatures(recognizedFeatures);
 
@@ -321,6 +333,8 @@
         setFeature(BALANCE_SYNTAX_TREES, false);
         setFeature(WARN_ON_DUPLICATE_ATTDEF, false);
         setFeature(PARSER_SETTINGS, true);
+        setFeature(NAMESPACE_GROWTH, false);
+        setFeature(TOLERATE_DUPLICATES, false);
 
         // add default recognized properties
         final String[] recognizedProperties = {
@@ -338,7 +352,8 @@
             SCHEMA_LOCATION,
             SCHEMA_NONS_LOCATION,
             DTD_VALIDATOR_PROPERTY,
-            DTD_VALIDATOR_FACTORY_PROPERTY
+            DTD_VALIDATOR_FACTORY_PROPERTY,
+            SCHEMA_DV_FACTORY
         };
         addRecognizedProperties(recognizedProperties);
 

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/Constants.java Thu Nov 26 14:28:33 2009
@@ -282,6 +282,12 @@
     /** Honour all schemaLocations feature ("honour-all-schemaLocations"). */
     public static final String HONOUR_ALL_SCHEMALOCATIONS_FEATURE = "honour-all-schemaLocations";
     
+    /** Namespace growth feature ("namespace-growth"). */
+    public static final String NAMESPACE_GROWTH_FEATURE = "namespace-growth";
+
+    /** Tolerate duplicates feature ("internal/tolerate-duplicates"). */
+    public static final String TOLERATE_DUPLICATES_FEATURE = "internal/tolerate-duplicates";
+    
     /** XInclude processing feature ("xinclude"). */
     public static final String XINCLUDE_FEATURE = "xinclude";
     
@@ -421,12 +427,15 @@
     /** Validation manager property ("internal/validation-manager"). */
     public static final String VALIDATION_MANAGER_PROPERTY = "internal/validation-manager";
     
-    /** Schema type of the root element in a document ("validation/schema/root-type-definition"). */
+    /** Schema type for the root element in a document ("validation/schema/root-type-definition"). */
     public static final String ROOT_TYPE_DEFINITION_PROPERTY = "validation/schema/root-type-definition";
     
     /** Schema element declaration for the root element in a document ("validation/schema/root-element-declaration"). */
     public static final String ROOT_ELEMENT_DECLARATION_PROPERTY = "validation/schema/root-element-declaration";
 
+    /** Schema element declaration for the root element in a document ("internal/validation/schema/dv-factory"). */
+    public static final String SCHEMA_DV_FACTORY_PROPERTY = "internal/validation/schema/dv-factory";
+
     /** Datatype XML version property ("validation/schema/datatype-xml-version"). */
     public static final String XML_SCHEMA_VERSION_PROPERTY ="validation/schema/version";
     
@@ -526,7 +535,9 @@
             ID_IDREF_CHECKING_FEATURE,
             IDC_CHECKING_FEATURE,
             UNPARSED_ENTITY_CHECKING_FEATURE,
-            TYPE_ALTERNATIVES_CHEKING_FEATURE,
+            NAMESPACE_GROWTH_FEATURE,
+            TOLERATE_DUPLICATES_FEATURE,
+            TYPE_ALTERNATIVES_CHEKING_FEATURE
     };
     
     /** Xerces properties. */
@@ -551,7 +562,8 @@
             LOCALE_PROPERTY,
             ROOT_TYPE_DEFINITION_PROPERTY,
             ROOT_ELEMENT_DECLARATION_PROPERTY,
-            XML_SCHEMA_VERSION_PROPERTY,
+            SCHEMA_DV_FACTORY_PROPERTY,
+            XML_SCHEMA_VERSION_PROPERTY
     };
     
     /** Empty enumeration. */

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/BaseSchemaDVFactory.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/BaseSchemaDVFactory.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/BaseSchemaDVFactory.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/BaseSchemaDVFactory.java Thu Nov 26 14:28:33 2009
@@ -318,4 +318,8 @@
         fDeclPool = declPool;
     }
 
+    /** Implementation internal **/
+    public XSSimpleTypeDecl newXSSimpleTypeDecl() {
+        return new XSSimpleTypeDecl();
+    }
 } //BaseSchemaDVFactory

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java Thu Nov 26 14:28:33 2009
@@ -60,40 +60,40 @@
  */
 public class XSSimpleTypeDecl implements XSSimpleType, TypeInfo {
 
-    static final short DV_STRING        = PRIMITIVE_STRING;
-    static final short DV_BOOLEAN       = PRIMITIVE_BOOLEAN;
-    static final short DV_DECIMAL       = PRIMITIVE_DECIMAL;
-    static final short DV_FLOAT         = PRIMITIVE_FLOAT;
-    static final short DV_DOUBLE        = PRIMITIVE_DOUBLE;
-    static final short DV_DURATION      = PRIMITIVE_DURATION;
-    static final short DV_DATETIME      = PRIMITIVE_DATETIME;
-    static final short DV_TIME          = PRIMITIVE_TIME;
-    static final short DV_DATE          = PRIMITIVE_DATE;
-    static final short DV_GYEARMONTH    = PRIMITIVE_GYEARMONTH;
-    static final short DV_GYEAR         = PRIMITIVE_GYEAR;
-    static final short DV_GMONTHDAY     = PRIMITIVE_GMONTHDAY;
-    static final short DV_GDAY          = PRIMITIVE_GDAY;
-    static final short DV_GMONTH        = PRIMITIVE_GMONTH;
-    static final short DV_HEXBINARY     = PRIMITIVE_HEXBINARY;
-    static final short DV_BASE64BINARY  = PRIMITIVE_BASE64BINARY;
-    static final short DV_ANYURI        = PRIMITIVE_ANYURI;
-    static final short DV_QNAME         = PRIMITIVE_QNAME;
-    static final short DV_PRECISIONDECIMAL = PRIMITIVE_PRECISIONDECIMAL;
-    static final short DV_NOTATION      = PRIMITIVE_NOTATION;
-
-    static final short DV_ANYSIMPLETYPE = 0;
-    static final short DV_ID            = DV_NOTATION + 1;
-    static final short DV_IDREF         = DV_NOTATION + 2;
-    static final short DV_ENTITY        = DV_NOTATION + 3;
-    static final short DV_INTEGER       = DV_NOTATION + 4;
-    static final short DV_LIST          = DV_NOTATION + 5;
-    static final short DV_UNION         = DV_NOTATION + 6;
-    static final short DV_YEARMONTHDURATION = DV_NOTATION + 7;
-    static final short DV_DAYTIMEDURATION	= DV_NOTATION + 8;
-    static final short DV_ANYATOMICTYPE = DV_NOTATION + 9;
-    static final short DV_ERROR = DV_NOTATION + 10;
+    protected static final short DV_STRING            = PRIMITIVE_STRING;
+    protected static final short DV_BOOLEAN           = PRIMITIVE_BOOLEAN;
+    protected static final short DV_DECIMAL           = PRIMITIVE_DECIMAL;
+    protected static final short DV_FLOAT             = PRIMITIVE_FLOAT;
+    protected static final short DV_DOUBLE            = PRIMITIVE_DOUBLE;
+    protected static final short DV_DURATION          = PRIMITIVE_DURATION;
+    protected static final short DV_DATETIME          = PRIMITIVE_DATETIME;
+    protected static final short DV_TIME              = PRIMITIVE_TIME;
+    protected static final short DV_DATE              = PRIMITIVE_DATE;
+    protected static final short DV_GYEARMONTH        = PRIMITIVE_GYEARMONTH;
+    protected static final short DV_GYEAR             = PRIMITIVE_GYEAR;
+    protected static final short DV_GMONTHDAY         = PRIMITIVE_GMONTHDAY;
+    protected static final short DV_GDAY              = PRIMITIVE_GDAY;
+    protected static final short DV_GMONTH            = PRIMITIVE_GMONTH;
+    protected static final short DV_HEXBINARY         = PRIMITIVE_HEXBINARY;
+    protected static final short DV_BASE64BINARY      = PRIMITIVE_BASE64BINARY;
+    protected static final short DV_ANYURI            = PRIMITIVE_ANYURI;
+    protected static final short DV_QNAME             = PRIMITIVE_QNAME;
+    protected static final short DV_PRECISIONDECIMAL  = PRIMITIVE_PRECISIONDECIMAL;
+    protected static final short DV_NOTATION          = PRIMITIVE_NOTATION;
+
+    protected static final short DV_ANYSIMPLETYPE     = 0;
+    protected static final short DV_ID                = DV_NOTATION + 1;
+    protected static final short DV_IDREF             = DV_NOTATION + 2;
+    protected static final short DV_ENTITY            = DV_NOTATION + 3;
+    protected static final short DV_INTEGER           = DV_NOTATION + 4;
+    protected static final short DV_LIST              = DV_NOTATION + 5;
+    protected static final short DV_UNION             = DV_NOTATION + 6;
+    protected static final short DV_YEARMONTHDURATION = DV_NOTATION + 7;
+    protected static final short DV_DAYTIMEDURATION	  = DV_NOTATION + 8;
+    protected static final short DV_ANYATOMICTYPE     = DV_NOTATION + 9;
+    protected static final short DV_ERROR             = DV_NOTATION + 10;
 
-    static final TypeValidator[] fDVs = {
+    private static final TypeValidator[] gDVs = {
         new AnySimpleDV(),
         new StringDV(),
         new BooleanDV(),
@@ -231,6 +231,14 @@
         }
     };
 
+    protected static TypeValidator[] getGDVs() {
+        return (TypeValidator[])gDVs.clone();
+    }
+    private TypeValidator[] fDVs = gDVs;
+    protected void setDVs(TypeValidator[] dvs) {
+        fDVs = dvs;
+    }
+    
     // this will be true if this is a static XSSimpleTypeDecl
     // and hence must remain immutable (i.e., applyFacets
     // may not be permitted to have any effect).
@@ -473,6 +481,7 @@
         //decline to do anything if the object is immutable.
         if(fIsImmutable) return null;
         fBase = base;
+        fAnonymous = false;
         fTypeName = name;
         fTargetNamespace = uri;
         fFinalSet = finalSet;
@@ -527,6 +536,7 @@
         //decline to do anything if the object is immutable.
         if(fIsImmutable) return null;
         fBase = fAnySimpleType;
+        fAnonymous = false;
         fTypeName = name;
         fTargetNamespace = uri;
         fFinalSet = finalSet;
@@ -554,6 +564,7 @@
         //decline to do anything if the object is immutable.
         if(fIsImmutable) return null;
         fBase = fAnySimpleType;
+        fAnonymous = false;
         fTypeName = name;
         fTargetNamespace = uri;
         fFinalSet = finalSet;
@@ -605,7 +616,7 @@
     public TypeValidator getTypeValidator() {
         return fDVs[fValidationDV];
     }
-
+    
     public boolean isFinal(short derivation) {
         return (fFinalSet & derivation) != 0;
     }
@@ -849,6 +860,18 @@
             }
         }
 
+        // whiteSpace
+        if ((presentFacet & FACET_WHITESPACE) != 0) {
+            if ((allowedFacet & FACET_WHITESPACE) == 0) {
+                reportError("cos-applicable-facets", new Object[]{"whiteSpace", fTypeName});
+            } else {
+                fWhiteSpace = facets.whiteSpace;
+                whiteSpaceAnnotation = facets.whiteSpaceAnnotation;
+                fFacetsDefined |= FACET_WHITESPACE;
+                if ((fixedFacet & FACET_WHITESPACE) != 0)
+                    fFixedFacet |= FACET_WHITESPACE;
+            }
+        }
         // enumeration
         if ((presentFacet & FACET_ENUMERATION) != 0) {
             if ((allowedFacet & FACET_ENUMERATION) == 0) {
@@ -865,7 +888,7 @@
                     if (enumNSDecls != null)
                         ctx.setNSContext((NamespaceContext)enumNSDecls.elementAt(i));
                     try {
-                        ValidatedInfo info = this.fBase.validateWithInfo((String)enumVals.elementAt(i), ctx, tempInfo);
+                        ValidatedInfo info = getActualEnumValue((String)enumVals.elementAt(i), ctx, tempInfo);
                         // check 4.3.5.c0 must: enumeration values from the value space of base
                         fEnumeration.addElement(info.actualValue);
                         fEnumerationType[i] = info.actualValueType;
@@ -892,19 +915,6 @@
                 fFixedFacet |= FACET_ASSERT;
         }
 
-        // whiteSpace
-        if ((presentFacet & FACET_WHITESPACE) != 0) {
-            if ((allowedFacet & FACET_WHITESPACE) == 0) {
-                reportError("cos-applicable-facets", new Object[]{"whiteSpace", fTypeName});
-            } else {
-                fWhiteSpace = facets.whiteSpace;
-                whiteSpaceAnnotation = facets.whiteSpaceAnnotation;
-                fFacetsDefined |= FACET_WHITESPACE;
-                if ((fixedFacet & FACET_WHITESPACE) != 0)
-                    fFixedFacet |= FACET_WHITESPACE;
-            }
-        }
-
         // maxInclusive
         if ((presentFacet & FACET_MAXINCLUSIVE) != 0) {
             if ((allowedFacet & FACET_MAXINCLUSIVE) == 0) {
@@ -1564,6 +1574,11 @@
 
     }
 
+    protected ValidatedInfo getActualEnumValue(String lexical, ValidationContext ctx, ValidatedInfo info)
+    throws InvalidDatatypeValueException {
+        return fBase.validateWithInfo(lexical, ctx, info);
+    }
+
     /**
      * validate a value, and return the compiled form
      */

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/SchemaGrammar.java Thu Nov 26 14:28:33 2009
@@ -27,6 +27,7 @@
 import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
 import org.apache.xerces.impl.xs.alternative.XSTypeAlternativeImpl;
 import org.apache.xerces.impl.xs.identity.IdentityConstraint;
+import org.apache.xerces.impl.xs.util.ObjectListImpl;
 import org.apache.xerces.impl.xs.util.SimpleLocator;
 import org.apache.xerces.impl.xs.util.StringListImpl;
 import org.apache.xerces.impl.xs.util.XSNamedMap4Types;
@@ -55,6 +56,7 @@
 import org.apache.xerces.xs.XSParticle;
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.apache.xerces.xs.XSWildcard;
+import org.apache.xerces.xs.datatypes.ObjectList;
 import org.xml.sax.SAXException;
 
 /**
@@ -88,6 +90,21 @@
     SymbolHash fGlobalIDConstraintDecls;
     SymbolHash fGlobalTypeDecls;
 
+    // extended global decls: map from schema location + decl name to decl object
+    // key is location,name
+    SymbolHash fGlobalAttrDeclsExt;
+    SymbolHash fGlobalAttrGrpDeclsExt;
+    SymbolHash fGlobalElemDeclsExt;
+    SymbolHash fGlobalGroupDeclsExt;
+    SymbolHash fGlobalNotationDeclsExt;
+    SymbolHash fGlobalIDConstraintDeclsExt;
+    SymbolHash fGlobalTypeDeclsExt;
+    
+    // A global map of all global element declarations - used for substitution group computation
+    // (handy when sharing components by reference, since we might end up with duplicate components
+    //  that are not added to either of the global element declarations above)
+    SymbolHash fAllGlobalElemDecls;
+
     // the XMLGrammarDescription member
     XSDDescription fGrammarDescription = null;
 
@@ -151,6 +168,18 @@
         fGlobalNotationDecls = new SymbolHash();
         fGlobalIDConstraintDecls = new SymbolHash();
 
+        // Extended tables
+        fGlobalAttrDeclsExt  = new SymbolHash();
+        fGlobalAttrGrpDeclsExt = new SymbolHash();
+        fGlobalElemDeclsExt = new SymbolHash();
+        fGlobalGroupDeclsExt = new SymbolHash();
+        fGlobalNotationDeclsExt = new SymbolHash();
+        fGlobalIDConstraintDeclsExt = new SymbolHash();
+        fGlobalTypeDeclsExt = new SymbolHash();
+        
+        // All global elements table
+        fAllGlobalElemDecls = new SymbolHash();
+
         // if we are parsing S4S, put built-in types in first
         // they might get overwritten by the types from S4S, but that's
         // considered what the application wants to do.
@@ -160,7 +189,83 @@
         else {
             fGlobalTypeDecls = new SymbolHash();
         }
-    } // <init>(String, XSDDescription)
+    } // <init>(String, XSDDescription, SymbolTable, short)
+
+ // Clone an existing schema grammar
+    public SchemaGrammar(SchemaGrammar grammar) {
+        fTargetNamespace = grammar.fTargetNamespace;
+        fGrammarDescription = grammar.fGrammarDescription.makeClone();
+        //fGrammarDescription.fContextType |= XSDDescription.CONTEXT_COLLISION; // REVISIT
+        fSymbolTable = grammar.fSymbolTable; // REVISIT
+
+        fGlobalAttrDecls  = grammar.fGlobalAttrDecls.makeClone();
+        fGlobalAttrGrpDecls = grammar.fGlobalAttrGrpDecls.makeClone();
+        fGlobalElemDecls = grammar.fGlobalElemDecls.makeClone();
+        fGlobalGroupDecls = grammar.fGlobalGroupDecls.makeClone();
+        fGlobalNotationDecls = grammar.fGlobalNotationDecls.makeClone();
+        fGlobalIDConstraintDecls = grammar.fGlobalIDConstraintDecls.makeClone();
+        fGlobalTypeDecls = grammar.fGlobalTypeDecls.makeClone();
+    
+        // Extended tables
+        fGlobalAttrDeclsExt  = grammar.fGlobalAttrDeclsExt.makeClone();
+        fGlobalAttrGrpDeclsExt = grammar.fGlobalAttrGrpDeclsExt.makeClone();
+        fGlobalElemDeclsExt = grammar.fGlobalElemDeclsExt.makeClone();
+        fGlobalGroupDeclsExt = grammar.fGlobalGroupDeclsExt.makeClone();
+        fGlobalNotationDeclsExt = grammar.fGlobalNotationDeclsExt.makeClone();
+        fGlobalIDConstraintDeclsExt = grammar.fGlobalIDConstraintDeclsExt.makeClone();
+        fGlobalTypeDeclsExt = grammar.fGlobalTypeDeclsExt.makeClone();
+        
+        // All global elements table
+        fAllGlobalElemDecls = grammar.fAllGlobalElemDecls.makeClone();
+
+        // Annotations associated with the "root" schema of this targetNamespace
+        fNumAnnotations = grammar.fNumAnnotations;
+        if (fNumAnnotations > 0) {
+            fAnnotations = new XSAnnotationImpl[grammar.fAnnotations.length];
+            System.arraycopy(grammar.fAnnotations, 0, fAnnotations, 0, fNumAnnotations);
+        }
+        
+        // All substitution group information declared in this namespace
+        fSubGroupCount = grammar.fSubGroupCount;
+        if (fSubGroupCount > 0) {
+            fSubGroups = new XSElementDecl[grammar.fSubGroups.length];
+            System.arraycopy(grammar.fSubGroups, 0, fSubGroups, 0, fSubGroupCount);
+        }
+
+        // Array to store complex type decls for constraint checking
+        fCTCount = grammar.fCTCount;
+        if (fCTCount > 0) {
+            fComplexTypeDecls = new XSComplexTypeDecl[grammar.fComplexTypeDecls.length];
+            fCTLocators = new SimpleLocator[grammar.fCTLocators.length];
+            System.arraycopy(grammar.fComplexTypeDecls, 0, fComplexTypeDecls, 0, fCTCount);
+            System.arraycopy(grammar.fCTLocators, 0, fCTLocators, 0, fCTCount);
+        }
+        
+        // Groups being redefined by restriction
+        fRGCount = grammar.fRGCount;
+        if (fRGCount > 0) {
+            fRedefinedGroupDecls = new XSGroupDecl[grammar.fRedefinedGroupDecls.length];
+            fRGLocators = new SimpleLocator[grammar.fRGLocators.length];
+            System.arraycopy(grammar.fRedefinedGroupDecls, 0, fRedefinedGroupDecls, 0, fRGCount);
+            System.arraycopy(grammar.fRGLocators, 0, fRGLocators, 0, fRGCount);
+        }
+
+        // List of imported grammars
+        if (grammar.fImported != null) {
+            fImported = new Vector();
+            for (int i=0; i<grammar.fImported.size(); i++) {
+                fImported.add(grammar.fImported.elementAt(i));
+            }
+        }
+
+        // Locations
+        if (grammar.fLocations != null) {
+            for (int k=0; k<grammar.fLocations.size(); k++) {
+                addDocument(null, (String)grammar.fLocations.elementAt(k));
+            }
+        }
+
+    } // <init>(SchemaGrammar)
 
     // number of built-in XSTypes we need to create for base and full
     // datatype set
@@ -210,6 +315,18 @@
                 fGlobalGroupDecls = new SymbolHash(1);
                 fGlobalNotationDecls = new SymbolHash(1);
                 fGlobalIDConstraintDecls = new SymbolHash(1);
+                
+                // no extended global decls
+                fGlobalAttrDeclsExt  = new SymbolHash(1);
+                fGlobalAttrGrpDeclsExt = new SymbolHash(1);
+                fGlobalElemDeclsExt = new SymbolHash(1);
+                fGlobalGroupDeclsExt = new SymbolHash(1);
+                fGlobalNotationDeclsExt = new SymbolHash(1);
+                fGlobalIDConstraintDeclsExt = new SymbolHash(1);
+                fGlobalTypeDeclsExt = new SymbolHash(1);
+
+                // all global element decls table
+                fAllGlobalElemDecls = new SymbolHash(1);
         
                 // get all built-in types
                 fGlobalTypeDecls = schemaFactory.getBuiltInTypes();
@@ -245,6 +362,18 @@
                 fGlobalNotationDecls = new SymbolHash(1);
                 fGlobalIDConstraintDecls = new SymbolHash(1);
                 fGlobalTypeDecls = new SymbolHash(1);
+
+                // no extended global decls 
+                fGlobalAttrDeclsExt  = new SymbolHash(1);
+                fGlobalAttrGrpDeclsExt = new SymbolHash(1);
+                fGlobalElemDeclsExt = new SymbolHash(1);
+                fGlobalGroupDeclsExt = new SymbolHash(1);
+                fGlobalNotationDeclsExt = new SymbolHash(1);
+                fGlobalIDConstraintDeclsExt = new SymbolHash(1);
+                fGlobalTypeDeclsExt = new SymbolHash(1);
+                
+                // no all global element decls
+                fAllGlobalElemDecls = new SymbolHash(1);
     
                 // 4 attributes, so initialize the size as 4*2 = 8
                 fGlobalAttrDecls  = new SymbolHash(8);
@@ -298,27 +427,54 @@
         public void addGlobalAttributeDecl(XSAttributeDecl decl) {
             // ignore
         }
+        public void addGlobalAttributeDecl(XSAttributeDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
             // ignore
         }
+        public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalElementDecl(XSElementDecl decl) {
             // ignore
         }
+        public void addGlobalElementDecl(XSElementDecl decl, String location) {
+            // ignore
+        }
+        public void addGlobalElementDeclAll(XSElementDecl decl) {
+            // ignore
+        }
         public void addGlobalGroupDecl(XSGroupDecl decl) {
             // ignore
         }
+        public void addGlobalGroupDecl(XSGroupDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalNotationDecl(XSNotationDecl decl) {
             // ignore
         }
+        public void addGlobalNotationDecl(XSNotationDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalTypeDecl(XSTypeDefinition decl) {
             // ignore
         }
+        public void addGlobalTypeDecl(XSTypeDefinition decl, String location) {
+            // ignore
+        }
         public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl) {
             // ignore
         }
+        public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalSimpleTypeDecl(XSSimpleType decl) {
             // ignore
         }
+        public void addGlobalSimpleTypeDecl(XSSimpleType decl, String location) {
+            // ignore
+        }
         public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
             // ignore
         }
@@ -385,6 +541,18 @@
             fGlobalGroupDecls = new SymbolHash(1);
             fGlobalNotationDecls = new SymbolHash(1);
             fGlobalIDConstraintDecls = new SymbolHash(1);
+
+            // no extended global decls
+            fGlobalAttrDeclsExt  = new SymbolHash(1);
+            fGlobalAttrGrpDeclsExt = new SymbolHash(1);
+            fGlobalElemDeclsExt = new SymbolHash(6);
+            fGlobalGroupDeclsExt = new SymbolHash(1);
+            fGlobalNotationDeclsExt = new SymbolHash(1);
+            fGlobalIDConstraintDeclsExt = new SymbolHash(1);
+            fGlobalTypeDeclsExt = new SymbolHash(1);
+            
+            // all global element declarations
+            fAllGlobalElemDecls = new SymbolHash(6);
             
             // get all built-in types
             fGlobalTypeDecls = getS4SGrammar(schemaVersion).fGlobalTypeDecls;
@@ -399,6 +567,14 @@
             fGlobalElemDecls.put(documentationDecl.fName, documentationDecl);
             fGlobalElemDecls.put(appinfoDecl.fName, appinfoDecl);
             
+            fGlobalElemDeclsExt.put(","+annotationDecl.fName, annotationDecl);
+            fGlobalElemDeclsExt.put(","+documentationDecl.fName, documentationDecl);
+            fGlobalElemDeclsExt.put(","+appinfoDecl.fName, appinfoDecl);
+            
+            fAllGlobalElemDecls.put(annotationDecl, annotationDecl);
+            fAllGlobalElemDecls.put(documentationDecl, documentationDecl);
+            fAllGlobalElemDecls.put(appinfoDecl, appinfoDecl);
+            
             // create complex type declarations for <annotation>, <documentation> and <appinfo>
             XSComplexTypeDecl annotationType = new XSComplexTypeDecl();
             XSComplexTypeDecl documentationType = new XSComplexTypeDecl();
@@ -514,27 +690,54 @@
         public void addGlobalAttributeDecl(XSAttributeDecl decl) {
             // ignore
         }
+        public void addGlobalAttributeDecl(XSAttributeGroupDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
             // ignore
         }
+        public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalElementDecl(XSElementDecl decl) {
             // ignore
         }
+        public void addGlobalElementDecl(XSElementDecl decl, String location) {
+            // ignore
+        }
+        public void addGlobalElementDeclAll(XSElementDecl decl) {
+            // ignore
+        }
         public void addGlobalGroupDecl(XSGroupDecl decl) {
             // ignore
         }
+        public void addGlobalGroupDecl(XSGroupDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalNotationDecl(XSNotationDecl decl) {
             // ignore
         }
+        public void addGlobalNotationDecl(XSNotationDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalTypeDecl(XSTypeDefinition decl) {
             // ignore
         }
+        public void addGlobalTypeDecl(XSTypeDefinition decl, String location) {
+            // ignore
+        }
         public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl) {
             // ignore
         }
+        public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl, String location) {
+            // ignore
+        }
         public void addGlobalSimpleTypeDecl(XSSimpleType decl) {
             // ignore
         }
+        public void addGlobalSimpleTypeDecl(XSSimpleType decl, String location) {
+            // ignore
+        }
         public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
             // ignore
         }
@@ -650,6 +853,13 @@
         decl.setNamespaceItem(this);
     }
 
+    public void addGlobalAttributeDecl(XSAttributeDecl decl, String location) {
+        fGlobalAttrDeclsExt.put(((location!=null) ? location : "") + "," + decl.fName, decl);
+        if (decl.getNamespaceItem() == null) {
+            decl.setNamespaceItem(this);
+        }
+    }
+
     /**
      * register one global attribute group
      */
@@ -658,19 +868,38 @@
         decl.setNamespaceItem(this);
     }
 
+    public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl, String location) {
+        fGlobalAttrGrpDeclsExt.put(((location!=null) ? location : "") + "," + decl.fName, decl);
+        if (decl.getNamespaceItem() == null) {
+            decl.setNamespaceItem(this);
+        }
+    }
+
     /**
      * register one global element
      */
+    public void addGlobalElementDeclAll(XSElementDecl decl) {
+        if (fAllGlobalElemDecls.get(decl) == null) {
+            fAllGlobalElemDecls.put(decl, decl);
+            // if there is a substitution group affiliation, store in an array,
+            // for further constraint checking: UPA, PD, EDC
+            if (decl.fSubGroup != null) {
+               if (fSubGroupCount == fSubGroups.length)
+                    fSubGroups = resize(fSubGroups, fSubGroupCount+INC_SIZE);
+                fSubGroups[fSubGroupCount++] = decl;
+            }
+        }
+    }
+
     public void addGlobalElementDecl(XSElementDecl decl) {
         fGlobalElemDecls.put(decl.fName, decl);
         decl.setNamespaceItem(this);
+    }
 
-        // if there is a substitution group affiliation, store in an array,
-        // for further constraint checking: UPA, PD, EDC
-        if (decl.fSubGroup != null) {
-            if (fSubGroupCount == fSubGroups.length)
-                fSubGroups = resize(fSubGroups, fSubGroupCount+INC_SIZE);
-            fSubGroups[fSubGroupCount++] = decl;
+    public void addGlobalElementDecl(XSElementDecl decl, String location) {
+        fGlobalElemDeclsExt.put(((location != null) ? location : "") + "," + decl.fName, decl);
+        if (decl.getNamespaceItem() == null) {
+            decl.setNamespaceItem(this);
         }
     }
 
@@ -682,6 +911,13 @@
         decl.setNamespaceItem(this);
     }
 
+    public void addGlobalGroupDecl(XSGroupDecl decl, String location) {
+        fGlobalGroupDeclsExt.put(((location!=null) ? location : "") + "," + decl.fName, decl);
+        if (decl.getNamespaceItem() == null) {
+            decl.setNamespaceItem(this);
+        }
+    }
+
     /**
      * register one global notation
      */
@@ -690,6 +926,13 @@
         decl.setNamespaceItem(this);
     }
 
+    public void addGlobalNotationDecl(XSNotationDecl decl, String location) {
+        fGlobalNotationDeclsExt.put(((location!=null) ? location : "") + "," +decl.fName, decl);
+        if (decl.getNamespaceItem() == null) {
+            decl.setNamespaceItem(this);
+        }
+    }
+
     /**
      * register one global type
      */
@@ -702,7 +945,19 @@
             ((XSSimpleTypeDecl) decl).setNamespaceItem(this);
         }
     }
-    
+
+    public void addGlobalTypeDecl(XSTypeDefinition decl, String location) {
+        fGlobalTypeDeclsExt.put(((location!=null) ? location : "") + "," + decl.getName(), decl);
+        if (decl.getNamespaceItem() == null) {
+            if (decl instanceof XSComplexTypeDecl) {
+                ((XSComplexTypeDecl) decl).setNamespaceItem(this);
+            }
+            else if (decl instanceof XSSimpleTypeDecl) {
+                ((XSSimpleTypeDecl) decl).setNamespaceItem(this);
+            }
+        }
+    }
+
     /**
      * register one global complex type
      */
@@ -710,6 +965,13 @@
         fGlobalTypeDecls.put(decl.getName(), decl);
         decl.setNamespaceItem(this);
     }
+
+    public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl, String location) {
+        fGlobalTypeDeclsExt.put(((location!=null) ? location : "") + "," + decl.getName(), decl);
+        if (decl.getNamespaceItem() == null) {
+            decl.setNamespaceItem(this);
+        }
+    }
     
     /**
      * register one global simple type
@@ -721,6 +983,13 @@
         }
     }
 
+    public void addGlobalSimpleTypeDecl(XSSimpleType decl, String location) {
+        fGlobalTypeDeclsExt.put(((location != null) ? location : "") + "," + decl.getName(), decl);
+        if (decl.getNamespaceItem() == null && decl instanceof XSSimpleTypeDecl) {
+            ((XSSimpleTypeDecl) decl).setNamespaceItem(this);
+        }
+    }
+
     /**
      * register one identity constraint
      */
@@ -729,6 +998,10 @@
         fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl);
     }
 
+    public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint decl, String location) {
+        fGlobalIDConstraintDeclsExt.put(((location != null) ? location : "") + "," + decl.getIdentityConstraintName(), decl);
+    }
+
     /**
      * register one type alternative
      */
@@ -743,6 +1016,10 @@
         return(XSAttributeDecl)fGlobalAttrDecls.get(declName);
     }
 
+    public final XSAttributeDecl getGlobalAttributeDecl(String declName, String location) {
+        return(XSAttributeDecl)fGlobalAttrDeclsExt.get(((location != null) ? location : "") + "," + declName);
+    }
+
     /**
      * get one global attribute group
      */
@@ -750,6 +1027,10 @@
         return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName);
     }
 
+    public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declName, String location) {
+        return(XSAttributeGroupDecl)fGlobalAttrGrpDeclsExt.get(((location != null) ? location : "") + "," + declName);
+    }
+
     /**
      * get one global element
      */
@@ -757,6 +1038,10 @@
         return(XSElementDecl)fGlobalElemDecls.get(declName);
     }
 
+    public final XSElementDecl getGlobalElementDecl(String declName, String location) {
+        return(XSElementDecl)fGlobalElemDeclsExt.get(((location != null) ? location : "") + "," + declName);
+    }
+    
     /**
      * get one global group
      */
@@ -764,6 +1049,10 @@
         return(XSGroupDecl)fGlobalGroupDecls.get(declName);
     }
 
+    public final XSGroupDecl getGlobalGroupDecl(String declName, String location) {
+        return(XSGroupDecl)fGlobalGroupDeclsExt.get(((location != null) ? location : "") + "," + declName);
+    }
+
     /**
      * get one global notation
      */
@@ -771,6 +1060,10 @@
         return(XSNotationDecl)fGlobalNotationDecls.get(declName);
     }
 
+    public final XSNotationDecl getGlobalNotationDecl(String declName, String location) {
+        return(XSNotationDecl)fGlobalNotationDeclsExt.get(((location != null) ? location : "") + "," + declName);
+    }
+
     /**
      * get one global type
      */
@@ -778,6 +1071,10 @@
         return(XSTypeDefinition)fGlobalTypeDecls.get(declName);
     }
 
+    public final XSTypeDefinition getGlobalTypeDecl(String declName, String location) {
+        return(XSTypeDefinition)fGlobalTypeDeclsExt.get(((location != null) ? location : "") + "," + declName);
+    }
+
     /**
      * get one identity constraint
      */
@@ -785,6 +1082,10 @@
         return(IdentityConstraint)fGlobalIDConstraintDecls.get(declName);
     }
 
+    public final IdentityConstraint getIDConstraintDecl(String declName, String location) {
+        return(IdentityConstraint)fGlobalIDConstraintDeclsExt.get(((location != null) ? location : "") + "," + declName);
+    }
+
     /**
      * get one identity constraint
      */
@@ -1130,6 +1431,7 @@
                                                  
     // store a certain kind of components from all namespaces
     private XSNamedMap[] fComponents = null;
+    private ObjectList[] fComponentsExt = null;
 
     // store the documents and their locations contributing to this namespace
     // REVISIT: use StringList and XSObjectList for there fields.
@@ -1271,6 +1573,53 @@
         return fComponents[objectType];
     }
 
+    public synchronized ObjectList getComponentsExt(short objectType) {
+        if (objectType <= 0 || objectType > MAX_COMP_IDX ||
+            !GLOBAL_COMP[objectType]) {
+            return ObjectListImpl.EMPTY_LIST;
+        }
+        
+        if (fComponentsExt == null)
+            fComponentsExt = new ObjectList[MAX_COMP_IDX+1];
+
+        // get the hashtable for this type of components
+        if (fComponentsExt[objectType] == null) {
+            SymbolHash table = null;
+            switch (objectType) {
+            case XSConstants.TYPE_DEFINITION:
+            case XSTypeDefinition.COMPLEX_TYPE:
+            case XSTypeDefinition.SIMPLE_TYPE:
+                table = fGlobalTypeDeclsExt;
+                break;
+            case XSConstants.ATTRIBUTE_DECLARATION:
+                table = fGlobalAttrDeclsExt;
+                break;
+            case XSConstants.ELEMENT_DECLARATION:
+                table = fGlobalElemDeclsExt;
+                break;
+            case XSConstants.ATTRIBUTE_GROUP:
+                table = fGlobalAttrGrpDeclsExt;
+                break;
+            case XSConstants.MODEL_GROUP_DEFINITION:
+                table = fGlobalGroupDeclsExt;
+                break;
+            case XSConstants.NOTATION_DECLARATION:
+                table = fGlobalNotationDeclsExt;
+                break;
+            }
+
+            Object[] entries = table.getEntries();
+            fComponentsExt[objectType] = new ObjectListImpl(entries, entries.length);
+        }
+
+        return fComponentsExt[objectType];
+    }
+
+    public synchronized void resetComponents() {
+        fComponents = null;
+        fComponentsExt = null;
+    }
+
     /**
      * Convenience method. Returns a top-level simple or complex type
      * definition.

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java Thu Nov 26 14:28:33 2009
@@ -38,6 +38,8 @@
 import org.apache.xerces.impl.XMLEntityManager;
 import org.apache.xerces.impl.XMLErrorReporter;
 import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
+import org.apache.xerces.impl.dv.SchemaDVFactory;
+import org.apache.xerces.impl.dv.xs.BaseSchemaDVFactory;
 import org.apache.xerces.impl.xs.models.CMBuilder;
 import org.apache.xerces.impl.xs.models.CMNodeFactory;
 import org.apache.xerces.impl.xs.traversers.XSDHandler;
@@ -132,7 +134,19 @@
         Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
     
     protected static final String PARSER_SETTINGS = 
-        Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;   
+        Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
+    
+    /** Feature identifier: namespace growth */
+    protected static final String NAMESPACE_GROWTH = 
+        Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+    
+    /** Feature identifier: tolerate duplicates */
+    protected static final String TOLERATE_DUPLICATES = 
+        Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
+    
+    /** Property identifier: Schema DV Factory */
+    protected static final String SCHEMA_DV_FACTORY = 
+        Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
     
     // recognized features:
     private static final String[] RECOGNIZED_FEATURES = {
@@ -144,7 +158,9 @@
         DISALLOW_DOCTYPE,
         GENERATE_SYNTHETIC_ANNOTATIONS,
         VALIDATE_ANNOTATIONS,
-        HONOUR_ALL_SCHEMALOCATIONS
+        HONOUR_ALL_SCHEMALOCATIONS,
+        NAMESPACE_GROWTH,
+        TOLERATE_DUPLICATES
     };
     
     // property identifiers
@@ -182,7 +198,11 @@
         Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
     
     protected static final String SECURITY_MANAGER =
-        Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;  
+        Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
+    
+    /** Property identifier: locale. */
+    protected static final String LOCALE =
+        Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY;
     
     protected static final String ENTITY_MANAGER =
         Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;   
@@ -202,9 +222,14 @@
         SCHEMA_NONS_LOCATION,
         JAXP_SCHEMA_SOURCE,
         SECURITY_MANAGER,
+        LOCALE,
+        SCHEMA_DV_FACTORY,
         XML_SCHEMA_VERSION
     };
     
+    private static final String EXTENDED_SCHEMA_FACTORY_CLASS = "org.apache.xerces.impl.dv.xs.ExtendedSchemaDVFactoryImpl";
+    private static final String SCHEMA11_FACTORY_CLASS = "org.apache.xerces.impl.dv.xs.Schema11DVFactoryImpl";
+    
     // Data
     
     // features and properties
@@ -231,6 +256,7 @@
     private SubstitutionGroupHandler fSubGroupHandler;
     private CMBuilder fCMBuilder;
     private XSDDescription fXSDDescription = new XSDDescription();
+    private SchemaDVFactory fDefaultSchemaDVFactory;
     
     private WeakHashMap fJAXPCache;
     private Locale fLocale = Locale.getDefault();
@@ -325,7 +351,6 @@
         }
         fCMBuilder = builder;
         fSchemaHandler = new XSDHandler(fGrammarBucket, fSchemaVersion, fXSConstraints);
-        fDeclPool = new XSDeclarationPool();
         fJAXPCache = new WeakHashMap();
         
         fSettingsChanged = true;
@@ -420,6 +445,9 @@
         else if (propertyId.equals(SCHEMA_NONS_LOCATION)){
             fExternalNoNSSchema = (String) state;
         }
+        else if (propertyId.equals(LOCALE)) {
+            setLocale((Locale) state);
+        }
         else if (propertyId.equals(ENTITY_RESOLVER)){
             fEntityManager.setProperty(ENTITY_RESOLVER, state);
         }
@@ -979,13 +1007,16 @@
         
         fGrammarBucket.reset();
         
-        fSubGroupHandler.reset();		
+        fSubGroupHandler.reset();
         
         if (!fSettingsChanged || !parserSettingsUpdated(componentManager)) {
             // need to reprocess JAXP schema sources
             fJAXPProcessed = false;
             // reinitialize grammar bucket
             initGrammarBucket();
+            if (fDeclPool != null) {
+                fDeclPool.reset();
+            }
             return;           
         } 
         
@@ -997,22 +1028,20 @@
         // get the error reporter
         fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);
         
-        boolean psvi = true;
+        // Determine schema dv factory to use
+        SchemaDVFactory dvFactory = null;
         try {
-            psvi = componentManager.getFeature(AUGMENT_PSVI);
+            dvFactory = (SchemaDVFactory)componentManager.getProperty(SCHEMA_DV_FACTORY);
         } catch (XMLConfigurationException e) {
-            psvi = false;
         }
-        
-        if (!psvi) {
-            fDeclPool.reset();
-            fCMBuilder.setDeclPool(fDeclPool);
-            fSchemaHandler.setDeclPool(fDeclPool);
-        } else {
-            fCMBuilder.setDeclPool(null);
-            fSchemaHandler.setDeclPool(null);
+        if (dvFactory == null) {
+            if (fDefaultSchemaDVFactory == null) {
+                fDefaultSchemaDVFactory = getSchemaDVFactory(fSchemaVersion);
+            }
+            dvFactory = fDefaultSchemaDVFactory;
         }
-        
+        fSchemaHandler.setDVFactory(dvFactory);
+
         // get schema location properties
         try {
             fExternalSchemas = (String) componentManager.getProperty(SCHEMA_LOCATION);
@@ -1039,6 +1068,41 @@
             fGrammarPool = null;
         }
         initGrammarBucket();
+
+        boolean psvi = true;
+        try {
+            psvi = componentManager.getFeature(AUGMENT_PSVI);
+        } catch (XMLConfigurationException e) {
+            psvi = false;
+        }
+        
+        // Only use the decl pool when there is no chance that the schema
+        // components will be exposed or cached.
+        // TODO: when someone calls loadGrammar(XMLInputSource), the schema is
+        // always exposed even without the use of a grammar pool.
+        // Disabling the "decl pool" feature for now until we understand when
+        // it can be safely used.
+        if (!psvi && fGrammarPool == null && false) {
+            if (fDeclPool != null) {
+                fDeclPool.reset();
+            }
+            else {
+                fDeclPool = new XSDeclarationPool();
+            }
+            fCMBuilder.setDeclPool(fDeclPool);
+            fSchemaHandler.setDeclPool(fDeclPool);
+            if (dvFactory instanceof BaseSchemaDVFactory) {
+                fDeclPool.setDVFactory((BaseSchemaDVFactory)dvFactory);
+                ((BaseSchemaDVFactory)dvFactory).setDeclPool(fDeclPool);
+            }
+        } else {
+            fCMBuilder.setDeclPool(null);
+            fSchemaHandler.setDeclPool(null);
+            if (dvFactory instanceof BaseSchemaDVFactory) {
+                ((BaseSchemaDVFactory)dvFactory).setDeclPool(null);
+            }
+        }
+        
         // get continue-after-fatal-error feature
         try {
             boolean fatalError = componentManager.getFeature(CONTINUE_AFTER_FATAL_ERROR);
@@ -1061,7 +1125,18 @@
         }
         fSchemaHandler.reset(componentManager);		 
     }
-    
+    private SchemaDVFactory getSchemaDVFactory(short schemaVersion) {
+        if (schemaVersion != Constants.SCHEMA_VERSION_1_0) {
+            if (schemaVersion == Constants.SCHEMA_VERSION_1_1) {
+                return SchemaDVFactory.getInstance(SCHEMA11_FACTORY_CLASS);
+            }
+            else {
+                return  SchemaDVFactory.getInstance(EXTENDED_SCHEMA_FACTORY_CLASS);
+            }
+        }
+
+        return SchemaDVFactory.getInstance();
+    }
     private boolean parserSettingsUpdated(XMLComponentManager componentManager) {
         try {
             return componentManager.getFeature(PARSER_SETTINGS);     
@@ -1180,7 +1255,9 @@
                 name.equals(ALLOW_JAVA_ENCODINGS) ||
                 name.equals(STANDARD_URI_CONFORMANT_FEATURE) ||
                 name.equals(GENERATE_SYNTHETIC_ANNOTATIONS) ||
-                name.equals(HONOUR_ALL_SCHEMALOCATIONS)) {
+                name.equals(HONOUR_ALL_SCHEMALOCATIONS) ||
+                name.equals(NAMESPACE_GROWTH) ||
+                name.equals(TOLERATE_DUPLICATES)) {
                 return true;
                 
             }
@@ -1195,7 +1272,8 @@
             name.equals(XMLGRAMMAR_POOL) ||
             name.equals(SCHEMA_LOCATION) ||
             name.equals(SCHEMA_NONS_LOCATION) ||
-            name.equals(JAXP_SCHEMA_SOURCE)) {
+            name.equals(JAXP_SCHEMA_SOURCE) ||
+            name.equals(SCHEMA_DV_FACTORY)) {
             return true;
         }
         return false;
@@ -1256,6 +1334,8 @@
             v.add(VALIDATE_ANNOTATIONS);
             v.add(GENERATE_SYNTHETIC_ANNOTATIONS);
             v.add(HONOUR_ALL_SCHEMALOCATIONS);
+            v.add(NAMESPACE_GROWTH);
+            v.add(TOLERATE_DUPLICATES);
             fRecognizedParameters = new DOMStringListImpl(v);      	
         }
         return fRecognizedParameters;

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=884565&r1=884564&r2=884565&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 Nov 26 14:28:33 2009
@@ -18,6 +18,7 @@
 package org.apache.xerces.impl.xs;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -29,6 +30,7 @@
 
 import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.RevalidationHandler;
+import org.apache.xerces.impl.XMLEntityManager;
 import org.apache.xerces.impl.XMLErrorReporter;
 import org.apache.xerces.impl.dv.DatatypeException;
 import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
@@ -51,6 +53,7 @@
 import org.apache.xerces.impl.xs.identity.XPathMatcher;
 import org.apache.xerces.impl.xs.models.CMBuilder;
 import org.apache.xerces.impl.xs.models.CMNodeFactory;
+import org.apache.xerces.impl.xs.models.XCMValidatorHelper;
 import org.apache.xerces.impl.xs.models.XSCMValidator;
 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 import org.apache.xerces.util.AugmentationsImpl;
@@ -59,6 +62,7 @@
 import org.apache.xerces.util.XMLAttributesImpl;
 import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.util.XMLSymbols;
+import org.apache.xerces.util.URI.MalformedURIException;
 import org.apache.xerces.xni.Augmentations;
 import org.apache.xerces.xni.NamespaceContext;
 import org.apache.xerces.xni.QName;
@@ -81,6 +85,7 @@
 import org.apache.xerces.xs.AttributePSVI;
 import org.apache.xerces.xs.ElementPSVI;
 import org.apache.xerces.xs.ShortList;
+import org.apache.xerces.xs.StringList;
 import org.apache.xerces.xs.XSAssert;
 import org.apache.xerces.xs.XSAttributeDeclaration;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
@@ -117,7 +122,7 @@
  * @version $Id$
  */
 public class XMLSchemaValidator
-    implements XMLComponent, XMLDocumentFilter, FieldActivator, RevalidationHandler {
+    implements XMLComponent, XMLDocumentFilter, FieldActivator, RevalidationHandler, XCMValidatorHelper {
 
     //
     // Constants
@@ -184,6 +189,14 @@
 
     protected static final String PARSER_SETTINGS =
             Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
+    
+    /** Feature identifier: namespace growth */
+    protected static final String NAMESPACE_GROWTH = 
+        Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACE_GROWTH_FEATURE;
+
+    /** Feature identifier: tolerate duplicates */
+    protected static final String TOLERATE_DUPLICATES = 
+        Constants.XERCES_FEATURE_PREFIX + Constants.TOLERATE_DUPLICATES_FEATURE;
 
     /** Feature identifier: whether to ignore xsi:type attributes until a global element declaration is encountered */
     protected static final String IGNORE_XSI_TYPE =
@@ -253,6 +266,10 @@
     protected static final String ROOT_ELEMENT_DECL =
         Constants.XERCES_PROPERTY_PREFIX + Constants.ROOT_ELEMENT_DECLARATION_PROPERTY;
 
+    /** Property identifier: Schema DV Factory */
+    protected static final String SCHEMA_DV_FACTORY = 
+        Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_DV_FACTORY_PROPERTY;
+
     /** Property identifier: xml schema version. */
     protected static final String XML_SCHEMA_VERSION =
         Constants.XERCES_PROPERTY_PREFIX + Constants.XML_SCHEMA_VERSION_PROPERTY;
@@ -277,7 +294,9 @@
             ID_IDREF_CHECKING,
             IDENTITY_CONSTRAINT_CHECKING,
             UNPARSED_ENTITY_CHECKING,
-            TYPE_ALTERNATIVES_CHECKING,
+            NAMESPACE_GROWTH,
+            TOLERATE_DUPLICATES,
+            TYPE_ALTERNATIVES_CHECKING
         };
 
 
@@ -308,6 +327,8 @@
         null,
         null,
         null,
+        null,
+        null
     };
 
     /** Recognized properties. */
@@ -323,12 +344,13 @@
             JAXP_SCHEMA_LANGUAGE,
             ROOT_TYPE_DEF,
             ROOT_ELEMENT_DECL,
+            SCHEMA_DV_FACTORY,
             XML_SCHEMA_VERSION,
         };
 
     /** Property defaults. */
     private static final Object[] PROPERTY_DEFAULTS =
-        { null, null, null, null, null, null, null, null, null, null, null, };
+        { null, null, null, null, null, null, null, null, null, null, null, null};
 
     // this is the number of valuestores of each kind
     // we expect an element to have.  It's almost
@@ -339,7 +361,10 @@
     static final XSAttributeDecl XSI_TYPE = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_TYPE);
     static final XSAttributeDecl XSI_NIL = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NIL);
     static final XSAttributeDecl XSI_SCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_SCHEMALOCATION);
-    static final XSAttributeDecl XSI_NONAMESPACESCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);  
+    static final XSAttributeDecl XSI_NONAMESPACESCHEMALOCATION = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
+
+    //
+    private static final Hashtable EMPTY_TABLE = new Hashtable();
 
     //
     // Data
@@ -369,6 +394,9 @@
     protected boolean fIdConstraint = false;
     protected boolean fUseGrammarPoolOnly = false;
 
+    // Namespace growth feature
+    protected boolean fNamespaceGrowth = false;
+    
     /** Schema type: None, DTD, Schema */
     private String fSchemaType = null;
 
@@ -526,6 +554,8 @@
     /** Schema Grammar Description passed,  to give a chance to application to supply the Grammar */
     protected final XSDDescription fXSDDescription = new XSDDescription();
     protected final Hashtable fLocationPairs = new Hashtable();
+    protected final Hashtable fExpandedLocationPairs = new Hashtable();
+    protected final ArrayList fUnparsedLocations = new ArrayList();
 
     /** XML Schema 1.1 Support */
     short fSchemaVersion;
@@ -1396,6 +1426,7 @@
         fIdConstraint = false;
         //reset XSDDescription
         fLocationPairs.clear();
+        fExpandedLocationPairs.clear();
 
         // cleanup id table
         fValidationState.resetIDTables();
@@ -1452,6 +1483,12 @@
         if (symbolTable != fSymbolTable) {
             fSymbolTable = symbolTable;
         }
+        
+        try {
+            fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH);
+        } catch (XMLConfigurationException e) {
+            fNamespaceGrowth = false;
+        }
 
         try {
             fDynamicValidation = componentManager.getFeature(DYNAMIC_VALIDATION);
@@ -1697,6 +1734,21 @@
         matcher.startDocumentFragment();
     }
 
+    // Implements XCMValidatorHelper interface
+    public XSElementDecl getGlobalElementDecl(QName element) {
+        final SchemaGrammar sGrammar =
+            findSchemaGrammar(
+                XSDDescription.CONTEXT_ELEMENT,
+                element.uri,
+                null,
+                element,
+                null);
+        if (sGrammar != null) {
+            return sGrammar.getGlobalElementDecl(element.localpart);
+        }
+        return null;
+    }
+    
     //
     // Protected methods
     //
@@ -1967,7 +2019,7 @@
         storeLocations(sLocation, nsLocation);
 
         // if we are in the content of "skip", then just skip this element
-        // REVISIT:  is this the correct behavior for ID constraints?  -NG
+        // REVISIT:  is this the correct behaviour for ID constraints?  -NG
         if (fSkipValidationDepth >= 0) {
             fElementDepth++;
             if (fAugPSVI)
@@ -1975,15 +2027,6 @@
             return augs;
         }
 
-        //try to find schema grammar by different means..
-        SchemaGrammar sGrammar =
-            findSchemaGrammar(
-                XSDDescription.CONTEXT_ELEMENT,
-                element.uri,
-                null,
-                element,
-                attributes);
-
         // if we are not skipping this element, and there is a content model,
         // we try to find the corresponding decl object for this element.
         // the reason we move this part of code here is to make sure the
@@ -1991,7 +2034,7 @@
         // context, instead of that of the current element.
         Object decl = null;
         if (fCurrentCM != null) {
-            decl = fCurrentCM.oneTransition(element, fCurrCMState, fSubGroupHandler, sGrammar);
+            decl = fCurrentCM.oneTransition(element, fCurrCMState, fSubGroupHandler, this);
             // it could be an element decl or a wildcard decl
             if (fCurrCMState[0] == XSCMValidator.FIRST_ERROR) {
                 XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType;
@@ -2153,6 +2196,14 @@
             // case 1: find declaration for root element
             // case 2: find declaration for element from another namespace
             if (fCurrentElemDecl == null) {
+                // try to find schema grammar by different means..
+                SchemaGrammar sGrammar =
+                    findSchemaGrammar(
+                        XSDDescription.CONTEXT_ELEMENT,
+                        element.uri,
+                        null,
+                        element,
+                        attributes);
                 if (sGrammar != null) {
                     fCurrentElemDecl = sGrammar.getGlobalElementDecl(element.localpart);
                 }
@@ -2163,7 +2214,7 @@
                 fCurrentType = fCurrentElemDecl.fType;
             }
         }
-               
+
         // check if we should be ignoring xsi:type on this element
         if (fElementDepth == fIgnoreXSITypeDepth && fCurrentElemDecl == null) {
             fIgnoreXSITypeDepth++;
@@ -2676,6 +2727,10 @@
             grammars = fGrammarBucket.getGrammars();
             // return the final set of grammars validator ended up with
             if (fGrammarPool != null) {
+                // Set grammars as immutable
+                for (int k=0; k < grammars.length; k++) {
+                    grammars[k].setImmutable(true);
+                }
                 fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, grammars);
             }
             augs = endElementPSVI(true, grammars, augs);
@@ -2834,39 +2889,19 @@
         short contextType,
         String namespace,
         QName enclosingElement,
-        QName triggeringComponet,
+        QName triggeringComponent,
         XMLAttributes attributes) {
         SchemaGrammar grammar = null;
         //get the grammar from local pool...
         grammar = fGrammarBucket.getGrammar(namespace);
         if (grammar == null) {
-            fXSDDescription.reset();
-            fXSDDescription.fContextType = contextType;
             fXSDDescription.setNamespace(namespace);
-            fXSDDescription.fEnclosedElementName = enclosingElement;
-            fXSDDescription.fTriggeringComponent = triggeringComponet;
-            fXSDDescription.fAttributes = attributes;
-            if (fLocator != null) {
-                fXSDDescription.setBaseSystemId(fLocator.getExpandedSystemId());
-            }
-
-            String[] temp = null;
-            Object locationArray =
-                fLocationPairs.get(namespace == null ? XMLSymbols.EMPTY_STRING : namespace);
-            if (locationArray != null)
-                temp = ((XMLSchemaLoader.LocationArray) locationArray).getLocationArray();
-            if (temp != null && temp.length != 0) {
-                fXSDDescription.fLocationHints = new String[temp.length];
-                System.arraycopy(temp, 0, fXSDDescription.fLocationHints, 0, temp.length);
-            }
-
-            // give a chance to application to be able to retreive the grammar.
             if (fGrammarPool != null) {
                 grammar = (SchemaGrammar) fGrammarPool.retrieveGrammar(fXSDDescription);
                 if (grammar != null) {
                     // put this grammar into the bucket, along with grammars
                     // imported by it (directly or indirectly)
-                    if (!fGrammarBucket.putGrammar(grammar, true)) {
+                    if (!fGrammarBucket.putGrammar(grammar, true, fNamespaceGrowth)) {
                         // REVISIT: a conflict between new grammar(s) and grammars
                         // in the bucket. What to do? A warning? An exception?
                         fXSIErrorReporter.fErrorReporter.reportError(
@@ -2878,15 +2913,58 @@
                     }
                 }
             }
-            if (grammar == null && !fUseGrammarPoolOnly) {
+        }
+
+        if (!fUseGrammarPoolOnly && (grammar == null || 
+            (fNamespaceGrowth && !hasSchemaComponent(grammar, contextType, triggeringComponent)))) {
+            fXSDDescription.reset();
+            fXSDDescription.fContextType = contextType;
+            fXSDDescription.setNamespace(namespace);
+            fXSDDescription.fEnclosedElementName = enclosingElement;
+            fXSDDescription.fTriggeringComponent = triggeringComponent;
+            fXSDDescription.fAttributes = attributes;
+            if (fLocator != null) {
+                fXSDDescription.setBaseSystemId(fLocator.getExpandedSystemId());
+            }
+
+            Hashtable locationPairs = fLocationPairs;
+            Object locationArray =
+                locationPairs.get(namespace == null ? XMLSymbols.EMPTY_STRING : namespace);
+            if (locationArray != null) {
+                String[] temp = ((XMLSchemaLoader.LocationArray) locationArray).getLocationArray();
+                if (temp.length != 0) {
+                    setLocationHints(fXSDDescription, temp, grammar);
+                }
+            }
+
+            if (grammar == null || fXSDDescription.fLocationHints != null) {
+                boolean toParseSchema = true;
+                if (grammar != null) {
+                     // use location hints instead
+                    locationPairs = EMPTY_TABLE;
+                }
+
                 // try to parse the grammar using location hints from that namespace..
                 try {
                     XMLInputSource xis =
                         XMLSchemaLoader.resolveDocument(
                             fXSDDescription,
-                            fLocationPairs,
+                            locationPairs,
                             fEntityResolver);
-                    grammar = fSchemaLoader.loadSchema(fXSDDescription, xis, fLocationPairs);
+                    if (grammar != null && fNamespaceGrowth) {
+                        try {
+                            // if we are dealing with a different schema location, then include the new schema
+                            // into the existing grammar
+                            if (grammar.getDocumentLocations().contains(XMLEntityManager.expandSystemId(xis.getSystemId(), xis.getBaseSystemId(), false))) {
+                                toParseSchema = false; 
+                            }
+                        }
+                        catch (MalformedURIException e) {
+                        }
+                    }
+                    if (toParseSchema) {
+                        grammar = fSchemaLoader.loadSchema(fXSDDescription, xis, fLocationPairs);
+                    }
                 } catch (IOException ex) {
                     final String [] locationHints = fXSDDescription.getLocationHints();
                     fXSIErrorReporter.fErrorReporter.reportError(
@@ -2902,6 +2980,61 @@
 
     } //findSchemaGrammar
 
+    private boolean hasSchemaComponent(SchemaGrammar grammar, short contextType, QName triggeringComponent) {
+        if (grammar != null && triggeringComponent != null) {
+            String localName = triggeringComponent.localpart;
+            if (localName != null && localName.length() > 0) {
+                switch (contextType) {
+                    case XSDDescription.CONTEXT_ELEMENT:
+                        return grammar.getElementDeclaration(localName) != null;
+                    case XSDDescription.CONTEXT_ATTRIBUTE:
+                        return grammar.getAttributeDeclaration(localName) != null;
+                    case XSDDescription.CONTEXT_XSITYPE:
+                        return grammar.getTypeDefinition(localName) != null;
+                }
+            }
+        }
+        return false;
+    }
+
+    private void setLocationHints(XSDDescription desc, String[] locations, SchemaGrammar grammar) {
+        int length = locations.length;
+        if (grammar == null) {
+            fXSDDescription.fLocationHints = new String[length];
+            System.arraycopy(locations, 0, fXSDDescription.fLocationHints, 0, length);
+        }
+        else {
+            setLocationHints(desc, locations, grammar.getDocumentLocations());
+        }
+    }
+    
+    private void setLocationHints(XSDDescription desc, String[] locations, StringList docLocations) {
+        int length = locations.length;
+        String[] hints = new String[length];
+        int counter = 0;
+
+        for (int i=0; i<length; i++) {
+            try {
+                String id = XMLEntityManager.expandSystemId(locations[i], desc.getBaseSystemId(), false);
+                if (!docLocations.contains(id)) {
+                    hints[counter++] = locations[i];
+                }
+            }
+            catch (MalformedURIException e) {
+            }
+        }
+
+        if (counter > 0) {
+            if (counter == length) {
+                fXSDDescription.fLocationHints = hints;
+            }
+            else {
+                fXSDDescription.fLocationHints = new String[counter];
+                System.arraycopy(hints, 0, fXSDDescription.fLocationHints, 0, counter);
+            }
+        }
+    }
+
     private boolean isValidBuiltInTypeName(String localpart) {
         if (fSchemaVersion == Constants.SCHEMA_VERSION_1_0_EXTENDED) {
             if (localpart.equals("duration") ||
@@ -2912,6 +3045,7 @@
         }
         return true;
     }
+
     XSTypeDefinition getAndCheckXsiType(QName element, String xsiType, XMLAttributes attributes) {
         // This method also deals with clause 1.2.1.2 of the constraint
         // Validation Rule: Schema-Validity Assessment (Element)

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java Thu Nov 26 14:28:33 2009
@@ -69,26 +69,36 @@
     // otherwise, return null
     public String addAttributeUse(XSAttributeUseImpl attrUse) {
 
-        if (fAttrUseNum == fAttributeUses.length) {
-            fAttributeUses = resize(fAttributeUses, fAttrUseNum*2);
-        }
-        fAttributeUses[fAttrUseNum++] = attrUse;
         // if this attribute use is prohibited, then don't check whether it's
         // of type ID
-        if (attrUse.fUse == SchemaSymbols.USE_PROHIBITED)
-            return null;
+        if (attrUse.fUse != SchemaSymbols.USE_PROHIBITED) {
+            if (attrUse.fAttrDecl.fType.isIDType()) {
+                // if there is already an attribute use of type ID,
+                // return its name (and don't add it to the list, to avoid
+                // interruption to instance validation.
+                if (fIDAttrName == null)
+                    fIDAttrName = attrUse.fAttrDecl.fName;
+                else
+                    return fIDAttrName;
+            }
+        }
 
-        if (attrUse.fAttrDecl.fType.isIDType()) {
-            // if there is already an attribute use of type ID, return it' sname
-            if (fIDAttrName == null)
-                fIDAttrName = attrUse.fAttrDecl.fName;
-            else
-                return fIDAttrName;
+        if (fAttrUseNum == fAttributeUses.length) {
+            fAttributeUses = resize(fAttributeUses, fAttrUseNum*2);
         }
+        fAttributeUses[fAttrUseNum++] = attrUse;
 
         return null;
     }
 
+    public void replaceAttributeUse(XSAttributeUse oldUse, XSAttributeUseImpl newUse) {
+        for (int i=0; i<fAttrUseNum; i++) {
+            if (fAttributeUses[i] == oldUse) {
+                fAttributeUses[i] = newUse;
+            }
+        }
+    }
+
     public XSAttributeUse getAttributeUse(String namespace, String name) {
         for (int i=0; i<fAttrUseNum; i++) {
             if ( (fAttributeUses[i].fAttrDecl.fTargetNamespace == namespace) &&
@@ -99,36 +109,50 @@
         return null;
     }
 
+    public XSAttributeUse getAttributeUseNoProhibited(String namespace, String name) {
+        for (int i=0; i<fAttrUseNum; i++) {
+            if ( (fAttributeUses[i].fAttrDecl.fTargetNamespace == namespace) &&
+                 (fAttributeUses[i].fAttrDecl.fName == name) &&
+                 (fAttributeUses[i].fUse != SchemaSymbols.USE_PROHIBITED))
+                return fAttributeUses[i];
+        }
+
+        return null;
+    }
+
     public void removeProhibitedAttrs() {
         if (fAttrUseNum == 0) return;
-        int pCount = 0;
-        XSAttributeUseImpl[] pUses = new XSAttributeUseImpl[fAttrUseNum];
+        // Remove all prohibited attributes.
+        int count = 0;
+        XSAttributeUseImpl[] uses = new XSAttributeUseImpl[fAttrUseNum];
         for (int i = 0; i < fAttrUseNum; i++) {
-            if (fAttributeUses[i].fUse == SchemaSymbols.USE_PROHIBITED) {
-                pCount++;
-                // we use the entries at the end, so that we can use the
-                // first entries to store non-prohibited attribute uses,
-                // hence avoid creating a new array.
-                pUses[fAttrUseNum-pCount] = fAttributeUses[i];
+            if (fAttributeUses[i].fUse != SchemaSymbols.USE_PROHIBITED) {
+                uses[count++] = fAttributeUses[i];
             }
         }
+        fAttributeUses = uses;
+        fAttrUseNum = count;
 
-        int newCount = 0;
-        if (pCount > 0) {
-            OUTER: for (int i = 0; i < fAttrUseNum; i++) {
-                if (fAttributeUses[i].fUse == SchemaSymbols.USE_PROHIBITED)
-                    continue;
-                for (int j = 1; j <= pCount; j++) {
-                    if (fAttributeUses[i].fAttrDecl.fName == pUses[fAttrUseNum-pCount].fAttrDecl.fName &&
-                        fAttributeUses[i].fAttrDecl.fTargetNamespace == pUses[fAttrUseNum-pCount].fAttrDecl.fTargetNamespace) {
-                        continue OUTER;
-                    }
-                }
-                pUses[newCount++] = fAttributeUses[i];
-            }
-            fAttributeUses = pUses;
-            fAttrUseNum = newCount;
-        }
+        // Do not remove attributes that have the same name as the prohibited
+        // ones, because they are specified at the same level. Prohibited
+        // attributes are only to remove attributes from the base type in a
+        // restriction.
+//        int newCount = 0;
+//        if (pCount > 0) {
+//            OUTER: for (int i = 0; i < fAttrUseNum; i++) {
+//                if (fAttributeUses[i].fUse == SchemaSymbols.USE_PROHIBITED)
+//                    continue;
+//                for (int j = 1; j <= pCount; j++) {
+//                    if (fAttributeUses[i].fAttrDecl.fName == pUses[fAttrUseNum-pCount].fAttrDecl.fName &&
+//                        fAttributeUses[i].fAttrDecl.fTargetNamespace == pUses[fAttrUseNum-pCount].fAttrDecl.fTargetNamespace) {
+//                        continue OUTER;
+//                    }
+//                }
+//                pUses[newCount++] = fAttributeUses[i];
+//            }
+//            fAttributeUses = pUses;
+//            fAttrUseNum = newCount;
+//        }
     }
 
     /**

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=884565&r1=884564&r2=884565&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 Nov 26 14:28:33 2009
@@ -30,6 +30,7 @@
 import org.apache.xerces.impl.xs.models.CMBuilder;
 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.SymbolHash;
 import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSObjectList;
@@ -55,6 +56,23 @@
     // TODO: using 1.0 xs:string
     static final XSSimpleType STRING_TYPE = (XSSimpleType)SchemaGrammar.getS4SGrammar(Constants.SCHEMA_VERSION_1_0).getGlobalTypeDecl(SchemaSymbols.ATTVAL_STRING);
 
+    private static XSParticleDecl fEmptyParticle = null;
+    public static XSParticleDecl getEmptySequence() {
+        if (fEmptyParticle == null) {
+            XSModelGroupImpl group = new XSModelGroupImpl();
+            group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
+            group.fParticleCount = 0;
+            group.fParticles = null;
+            group.fAnnotations = XSObjectListImpl.EMPTY_LIST;
+            XSParticleDecl particle = new XSParticleDecl();
+            particle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
+            particle.fValue = group;
+            particle.fAnnotations = XSObjectListImpl.EMPTY_LIST;
+            fEmptyParticle = particle;
+       }
+        return fEmptyParticle;
+    }
+
     static final XSConstraints XS_1_0_CONSTRAINTS = new XS10Constraints(Constants.SCHEMA_VERSION_1_0);
     static final XSConstraints XS_1_0_CONSTRAINTS_EXTENDED = new XS10Constraints(Constants.SCHEMA_VERSION_1_0_EXTENDED);
     static final XSConstraints XS_1_1_CONSTRAINTS = new XS11Constraints();

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDeclarationPool.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDeclarationPool.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDeclarationPool.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDeclarationPool.java Thu Nov 26 14:28:33 2009
@@ -17,6 +17,7 @@
 
 package org.apache.xerces.impl.xs;
 
+import org.apache.xerces.impl.dv.xs.BaseSchemaDVFactory;
 import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
 
 /**
@@ -71,6 +72,11 @@
     /** AttributeUse declaration pool */
     private XSAttributeUseImpl fAttributeUse[][] = new XSAttributeUseImpl[INITIAL_CHUNK_COUNT][];
     private int fAttributeUseIndex = 0;
+    
+    private BaseSchemaDVFactory dvFactory;
+    public void setDVFactory(BaseSchemaDVFactory dvFactory) {
+        this.dvFactory = dvFactory;
+    }
 
     public final  XSElementDecl getElementDecl(){
         int     chunk       = fElementDeclIndex >> CHUNK_SHIFT;
@@ -132,7 +138,7 @@
         int     index       = fSTDeclIndex &  CHUNK_MASK;
         ensureSTDeclCapacity(chunk);
         if (fSTDecl[chunk][index] == null) {
-            fSTDecl[chunk][index] = new XSSimpleTypeDecl();
+            fSTDecl[chunk][index] = dvFactory.newXSSimpleTypeDecl();
         } else {
             fSTDecl[chunk][index].reset();
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSGrammarBucket.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSGrammarBucket.java?rev=884565&r1=884564&r2=884565&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSGrammarBucket.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSGrammarBucket.java Thu Nov 26 14:28:33 2009
@@ -134,6 +134,77 @@
     }
 
     /**
+     * put a schema grammar and any grammars imported by it (directly or
+     * inderectly) into the registry. when a grammar with the same target
+     * namespace is already in the bucket, and different from the one being
+     * added, no grammar will be added into the bucket.
+     *
+     * @param grammar        the grammar to put in the registry
+     * @param deep           whether to add imported grammars
+     * @param ignoreConflict whether to ignore grammars that already exist in the grammar
+     *                       bucket or not - including 'grammar' parameter. 
+     * @return               whether the process succeeded
+     */
+    public boolean putGrammar(SchemaGrammar grammar, boolean deep, boolean ignoreConflict) {
+        if (!ignoreConflict) {
+            return putGrammar(grammar, deep);
+        }
+
+        // if grammar already exist in the bucket, we ignore the request
+        SchemaGrammar sg = getGrammar(grammar.fTargetNamespace);
+        if (sg == null) {
+            putGrammar(grammar);
+        }
+        
+        // not adding the imported grammars
+        if (!deep) {
+            return true;
+        }
+
+        // get all imported grammars, and make a copy of the Vector, so that
+        // we can recursively process the grammars, and add distinct ones
+        // to the same vector
+        Vector currGrammars = (Vector)grammar.getImportedGrammars();
+        if (currGrammars == null) {
+            return true;
+        }
+        
+        Vector grammars = ((Vector)currGrammars.clone());
+        SchemaGrammar sg1, sg2;
+        Vector gs;
+        // for all (recursively) imported grammars
+        for (int i = 0; i < grammars.size(); i++) {
+            // get the grammar
+            sg1 = (SchemaGrammar)grammars.elementAt(i);
+            // check whether the bucket has one with the same tns
+            sg2 = getGrammar(sg1.fTargetNamespace);
+            if (sg2 == null) {
+                // we need to add grammars imported by sg1 too
+                gs = sg1.getImportedGrammars();
+                // for all grammars imported by sg2, but not in the vector
+                // we add them to the vector
+                if(gs == null) continue;
+                for (int j = gs.size() - 1; j >= 0; j--) {
+                    sg2 = (SchemaGrammar)gs.elementAt(j);
+                    if (!grammars.contains(sg2))
+                        grammars.addElement(sg2);
+                }
+            }
+            // we found one with the same target namespace, ignore it
+            else  {
+                grammars.remove(sg1);
+            }
+        }
+
+        // now we have all imported grammars stored in the vector. add them
+        for (int i = grammars.size() - 1; i >= 0; i--) {
+            putGrammar((SchemaGrammar)grammars.elementAt(i));
+        }
+
+        return true;
+    }
+
+    /**
      * get all grammars in the registry
      *
      * @return an array of SchemaGrammars.



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


Mime
View raw message