You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2002/04/04 01:48:27 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/parsers NonValidatingConfiguration.java AbstractDOMParser.java

elena       02/04/03 15:48:27

  Modified:    java/src/org/apache/xerces/dom ASDOMImplementationImpl.java
                        AttrNSImpl.java CharacterDataImpl.java
                        CoreDOMImplementationImpl.java
                        DOMImplementationImpl.java ElementNSImpl.java
                        TextImpl.java
               java/src/org/apache/xerces/impl/dv/xs
                        SchemaDVFactoryImpl.java XSSimpleTypeDecl.java
               java/src/org/apache/xerces/impl/xs XMLSchemaValidator.java
                        XSAttributeDecl.java XSAttributeGroupDecl.java
                        XSAttributeUse.java XSComplexTypeDecl.java
                        XSDeclarationPool.java XSElementDecl.java
                        XSParticleDecl.java
               java/src/org/apache/xerces/impl/xs/dom DOMParser.java
                        DocumentImpl.java ElementNSImpl.java
               java/src/org/apache/xerces/impl/xs/models CMBuilder.java
               java/src/org/apache/xerces/impl/xs/traversers
                        XSDAbstractParticleTraverser.java
                        XSDAbstractTraverser.java
                        XSDAttributeTraverser.java
                        XSDComplexTypeTraverser.java
                        XSDElementTraverser.java XSDGroupTraverser.java
                        XSDHandler.java XSDSimpleTypeTraverser.java
                        XSDWildcardTraverser.java
               java/src/org/apache/xerces/parsers AbstractDOMParser.java
  Added:       java/src/org/apache/xerces/impl/xs/dom DOMNodePool.java
               java/src/org/apache/xerces/parsers
                        NonValidatingConfiguration.java
  Log:
  Tried to optimize XML Schema parsing code:
  1. Implemented XSDeclarationPool.
  2. Modified impl.xs.DOMParser to use NonValidatingConfiguration and specify CoreDocumentImpl
  as DocumentClassName for parsers.DOMParser.
  3. Implemented DOMNodePool that manages the pool of DOM nodes that are
  used for parsing XML Schemas.
  
  I wrote a small program that was parsing and validating 6 files for about 20 times each.
  The test showed ~7.8% decrease in object creation. The speed of the parser remained the same.
  
  Revision  Changes    Path
  1.2       +15 -1     xml-xerces/java/src/org/apache/xerces/dom/ASDOMImplementationImpl.java
  
  Index: ASDOMImplementationImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ASDOMImplementationImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ASDOMImplementationImpl.java	28 Mar 2002 21:17:30 -0000	1.1
  +++ ASDOMImplementationImpl.java	3 Apr 2002 23:48:26 -0000	1.2
  @@ -79,13 +79,27 @@
    * <P>
    * This particular class, along with DocumentImpl, supports the DOM
    * Core, DOM Level 2 optional mofules, and Abstract Schemas (Experimental). 
  - * @version $Id: ASDOMImplementationImpl.java,v 1.1 2002/03/28 21:17:30 elena Exp $
  + * @version $Id: ASDOMImplementationImpl.java,v 1.2 2002/04/03 23:48:26 elena Exp $
    * @since PR-DOM-Level-1-19980818.
    */
   public class ASDOMImplementationImpl extends DOMImplementationImpl 
       implements DOMImplementationAS {
   
   
  +    // static
  +
  +    /** Dom implementation singleton. */
  +    static ASDOMImplementationImpl singleton = new ASDOMImplementationImpl();
  +
  +
  +    //
  +    // Public methods
  +    //
  +
  +    /** NON-DOM: Obtain and return the single shared object */
  +    public static DOMImplementation getDOMImplementation() {
  +        return singleton;
  +    }  
   
       //
       // DOM L3 Abstract Schemas:
  
  
  
  1.25      +33 -3     xml-xerces/java/src/org/apache/xerces/dom/AttrNSImpl.java
  
  Index: AttrNSImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrNSImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- AttrNSImpl.java	14 Feb 2002 16:34:29 -0000	1.24
  +++ AttrNSImpl.java	3 Apr 2002 23:48:26 -0000	1.25
  @@ -1,4 +1,4 @@
  -/* $Id: AttrNSImpl.java,v 1.24 2002/02/14 16:34:29 sandygao Exp $ */
  +/* $Id: AttrNSImpl.java,v 1.25 2002/04/03 23:48:26 elena Exp $ */
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -91,7 +91,13 @@
     
       /** DOM2: localName. */
       protected String localName;
  -    /**
  +
  +    /*
  +     * Default constructor
  +     */
  +    public AttrNSImpl(){}
  +        
  +   /**
        * DOM2: Constructor for Namespace implementation.
        */
       protected AttrNSImpl(CoreDocumentImpl ownerDocument, 
  @@ -144,7 +150,7 @@
       } 
   
       // when local name is known
  -    protected AttrNSImpl(CoreDocumentImpl ownerDocument, 
  +    public AttrNSImpl(CoreDocumentImpl ownerDocument, 
                            String namespaceURI, 
                            String qualifiedName,
                            String localName) {
  @@ -158,6 +164,30 @@
       protected AttrNSImpl(CoreDocumentImpl ownerDocument, 
                            String value) {
           super(ownerDocument, value);
  +    }
  +
  +    /**
  +     * NON-DOM: resets this node and sets specified values for the node
  +     * 
  +     * @param ownerDocument
  +     * @param namespaceURI
  +     * @param qualifiedName
  +     * @param localName
  +     */
  +    public void setValues (CoreDocumentImpl ownerDocument, 
  +                         String namespaceURI, 
  +                         String qualifiedName,
  +                         String localName){
  +
  +        super.textNode = null;
  +        super.flags = 0;
  +        isSpecified(true);
  +        hasStringValue(true);
  +        super.setOwnerDocument(ownerDocument);
  +        this.localName = localName;
  +        this.namespaceURI = namespaceURI;
  +        super.name = qualifiedName;
  +        super.value = null;
       }
   
       //
  
  
  
  1.17      +3 -1      xml-xerces/java/src/org/apache/xerces/dom/CharacterDataImpl.java
  
  Index: CharacterDataImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CharacterDataImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CharacterDataImpl.java	29 Jan 2002 01:15:07 -0000	1.16
  +++ CharacterDataImpl.java	3 Apr 2002 23:48:26 -0000	1.17
  @@ -74,7 +74,7 @@
    * This class doesn't directly support mutation events, however, it notifies
    * the document when mutations are performed so that the document class do so.
    *
  - * @version $Id: CharacterDataImpl.java,v 1.16 2002/01/29 01:15:07 lehors Exp $
  + * @version $Id: CharacterDataImpl.java,v 1.17 2002/04/03 23:48:26 elena Exp $
    * @since  PR-DOM-Level-1-19980818.
    */
   public abstract class CharacterDataImpl
  @@ -102,6 +102,8 @@
       //
       // Constructors
       //
  +
  +    public CharacterDataImpl(){}
   
       /** Factory constructor. */
       protected CharacterDataImpl(CoreDocumentImpl ownerDocument, String data) {
  
  
  
  1.6       +12 -11    xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java
  
  Index: CoreDOMImplementationImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDOMImplementationImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CoreDOMImplementationImpl.java	28 Mar 2002 21:17:30 -0000	1.5
  +++ CoreDOMImplementationImpl.java	3 Apr 2002 23:48:26 -0000	1.6
  @@ -84,7 +84,7 @@
    * This particular class, along with CoreDocumentImpl, supports the DOM
    * Core and Load/Save (Experimental). Optional modules are supported by 
    * the more complete DOMImplementation class along with DocumentImpl.
  - * @version $Id: CoreDOMImplementationImpl.java,v 1.5 2002/03/28 21:17:30 elena Exp $
  + * @version $Id: CoreDOMImplementationImpl.java,v 1.6 2002/04/03 23:48:26 elena Exp $
    * @since PR-DOM-Level-1-19980818.
    */
   public class CoreDOMImplementationImpl  
  @@ -97,8 +97,17 @@
       // static
   
       /** Dom implementation singleton. */
  -    static CoreDOMImplementationImpl singleton =
  -    new CoreDOMImplementationImpl();
  +    static CoreDOMImplementationImpl singleton = new CoreDOMImplementationImpl();
  +
  +
  +    //
  +    // Public methods
  +    //
  +
  +    /** NON-DOM: Obtain and return the single shared object */
  +    public static DOMImplementation getDOMImplementation() {
  +        return singleton;
  +    }  
   
       //
       // DOMImplementation methods
  @@ -139,14 +148,6 @@
   
       } // hasFeature(String,String):boolean
   
  -    //
  -    // Public methods
  -    //
  -
  -    /** NON-DOM: Obtain and return the single shared object */
  -    public static DOMImplementation getDOMImplementation() {
  -        return singleton;
  -    }  
   
       /**
        * Introduced in DOM Level 2. <p>
  
  
  
  1.23      +12 -10    xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationImpl.java
  
  Index: DOMImplementationImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMImplementationImpl.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- DOMImplementationImpl.java	28 Mar 2002 21:17:30 -0000	1.22
  +++ DOMImplementationImpl.java	3 Apr 2002 23:48:26 -0000	1.23
  @@ -74,10 +74,10 @@
    * methods. However, there's nothing that says it can't be a singleton,
    * so that's how I've implemented it.
    *
  - * @version $Id: DOMImplementationImpl.java,v 1.22 2002/03/28 21:17:30 elena Exp $
  + * @version $Id: DOMImplementationImpl.java,v 1.23 2002/04/03 23:48:26 elena Exp $
    * @since  PR-DOM-Level-1-19980818.
    */
  -public class DOMImplementationImpl  
  +public class DOMImplementationImpl extends CoreDOMImplementationImpl 
       implements DOMImplementation {
   
       //
  @@ -89,6 +89,16 @@
       /** Dom implementation singleton. */
       static DOMImplementationImpl singleton = new DOMImplementationImpl();
   
  +
  +    //
  +    // Public methods
  +    //
  +
  +    /** NON-DOM: Obtain and return the single shared object */
  +    public static DOMImplementation getDOMImplementation() {
  +        return singleton;
  +    }  
  +
       //
       // DOMImplementation methods
       //
  @@ -137,14 +147,6 @@
   
       } // hasFeature(String,String):boolean
   
  -    //
  -    // Public methods
  -    //
  -
  -    /** NON-DOM: Obtain and return the single shared object */
  -    public static DOMImplementation getDOMImplementation() {
  -        return singleton;
  -    }  
       
       /**
        * Introduced in DOM Level 2. <p>
  
  
  
  1.20      +37 -2     xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java
  
  Index: ElementNSImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ElementNSImpl.java	14 Feb 2002 16:34:29 -0000	1.19
  +++ ElementNSImpl.java	3 Apr 2002 23:48:26 -0000	1.20
  @@ -1,4 +1,4 @@
  -/* $Id: ElementNSImpl.java,v 1.19 2002/02/14 16:34:29 sandygao Exp $ */
  +/* $Id: ElementNSImpl.java,v 1.20 2002/04/03 23:48:26 elena Exp $ */
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -89,7 +89,9 @@
       /** DOM2: localName. */
       protected String localName;
   
  -
  +    protected ElementNSImpl() {
  +        super();
  +    }
       /**
        * DOM2: Constructor for Namespace implementation.
        */
  @@ -149,10 +151,42 @@
           super(ownerDocument, value);
       }
   
  +    /**
  +     * NON-DOM: resets this node and sets specified values for the node
  +     * 
  +     * @param ownerDocument
  +     * @param namespaceURI
  +     * @param qualifiedName
  +     * @param localName
  +     */
  +    protected void setValues (CoreDocumentImpl ownerDocument, 
  +                            String namespaceURI, String qualifiedName,
  +                            String localName){
  +        
  +        // remove children first
  +        firstChild = null;
  +        previousSibling = null;
  +        nextSibling = null;
  +        fNodeListCache = null;
  +        
  +        // set owner document
  +        attributes = null;
  +        super.flags = 0;
  +        setOwnerDocument(ownerDocument);
  +
  +        // synchronizeData will initialize attributes
  +        needsSyncData(true);    
  +        super.name = qualifiedName;
  +        this.localName = localName;
  +        this.namespaceURI = namespaceURI;
  +
  +    }
  +
       //
       // Node methods
       //
   
  +
       
       //
       //DOM2: Namespace methods.
  @@ -191,6 +225,7 @@
        */
       public String getPrefix()
       {
  +        
           if (needsSyncData()) {
               synchronizeData();
           }
  
  
  
  1.15      +19 -2     xml-xerces/java/src/org/apache/xerces/dom/TextImpl.java
  
  Index: TextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/TextImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TextImpl.java	19 Mar 2002 19:44:12 -0000	1.14
  +++ TextImpl.java	3 Apr 2002 23:48:26 -0000	1.15
  @@ -75,7 +75,7 @@
    * valid, since they're really just two different ways of quoting
    * characters when they're written out as part of an XML stream.
    *
  - * @version $Id: TextImpl.java,v 1.14 2002/03/19 19:44:12 elena Exp $
  + * @version $Id: TextImpl.java,v 1.15 2002/04/03 23:48:26 elena Exp $
    * @since  PR-DOM-Level-1-19980818.
    */
   public class TextImpl 
  @@ -93,11 +93,28 @@
       // Constructors
       //
   
  +    /** Default constructor */
  +    public TextImpl(){}
  +
       /** Factory constructor. */
       public TextImpl(CoreDocumentImpl ownerDoc, String data) {
           super(ownerDoc, data);
  -    }  
  +    }
       
  +    /**
  +     * NON-DOM: resets node and sets specified values for the current node
  +     * 
  +     * @param ownerDoc
  +     * @param data
  +     */
  +    public void setValues(CoreDocumentImpl ownerDoc, String data){
  +
  +        flags=0;
  +        nextSibling = null;
  +        previousSibling=null;
  +        setOwnerDocument(ownerDoc);
  +        super.data = data;
  +    }
       //
       // Node methods
       //
  
  
  
  1.4       +24 -1     xml-xerces/java/src/org/apache/xerces/impl/dv/xs/SchemaDVFactoryImpl.java
  
  Index: SchemaDVFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/SchemaDVFactoryImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SchemaDVFactoryImpl.java	19 Mar 2002 15:49:11 -0000	1.3
  +++ SchemaDVFactoryImpl.java	3 Apr 2002 23:48:26 -0000	1.4
  @@ -63,6 +63,8 @@
   import org.apache.xerces.impl.dv.XSListSimpleType;
   import org.apache.xerces.impl.dv.XSUnionSimpleType;
   import org.apache.xerces.impl.dv.XSFacets;
  +
  +import org.apache.xerces.impl.xs.XSDeclarationPool;
   import java.util.Hashtable;
   
   /**
  @@ -71,7 +73,7 @@
    * @author Neeraj Bajaj, Sun Microsystems, inc.
    * @author Sandy Gao, IBM
    *
  - * @version $Id: SchemaDVFactoryImpl.java,v 1.3 2002/03/19 15:49:11 sandygao Exp $
  + * @version $Id: SchemaDVFactoryImpl.java,v 1.4 2002/04/03 23:48:26 elena Exp $
    */
   public class SchemaDVFactoryImpl extends SchemaDVFactory {
   
  @@ -79,6 +81,8 @@
   
       static Hashtable fBuiltInTypes = null;
   
  +    protected XSDeclarationPool fDeclPool = null;
  +
       /**
        * Get a built-in simple type of the given name
        * REVISIT: its still not decided within the Schema WG how to define the
  @@ -118,6 +122,11 @@
        */
       public XSSimpleType createTypeRestriction(String name, String targetNamespace,
                                                 short finalSet, XSSimpleType base) {
  +        
  +        if (fDeclPool != null) {
  +           XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl();
  +           return st.setRestrictionValues((XSSimpleTypeDecl)base, name, targetNamespace, finalSet);
  +        }
           return new XSSimpleTypeDecl((XSSimpleTypeDecl)base, name, targetNamespace, finalSet);
       }
   
  @@ -134,6 +143,11 @@
       public XSListSimpleType createTypeList(String name, String targetNamespace,
                                              short finalSet, XSSimpleType itemType) {
           prepareBuiltInTypes();
  +
  +        if (fDeclPool != null) {
  +           XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl();
  +           return st.setListValues(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType);
  +        }
           return new XSSimpleTypeDecl(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType);
       }
   
  @@ -153,6 +167,11 @@
           int typeNum = memberTypes.length;
           XSSimpleTypeDecl[] mtypes = new XSSimpleTypeDecl[typeNum];
           System.arraycopy(memberTypes, 0, mtypes, 0, typeNum);
  +
  +        if (fDeclPool != null) {
  +           XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl();
  +           return st.setUnionValues(name, targetNamespace, finalSet, mtypes);
  +        }
           return new XSSimpleTypeDecl(name, targetNamespace, finalSet, mtypes);
       }
   
  @@ -381,5 +400,9 @@
   
           fBuiltInTypes = types;
       }//createBuiltInTypes()
  +
  +    public void setDeclPool (XSDeclarationPool declPool){
  +        fDeclPool = declPool;
  +    }
   
   }//SchemaDVFactory
  
  
  
  1.7       +123 -1    xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
  
  Index: XSSimpleTypeDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSSimpleTypeDecl.java	21 Mar 2002 20:53:17 -0000	1.6
  +++ XSSimpleTypeDecl.java	3 Apr 2002 23:48:26 -0000	1.7
  @@ -80,7 +80,7 @@
    * @author Sandy Gao, IBM
    * @author Neeraj Bajaj, Sun Microsystems, inc.
    *
  - * @version $Id: XSSimpleTypeDecl.java,v 1.6 2002/03/21 20:53:17 sandygao Exp $
  + * @version $Id: XSSimpleTypeDecl.java,v 1.7 2002/04/03 23:48:26 elena Exp $
    */
   public class XSSimpleTypeDecl implements XSAtomicSimpleType, XSListSimpleType, XSUnionSimpleType {
   
  @@ -186,6 +186,9 @@
       private short fCardinality;
       private boolean fBounded;
       private boolean fNumeric;
  +    
  +    // default constructor
  +    public XSSimpleTypeDecl(){}
   
       //Create a new built-in primitive types (and id/idref/entity)
       protected XSSimpleTypeDecl(XSSimpleTypeDecl base, String name, short validateDV,
  @@ -287,6 +290,91 @@
           caclFundamentalFacets();
       }
   
  +    //set values for restriction.
  +    protected XSSimpleTypeDecl setRestrictionValues(XSSimpleTypeDecl base, String name, String uri, short finalSet) {
  +        fBase = base;
  +        fTypeName = name;
  +        fTargetNamespace = uri;
  +        fFinalSet = finalSet;
  +
  +        fVariety = fBase.fVariety;
  +        fValidationDV = fBase.fValidationDV;
  +        switch (fVariety) {
  +        case VARIETY_ATOMIC:
  +            break;
  +        case VARIETY_LIST:
  +            fItemType = fBase.fItemType;
  +            break;
  +        case VARIETY_UNION:
  +            fMemberTypes = fBase.fMemberTypes;
  +            break;
  +        }
  +
  +        // always inherit facets from the base.
  +        // in case a type is created, but applyFacets is not called
  +        fLength = fBase.fLength;
  +        fMinLength = fBase.fMinLength;
  +        fMaxLength = fBase.fMaxLength;
  +        fPattern = fBase.fPattern;
  +        fEnumeration = fBase.fEnumeration;
  +        fWhiteSpace = fBase.fWhiteSpace;
  +        fMaxExclusive = fBase.fMaxExclusive;
  +        fMaxInclusive = fBase.fMaxInclusive;
  +        fMinExclusive = fBase.fMinExclusive;
  +        fMinInclusive = fBase.fMinInclusive;
  +        fTotalDigits = fBase.fTotalDigits;
  +        fFractionDigits = fBase.fFractionDigits;
  +        fTokenType = fBase.fTokenType;
  +        fFixedFacet = fBase.fFixedFacet;
  +        fFacetsDefined = fBase.fFacetsDefined;
  +
  +        //we also set fundamental facets information in case applyFacets is not called.
  +        caclFundamentalFacets();
  +        return this;
  +    }
  +
  +    //set values for list.
  +    protected XSSimpleTypeDecl setListValues(String name, String uri, short finalSet, XSSimpleTypeDecl itemType) {
  +        fBase = fAnySimpleType;
  +        fTypeName = name;
  +        fTargetNamespace = uri;
  +        fFinalSet = finalSet;
  +
  +        fVariety = VARIETY_LIST;
  +        fItemType = (XSSimpleTypeDecl)itemType;
  +        fValidationDV = DV_LIST;
  +        fFacetsDefined = FACET_WHITESPACE;
  +        fFixedFacet = FACET_WHITESPACE;
  +        fWhiteSpace = WS_COLLAPSE;
  +
  +        //setting fundamental facets
  +        caclFundamentalFacets();
  +        return this;
  +    }
  +
  +    //set values for union.
  +    protected XSSimpleTypeDecl setUnionValues(String name, String uri, short finalSet, XSSimpleTypeDecl[] memberTypes) {
  +        fBase = fAnySimpleType;
  +        fTypeName = name;
  +        fTargetNamespace = uri;
  +        fFinalSet = finalSet;
  +
  +        fVariety = VARIETY_UNION;
  +        fMemberTypes = memberTypes;
  +        fValidationDV = DV_UNION;
  +        // even for union, we set whitespace to something
  +        // this will never be used, but we can use fFacetsDefined to check
  +        // whether applyFacets() is allwwed: it's not allowed
  +        // if fFacetsDefined != 0
  +        fFacetsDefined = FACET_WHITESPACE;
  +        fWhiteSpace = WS_COLLAPSE;
  +
  +        //setting fundamental facets
  +        caclFundamentalFacets();
  +        return this;
  +    }
  +
  +
       public short getXSType () {
           return XSTypeDecl.SIMPLE_TYPE;
       }
  @@ -1800,5 +1888,39 @@
               else
                   return fNSContext.getURI(prefix);
           }
  +    }
  +
  +    public void reset(){
  +
  +        fItemType = null;
  +        fMemberTypes = null;
  +
  +        fTypeName = null;
  +        fTargetNamespace = null;
  +        fFinalSet = 0;
  +        fBase = null;
  +        fVariety = -1;
  +        fValidationDV = -1;
  +
  +        fFacetsDefined = 0;
  +        fFixedFacet = 0;
  +
  +        //for constraining facets
  +        fWhiteSpace = 0;
  +        fLength = -1;
  +        fMinLength = -1;
  +        fMaxLength = -1;
  +        fTotalDigits = -1;
  +        fFractionDigits = -1;
  +        fPattern = null;
  +        fEnumeration = null;
  +        fMaxInclusive = null;
  +        fMaxExclusive = null;
  +        fMinExclusive = null;
  +        fMinInclusive = null;
  +
  +        fTokenType = SPECIAL_TOKEN_NONE;
  +
  +        // REVISIT: reset for fundamental facets
       }
   } // class XSComplexTypeDecl
  
  
  
  1.51      +15 -3     xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
  
  Index: XMLSchemaValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- XMLSchemaValidator.java	3 Apr 2002 15:09:11 -0000	1.50
  +++ XMLSchemaValidator.java	3 Apr 2002 23:48:26 -0000	1.51
  @@ -141,7 +141,7 @@
    * @author Elena Litani IBM
    * @author Andy Clark IBM
    * @author Neeraj Bajaj, Sun Microsystems, inc.
  - * @version $Id: XMLSchemaValidator.java,v 1.50 2002/04/03 15:09:11 neilg Exp $
  + * @version $Id: XMLSchemaValidator.java,v 1.51 2002/04/03 23:48:26 elena Exp $
    */
   public class XMLSchemaValidator
                implements XMLComponent, XMLDocumentFilter, FieldActivator {
  @@ -280,6 +280,7 @@
   
       /** Symbol table. */
       protected SymbolTable fSymbolTable;
  +    protected final XSDeclarationPool fDeclPool = new XSDeclarationPool();
   
       /**
        * A wrapper of the standard error reporter. We'll store all schema errors
  @@ -1212,6 +1213,16 @@
                                fEntityResolver, fSymbolTable,
                                fExternalSchemas, fExternalNoNamespaceSchema,
                                fGrammarPool);
  +        
  +        // register declaration pool
  +        fDeclPool.reset();
  +        if (fGrammarPool == null) {
  +            fCMBuilder.setDeclPool(fDeclPool);
  +            fSchemaHandler.setDeclPool(fDeclPool);
  +        } else {
  +            fCMBuilder.setDeclPool(null);
  +            fSchemaHandler.setDeclPool(null);
  +        } 
   
           //reset XSDDescripton
           fXSDDescription.reset() ;
  @@ -2446,7 +2457,7 @@
           }
   
           XSAttributeUse attrUses[] = attrGrp.getAttributeUses();
  -        int useCount = attrUses.length;
  +        int useCount = (attrUses!=null)? attrUses.length:0;
           XSWildcardDecl attrWildcard = attrGrp.fAttributeWC;
   
           // whether we have seen a Wildcard ID.
  @@ -2485,6 +2496,7 @@
               // it's not xmlns, and not xsi, then we need to find a decl for it
               XSAttributeUse currUse = null;
               for (int i = 0; i < useCount; i++) {
  +
                   if (attrUses[i].fAttrDecl.fName == fTempQName.localpart &&
                       attrUses[i].fAttrDecl.fTargetNamespace == fTempQName.uri) {
                       currUse = attrUses[i];
  @@ -2664,7 +2676,7 @@
               System.out.println("addDefaultAttributes: " + element);
           }
           XSAttributeUse attrUses[] = attrGrp.getAttributeUses();
  -        int useCount = attrUses.length;
  +        int useCount = (attrUses!=null)? attrUses.length:0;
           XSAttributeUse currUse;
           XSAttributeDecl currDecl;
           short constType;
  
  
  
  1.6       +11 -3     xml-xerces/java/src/org/apache/xerces/impl/xs/XSAttributeDecl.java
  
  Index: XSAttributeDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSAttributeDecl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XSAttributeDecl.java	29 Jan 2002 01:15:14 -0000	1.5
  +++ XSAttributeDecl.java	3 Apr 2002 23:48:26 -0000	1.6
  @@ -66,7 +66,7 @@
    *
    * @author Elena Litani, IBM
    * @author Sandy Gao, IBM
  - * @version $Id: XSAttributeDecl.java,v 1.5 2002/01/29 01:15:14 lehors Exp $
  + * @version $Id: XSAttributeDecl.java,v 1.6 2002/04/03 23:48:26 elena Exp $
    */
   public class XSAttributeDecl {
   
  @@ -92,10 +92,10 @@
       // methods to get/set misc flag
   
       public short getConstraintType() {
  -        return (short)(fMiscFlags & CONSTRAINT_MASK);
  +        return(short)(fMiscFlags & CONSTRAINT_MASK);
       }
       public boolean isGlobal() {
  -        return ((fMiscFlags & GLOBAL) != 0);
  +        return((fMiscFlags & GLOBAL) != 0);
       }
   
       public void setConstraintType(short constraintType) {
  @@ -106,6 +106,14 @@
       }
       public void setIsGlobal() {
           fMiscFlags |= GLOBAL;
  +    }
  +
  +    public void reset(){
  +        fName = null;
  +        fTargetNamespace = null;
  +        fType = null;
  +        fMiscFlags = 0;
  +        fDefault = null;
       }
   
   } // class XSAttributeDecl
  
  
  
  1.7       +108 -93   xml-xerces/java/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java
  
  Index: XSAttributeGroupDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSAttributeGroupDecl.java	15 Mar 2002 23:01:57 -0000	1.6
  +++ XSAttributeGroupDecl.java	3 Apr 2002 23:48:26 -0000	1.7
  @@ -66,7 +66,7 @@
    * @author Sandy Gao, IBM
    * @author Rahul Srivastava, Sun Microsystems Inc.
    *
  - * @version $Id: XSAttributeGroupDecl.java,v 1.6 2002/03/15 23:01:57 sandygao Exp $
  + * @version $Id: XSAttributeGroupDecl.java,v 1.7 2002/04/03 23:48:26 elena Exp $
    */
   public class XSAttributeGroupDecl {
   
  @@ -89,11 +89,11 @@
       // use of type ID, then return the name of the other attribute use;
       // otherwise, return null
       public String addAttributeUse(XSAttributeUse 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)
  @@ -152,15 +152,18 @@
       }
   
       public XSAttributeUse[] getAttributeUses() {
  +        if (fAttrUseNum == 0) {
  +            return null;
  +        }
           if (fAttrUseNum < fAttributeUses.length) {
               fAttributeUses = resize(fAttributeUses, fAttrUseNum);
           }
           return fAttributeUses;
       }
   
  -   // Check that the attributes in this group validly restrict those from a base group
  -   // If an error is found, the error code is returned.
  -   public String validRestrictionOf(XSAttributeGroupDecl baseGroup) {
  +    // Check that the attributes in this group validly restrict those from a base group
  +    // If an error is found, the error code is returned.
  +    public String validRestrictionOf(XSAttributeGroupDecl baseGroup) {
   
           String errorCode = null;
           XSAttributeUse attrUse = null;
  @@ -170,84 +173,82 @@
   
           for (int i=0; i<fAttrUseNum; i++) {
   
  -           attrUse = fAttributeUses[i];
  -           attrDecl = attrUse.fAttrDecl;
  +            attrUse = fAttributeUses[i];
  +            attrDecl = attrUse.fAttrDecl;
   
  -           // Look for a match in the base
  -           baseAttrUse = baseGroup.getAttributeUse(
  -                                    attrDecl.fTargetNamespace,attrDecl.fName);
  -           if (baseAttrUse != null) {
  -             //
  -             // derivation-ok-restriction.  Constraint 2.1.1
  -             //
  -
  -             if (baseAttrUse.fUse == SchemaSymbols.USE_REQUIRED &&
  -                 attrUse.fUse != SchemaSymbols.USE_REQUIRED) {
  -               errorCode = "derivation-ok-restriction.2.1.1";
  -               return errorCode;
  -             }
  -
  -             // if this attribute is prohibited in the derived type, don't
  -             // need to check any of the following constraints.
  -             if (attrUse.fUse == SchemaSymbols.USE_PROHIBITED) {
  -                continue;
  -             }
  -             
  -             baseAttrDecl = baseAttrUse.fAttrDecl;
  -             //
  -             // derivation-ok-restriction.  Constraint 2.1.1
  -             //
  -             if (! XSConstraints.checkSimpleDerivationOk(attrDecl.fType,
  -                                           baseAttrDecl.fType,
  -                                           baseAttrDecl.fType.getFinalSet()) ) {
  -                errorCode="derivation-ok-restriction.2.1.2";
  -                return errorCode;
  -             }
  +            // Look for a match in the base
  +            baseAttrUse = baseGroup.getAttributeUse(
  +                                                   attrDecl.fTargetNamespace,attrDecl.fName);
  +            if (baseAttrUse != null) {
  +                //
  +                // derivation-ok-restriction.  Constraint 2.1.1
  +                //
  +
  +                if (baseAttrUse.fUse == SchemaSymbols.USE_REQUIRED &&
  +                    attrUse.fUse != SchemaSymbols.USE_REQUIRED) {
  +                    errorCode = "derivation-ok-restriction.2.1.1";
  +                    return errorCode;
  +                }
   
  +                // if this attribute is prohibited in the derived type, don't
  +                // need to check any of the following constraints.
  +                if (attrUse.fUse == SchemaSymbols.USE_PROHIBITED) {
  +                    continue;
  +                }
   
  -             //
  -             // derivation-ok-restriction.  Constraint 2.1.3
  -             //
  -             int baseConsType=baseAttrUse.fConstraintType!=XSAttributeDecl.NO_CONSTRAINT?
  +                baseAttrDecl = baseAttrUse.fAttrDecl;
  +                //
  +                // derivation-ok-restriction.  Constraint 2.1.1
  +                //
  +                if (! XSConstraints.checkSimpleDerivationOk(attrDecl.fType,
  +                                                            baseAttrDecl.fType,
  +                                                            baseAttrDecl.fType.getFinalSet()) ) {
  +                    errorCode="derivation-ok-restriction.2.1.2";
  +                    return errorCode;
  +                }
  +
  +
  +                //
  +                // derivation-ok-restriction.  Constraint 2.1.3
  +                //
  +                int baseConsType=baseAttrUse.fConstraintType!=XSAttributeDecl.NO_CONSTRAINT?
                                    baseAttrUse.fConstraintType:baseAttrDecl.getConstraintType();
  -             int thisConstType = attrUse.fConstraintType!=XSAttributeDecl.NO_CONSTRAINT?
  -                                 attrUse.fConstraintType:attrDecl.getConstraintType();
  +                int thisConstType = attrUse.fConstraintType!=XSAttributeDecl.NO_CONSTRAINT?
  +                                    attrUse.fConstraintType:attrDecl.getConstraintType();
   
  -             if (baseConsType == XSAttributeDecl.FIXED_VALUE) {
  +                if (baseConsType == XSAttributeDecl.FIXED_VALUE) {
   
  -                if (thisConstType != XSAttributeDecl.FIXED_VALUE) {
  -                    errorCode="derivation-ok-restriction.2.1.3";
  -                    return errorCode;
  -                }
  -                else {
  -                    // check the values are the same.
  -                    ValidatedInfo baseFixedValue=(baseAttrUse.fDefault!=null ?
  -                                                 baseAttrUse.fDefault: baseAttrDecl.fDefault);
  -                    ValidatedInfo thisFixedValue=(attrUse.fDefault!=null ?
  -                                                 attrUse.fDefault: attrDecl.fDefault);
  -                    if (!baseAttrDecl.fType.isEqual(baseFixedValue.actualValue,thisFixedValue.actualValue)) {
  +                    if (thisConstType != XSAttributeDecl.FIXED_VALUE) {
                           errorCode="derivation-ok-restriction.2.1.3";
                           return errorCode;
  -                   }
  +                    } else {
  +                        // check the values are the same.
  +                        ValidatedInfo baseFixedValue=(baseAttrUse.fDefault!=null ?
  +                                                      baseAttrUse.fDefault: baseAttrDecl.fDefault);
  +                        ValidatedInfo thisFixedValue=(attrUse.fDefault!=null ?
  +                                                      attrUse.fDefault: attrDecl.fDefault);
  +                        if (!baseAttrDecl.fType.isEqual(baseFixedValue.actualValue,thisFixedValue.actualValue)) {
  +                            errorCode="derivation-ok-restriction.2.1.3";
  +                            return errorCode;
  +                        }
  +
  +                    }
   
  -                 }
  +                }
  +            } else {
  +                // No matching attribute in base - there should be a matching wildcard
  +
  +
  +                //
  +                // derivation-ok-restriction.  Constraint 2.2
  +                //
  +                if (baseGroup.fAttributeWC == null ||
  +                    (!baseGroup.fAttributeWC.allowNamespace(attrDecl.fTargetNamespace))) {
   
  -             }
  -           }
  -           else {
  -             // No matching attribute in base - there should be a matching wildcard
  -
  -
  -             //
  -             // derivation-ok-restriction.  Constraint 2.2
  -             //
  -             if (baseGroup.fAttributeWC == null ||
  -                 (!baseGroup.fAttributeWC.allowNamespace(attrDecl.fTargetNamespace))) {
  -
  -               errorCode = "derivation-ok-restriction.2.2";
  -               return errorCode;
  -             }
  -           }
  +                    errorCode = "derivation-ok-restriction.2.2";
  +                    return errorCode;
  +                }
  +            }
           }
   
           //
  @@ -257,19 +258,19 @@
           //
           for (int i=0; i<baseGroup.fAttrUseNum; i++) {
   
  -           baseAttrUse = baseGroup.fAttributeUses[i];
  +            baseAttrUse = baseGroup.fAttributeUses[i];
   
  -           if (baseAttrUse.fUse == SchemaSymbols.USE_REQUIRED) {
  +            if (baseAttrUse.fUse == SchemaSymbols.USE_REQUIRED) {
   
  -             baseAttrDecl = baseAttrUse.fAttrDecl;
  -             // Look for a match in this group
  -             XSAttributeUse thisAttrUse = getAttributeUse(
  -                                    baseAttrDecl.fTargetNamespace,baseAttrDecl.fName);
  -             if (thisAttrUse == null) {
  -               errorCode = "derivation-ok-restriction.3";
  -               return errorCode;
  -             }
  -           }
  +                baseAttrDecl = baseAttrUse.fAttrDecl;
  +                // Look for a match in this group
  +                XSAttributeUse thisAttrUse = getAttributeUse(
  +                                                            baseAttrDecl.fTargetNamespace,baseAttrDecl.fName);
  +                if (thisAttrUse == null) {
  +                    errorCode = "derivation-ok-restriction.3";
  +                    return errorCode;
  +                }
  +            }
           }
   
   
  @@ -278,24 +279,38 @@
           // derivation-ok-restriction.  Constraint 4
           //
           if (fAttributeWC != null) {
  -          if (baseGroup.fAttributeWC == null) {
  -            errorCode = "derivation-ok-restriction.4";
  -            return errorCode;
  -          }
  -          if (! fAttributeWC.isSubsetOf(baseGroup.fAttributeWC)) {
  -            errorCode="derivation-ok-restriction.4";
  -            return errorCode;
  -          }
  +            if (baseGroup.fAttributeWC == null) {
  +                errorCode = "derivation-ok-restriction.4";
  +                return errorCode;
  +            }
  +            if (! fAttributeWC.isSubsetOf(baseGroup.fAttributeWC)) {
  +                errorCode="derivation-ok-restriction.4";
  +                return errorCode;
  +            }
           }
   
           return null;
   
  -   }
  +    }
   
       static final XSAttributeUse[] resize(XSAttributeUse[] oldArray, int newSize) {
           XSAttributeUse[] newArray = new XSAttributeUse[newSize];
           System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
           return newArray;
  +    }
  +
  +    // reset the attribute group declaration
  +    public void reset(){
  +        fName = null;
  +        fTargetNamespace = null;
  +        // reset attribute uses
  +        for (int i=0;i<fAttrUseNum;i++) {
  +            fAttributeUses[i] = null;
  +        } 
  +        fAttrUseNum = 0;
  +        fAttributeWC = null;
  +        fIDAttrName = null;
  +
       }
   
   } // class XSAttributeGroupDecl
  
  
  
  1.4       +8 -1      xml-xerces/java/src/org/apache/xerces/impl/xs/XSAttributeUse.java
  
  Index: XSAttributeUse.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSAttributeUse.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XSAttributeUse.java	29 Jan 2002 01:15:14 -0000	1.3
  +++ XSAttributeUse.java	3 Apr 2002 23:48:26 -0000	1.4
  @@ -64,7 +64,7 @@
    * schema component is a local <attribute> element information item
    *
    * @author Sandy Gao, IBM
  - * @version $Id: XSAttributeUse.java,v 1.3 2002/01/29 01:15:14 lehors Exp $
  + * @version $Id: XSAttributeUse.java,v 1.4 2002/04/03 23:48:26 elena Exp $
    */
   public class XSAttributeUse {
   
  @@ -76,5 +76,12 @@
       public short fConstraintType = XSAttributeDecl.NO_CONSTRAINT;
       // value constraint value
       public ValidatedInfo fDefault = null;
  +
  +    public void reset(){
  +        fDefault = null;
  +        fAttrDecl = null;
  +        fUse =  SchemaSymbols.USE_OPTIONAL;
  +        fConstraintType = XSAttributeDecl.NO_CONSTRAINT;
  +    }
   
   } // class XSAttributeUse
  
  
  
  1.7       +26 -8     xml-xerces/java/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java
  
  Index: XSComplexTypeDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSComplexTypeDecl.java	21 Mar 2002 20:53:45 -0000	1.6
  +++ XSComplexTypeDecl.java	3 Apr 2002 23:48:26 -0000	1.7
  @@ -67,7 +67,7 @@
    *
    * @author Elena Litani, IBM
    * @author Sandy Gao, IBM
  - * @version $Id: XSComplexTypeDecl.java,v 1.6 2002/03/21 20:53:45 sandygao Exp $
  + * @version $Id: XSComplexTypeDecl.java,v 1.7 2002/04/03 23:48:26 elena Exp $
    */
   public class XSComplexTypeDecl implements XSTypeDecl {
   
  @@ -142,13 +142,13 @@
       // methods to get/set misc flag
   
       public boolean isAbstractType() {
  -        return ((fMiscFlags & CT_IS_ABSTRACT) != 0);
  +        return((fMiscFlags & CT_IS_ABSTRACT) != 0);
       }
       public boolean containsTypeID () {
  -        return ((fMiscFlags & CT_HAS_TYPE_ID) != 0);
  +        return((fMiscFlags & CT_HAS_TYPE_ID) != 0);
       }
       public boolean isAnonymous() {
  -        return ((fMiscFlags & CT_IS_ANONYMOUS) != 0);
  +        return((fMiscFlags & CT_IS_ANONYMOUS) != 0);
       }
   
       public void setIsAbstractType() {
  @@ -182,7 +182,7 @@
   
           str.append("Complex type name='" + fTargetNamespace + "," + getTypeName() + "', ");
           if (fBaseType != null)
  -          str.append(" base type name='" + fBaseType.getTypeName() + "', ");
  +            str.append(" base type name='" + fBaseType.getTypeName() + "', ");
   
           str.append(" content type='" + contentType[fContentType] + "', ");
           str.append(" isAbstract='" + isAbstractType() + "', ");
  @@ -190,7 +190,7 @@
           str.append(" final='" + fFinal + "', ");
           str.append(" block='" + fBlock + "', ");
           if (fParticle != null)
  -          str.append(" particle='" + fParticle.toString() + "', ");
  +            str.append(" particle='" + fParticle.toString() + "', ");
           str.append(" derivedBy='" + derivedBy[fDerivedBy] + "'. ");
   
       }
  @@ -212,7 +212,7 @@
   
           return type == ancestor;
       }
  -    
  +
       public boolean derivedFrom(String ancestorNS, String ancestorName) {
           // ancestor is null, retur false
           if (ancestorName == null)
  @@ -235,7 +235,25 @@
           }
   
           return type != SchemaGrammar.fAnySimpleType &&
  -               type != SchemaGrammar.fAnyType;
  +        type != SchemaGrammar.fAnyType;
  +    }
  +
  +    public void reset(){
  +        fName = null;
  +        fTargetNamespace = null;
  +        fBaseType = null;
  +        fDerivedBy = SchemaSymbols.RESTRICTION;
  +        fFinal = SchemaSymbols.EMPTY_SET;
  +        fBlock = SchemaSymbols.EMPTY_SET;
  +
  +        fMiscFlags = 0;
  +
  +        // reset attribute group
  +        fAttrGrp.reset();
  +        fContentType = CONTENTTYPE_EMPTY;
  +        fXSSimpleType = null;
  +        fParticle = null;
  +        fCMValidator = null;
       }
   
   } // class XSComplexTypeDecl
  
  
  
  1.3       +232 -10   xml-xerces/java/src/org/apache/xerces/impl/xs/XSDeclarationPool.java
  
  Index: XSDeclarationPool.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSDeclarationPool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XSDeclarationPool.java	29 Jan 2002 01:15:14 -0000	1.2
  +++ XSDeclarationPool.java	3 Apr 2002 23:48:26 -0000	1.3
  @@ -57,6 +57,8 @@
   
   package org.apache.xerces.impl.xs;
   
  +import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
  +
   /**
    * This class is pool that enables caching of XML Schema declaration objects.
    * Before a compiled grammar object is garbage collected,
  @@ -65,37 +67,257 @@
    * Note: The cashing mechanism is not implemented yet.
    * 
    * @author Elena Litani, IBM
  - * @version $Id: XSDeclarationPool.java,v 1.2 2002/01/29 01:15:14 lehors Exp $
  + * @version $Id: XSDeclarationPool.java,v 1.3 2002/04/03 23:48:26 elena Exp $
    */
   public final class XSDeclarationPool {
  +    /** Chunk shift (8). */
  +    private static final int CHUNK_SHIFT = 8; // 2^8 = 256
   
  -    public final  XSElementDecl getElementDecl(){
  -        return new XSElementDecl();
  +    /** Chunk size (1 << CHUNK_SHIFT). */
  +    private static final int CHUNK_SIZE = 1 << CHUNK_SHIFT;
  +
  +    /** Chunk mask (CHUNK_SIZE - 1). */
  +    private static final int CHUNK_MASK = CHUNK_SIZE - 1;
  +
  +    /** Initial chunk count (). */
  +    private static final int INITIAL_CHUNK_COUNT = (1 << (10 - CHUNK_SHIFT)); // 2^10 = 1k
  +
  +    /** Element declaration pool*/
  +    private XSElementDecl fElementDecl[][] = new XSElementDecl[INITIAL_CHUNK_COUNT][];
  +    private int fElementDeclIndex = 0;
  +
  +    /** Particle declaration pool */
  +    private XSParticleDecl fParticleDecl[][] = new XSParticleDecl[INITIAL_CHUNK_COUNT][];
  +    private int fParticleDeclIndex = 0;
   
  +    /** Attribute declaration pool */
  +    private XSAttributeDecl fAttrDecl[][] = new XSAttributeDecl[INITIAL_CHUNK_COUNT][];
  +    private int fAttrDeclIndex = 0;
  +
  +    /** ComplexType declaration pool */
  +    private XSComplexTypeDecl fCTDecl[][] = new XSComplexTypeDecl[INITIAL_CHUNK_COUNT][];
  +    private int fCTDeclIndex = 0;
  +
  +    /** SimpleType declaration pool */
  +    private XSSimpleTypeDecl fSTDecl[][] = new XSSimpleTypeDecl[INITIAL_CHUNK_COUNT][];
  +    private int fSTDeclIndex = 0;
  +
  +    /** AttributeUse declaration pool */
  +    private XSAttributeUse fAttributeUse[][] = new XSAttributeUse[INITIAL_CHUNK_COUNT][];
  +    private int fAttributeUseIndex = 0;
  +
  +    public final  XSElementDecl getElementDecl(){
  +        int     chunk       = fElementDeclIndex >> CHUNK_SHIFT;
  +        int     index       = fElementDeclIndex &  CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (fElementDecl[chunk][index] == null) {
  +            fElementDecl[chunk][index] = new XSElementDecl();
  +        } else {
  +            fElementDecl[chunk][index].reset();
  +        }
  +        fElementDeclIndex++;
  +        return fElementDecl[chunk][index];
       }
   
       public final XSAttributeDecl getAttributeDecl(){
  -        return new XSAttributeDecl();
  +        int     chunk       = fAttrDeclIndex >> CHUNK_SHIFT;
  +        int     index       = fAttrDeclIndex &  CHUNK_MASK;
  +        ensureAttrDeclCapacity(chunk);
  +        if (fAttrDecl[chunk][index] == null) {
  +            fAttrDecl[chunk][index] = new XSAttributeDecl();
  +        } else {
  +            fAttrDecl[chunk][index].reset();
  +        }
  +        fAttrDeclIndex++;
  +        return fAttrDecl[chunk][index];
   
       }
   
       public final XSAttributeUse getAttributeUse(){
  -        return new XSAttributeUse();
  +        int     chunk       = fAttributeUseIndex >> CHUNK_SHIFT;
  +        int     index       = fAttributeUseIndex &  CHUNK_MASK;
  +        ensureAttributeUseCapacity(chunk);
  +        if (fAttributeUse[chunk][index] == null) {
  +            fAttributeUse[chunk][index] = new XSAttributeUse();
  +        } else {
  +            fAttributeUse[chunk][index].reset();
  +        }
  +        fAttributeUseIndex++;
  +        return fAttributeUse[chunk][index];
   
       }
       
       public final XSComplexTypeDecl getComplexTypeDecl(){
  -        return new XSComplexTypeDecl();
  -
  +        int     chunk       = fCTDeclIndex >> CHUNK_SHIFT;
  +        int     index       = fCTDeclIndex &  CHUNK_MASK;
  +        ensureCTDeclCapacity(chunk);
  +        if (fCTDecl[chunk][index] == null) {
  +
  +            fCTDecl[chunk][index] = new XSComplexTypeDecl();
  +        } else {
  +            fCTDecl[chunk][index].reset();
  +        }
  +        fCTDeclIndex++;
  +        return fCTDecl[chunk][index];
       }
   
  +    public final XSSimpleTypeDecl getSimpleTypeDecl(){
  +        int     chunk       = fSTDeclIndex >> CHUNK_SHIFT;
  +        int     index       = fSTDeclIndex &  CHUNK_MASK;
  +        ensureSTDeclCapacity(chunk);
  +        if (fSTDecl[chunk][index] == null) {
  +            fSTDecl[chunk][index] = new XSSimpleTypeDecl();
  +        } else {
  +            fSTDecl[chunk][index].reset();
  +        }
  +        fSTDeclIndex++;
  +        return fSTDecl[chunk][index];
  +
  +    } 
  +
       public final XSParticleDecl getParticleDecl(){
  -        return new XSParticleDecl();
  +        int     chunk       = fParticleDeclIndex >> CHUNK_SHIFT;
  +        int     index       = fParticleDeclIndex &  CHUNK_MASK;
  +        ensureParticleDeclCapacity(chunk);
  +        if (fParticleDecl[chunk][index] == null) {
  +            fParticleDecl[chunk][index] = new XSParticleDecl();
  +        } else {
  +            fParticleDecl[chunk][index].reset();
  +        }
  +        fParticleDeclIndex++;
  +        return fParticleDecl[chunk][index];
  +    }
  +
  +    // REVISIT: do we need decl pool for group declarations, attribute group,
  +    //          notations?
  +    //          it seems like each schema would use a small number of those
  +    //          components, so it probably is not worth keeping those components
  +    //          in the pool.
  +
  +    private boolean ensureElementDeclCapacity(int chunk) {
  +        try {
  +            return fElementDecl[chunk][0] == null;
  +        } catch (ArrayIndexOutOfBoundsException ex) {
  +            fElementDecl = resize(fElementDecl, fElementDecl.length * 2);
  +        } catch (NullPointerException ex) {
  +            // ignore
  +        }
  +
  +        fElementDecl[chunk] = new XSElementDecl[CHUNK_SIZE];
  +        return true;
  +    }
   
  +    private static XSElementDecl[][] resize(XSElementDecl array[][], int newsize) {
  +        XSElementDecl newarray[][] = new XSElementDecl[newsize][];
  +        System.arraycopy(array, 0, newarray, 0, array.length);
  +        return newarray;
       }
   
  -    // REVISIT: add method getSimpleTypeDecl
  +    private boolean ensureParticleDeclCapacity(int chunk) {
  +        try {
  +            return fParticleDecl[chunk][0] == null;
  +        } catch (ArrayIndexOutOfBoundsException ex) {
  +            fParticleDecl = resize(fParticleDecl, fParticleDecl.length * 2);
  +        } catch (NullPointerException ex) {
  +            // ignore
  +        }
  +
  +        fParticleDecl[chunk] = new XSParticleDecl[CHUNK_SIZE];
  +        return true;
  +    }
  +
  +    private static XSParticleDecl[][] resize(XSParticleDecl array[][], int newsize) {
  +        XSParticleDecl newarray[][] = new XSParticleDecl[newsize][];
  +        System.arraycopy(array, 0, newarray, 0, array.length);
  +        return newarray;
  +    }
  +
  +
  +    private boolean ensureAttrDeclCapacity(int chunk) {
  +        try {
  +            return fAttrDecl[chunk][0] == null;
  +        } catch (ArrayIndexOutOfBoundsException ex) {
  +            fAttrDecl = resize(fAttrDecl, fAttrDecl.length * 2);
  +        } catch (NullPointerException ex) {
  +            // ignore
  +        }
  +
  +        fAttrDecl[chunk] = new XSAttributeDecl[CHUNK_SIZE];
  +        return true;
  +    }
  +
  +    private static XSAttributeDecl[][] resize(XSAttributeDecl array[][], int newsize) {
  +        XSAttributeDecl newarray[][] = new XSAttributeDecl[newsize][];
  +        System.arraycopy(array, 0, newarray, 0, array.length);
  +        return newarray;
  +    }
  +
  +    private boolean ensureAttributeUseCapacity(int chunk) {
  +        try {
  +            return fAttributeUse[chunk][0] == null;
  +        } catch (ArrayIndexOutOfBoundsException ex) {
  +            fAttributeUse = resize(fAttributeUse, fAttributeUse.length * 2);
  +        } catch (NullPointerException ex) {
  +            // ignore
  +        }
  +
  +        fAttributeUse[chunk] = new XSAttributeUse[CHUNK_SIZE];
  +        return true;
  +    }
  +
  +    private static XSAttributeUse[][] resize(XSAttributeUse array[][], int newsize) {
  +        XSAttributeUse newarray[][] = new XSAttributeUse[newsize][];
  +        System.arraycopy(array, 0, newarray, 0, array.length);
  +        return newarray;
  +    }
  +
  +    private boolean ensureSTDeclCapacity(int chunk) {
  +        try {
  +            return fSTDecl[chunk][0] == null;
  +        } catch (ArrayIndexOutOfBoundsException ex) {
  +            fSTDecl = resize(fSTDecl, fSTDecl.length * 2);
  +        } catch (NullPointerException ex) {
  +            // ignore
  +        }
  +
  +        fSTDecl[chunk] = new XSSimpleTypeDecl[CHUNK_SIZE];
  +        return true;
  +    }
  +
  +    private static XSSimpleTypeDecl[][] resize(XSSimpleTypeDecl array[][], int newsize) {
  +        XSSimpleTypeDecl newarray[][] = new XSSimpleTypeDecl[newsize][];
  +        System.arraycopy(array, 0, newarray, 0, array.length);
  +        return newarray;
  +    }
  +
  +    private boolean ensureCTDeclCapacity(int chunk) {
  +        try {
  +            return fCTDecl[chunk][0] == null;
  +        } catch (ArrayIndexOutOfBoundsException ex) {
  +            fCTDecl = resize(fCTDecl, fCTDecl.length * 2);
  +        } catch (NullPointerException ex) {
  +            // ignore
  +        }
  +
  +        fCTDecl[chunk] = new XSComplexTypeDecl[CHUNK_SIZE];
  +        return true;
  +    }
  +
  +    private static XSComplexTypeDecl[][] resize(XSComplexTypeDecl array[][], int newsize) {
  +        XSComplexTypeDecl newarray[][] = new XSComplexTypeDecl[newsize][];
  +        System.arraycopy(array, 0, newarray, 0, array.length);
  +        return newarray;
  +    }
  +
  +
  +
  +    public void reset(){
  +        fElementDeclIndex = 0;
  +        fParticleDeclIndex = 0;
  +        fSTDeclIndex = 0;
  +        fCTDeclIndex = 0;
  +        fAttrDeclIndex = 0;
  +    }
   
  -    // REVISIT: add methods for adding decls to the pool.
   
   }
  
  
  
  1.7       +25 -1     xml-xerces/java/src/org/apache/xerces/impl/xs/XSElementDecl.java
  
  Index: XSElementDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSElementDecl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XSElementDecl.java	29 Jan 2002 01:15:14 -0000	1.6
  +++ XSElementDecl.java	3 Apr 2002 23:48:26 -0000	1.7
  @@ -66,7 +66,7 @@
    *
    * @author Elena Litani, IBM
    * @author Sandy Gao, IBM
  - * @version $Id: XSElementDecl.java,v 1.6 2002/01/29 01:15:14 lehors Exp $
  + * @version $Id: XSElementDecl.java,v 1.7 2002/04/03 23:48:26 elena Exp $
    */
   public class XSElementDecl {
   
  @@ -140,6 +140,9 @@
       }
   
       public IdentityConstraint[] getIDConstraints() {
  +        if (fIDCPos == 0) {
  +            return null;
  +        }
           if (fIDCPos < fIDConstraints.length) {
               fIDConstraints = resize(fIDConstraints, fIDCPos);
           }
  @@ -185,5 +188,26 @@
        */
       public boolean equals(Object o) {
           return o == this;
  +    }
  +
  +    /**
  +      * Reset current element declaration
  +      */
  +    public void reset(){
  +
  +        fName = null;
  +        fTargetNamespace = null;
  +        fType = null;
  +        fMiscFlags = 0;
  +        fBlock = SchemaSymbols.EMPTY_SET;
  +        fFinal = SchemaSymbols.EMPTY_SET;
  +        fDefault = null;
  +        fSubGroup = null;
  +        // reset identity constraints
  +        for (int i=0;i<fIDCPos;i++) {
  +            fIDConstraints[i] = null;
  +        }
  +
  +        fIDCPos = 0;
       }
   } // class XMLElementDecl
  
  
  
  1.5       +11 -1     xml-xerces/java/src/org/apache/xerces/impl/xs/XSParticleDecl.java
  
  Index: XSParticleDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XSParticleDecl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XSParticleDecl.java	15 Mar 2002 23:01:57 -0000	1.4
  +++ XSParticleDecl.java	3 Apr 2002 23:48:26 -0000	1.5
  @@ -62,7 +62,7 @@
    *
    * @author Sandy Gao, IBM
    *
  - * @version $Id: XSParticleDecl.java,v 1.4 2002/03/15 23:01:57 sandygao Exp $
  + * @version $Id: XSParticleDecl.java,v 1.5 2002/04/03 23:48:26 elena Exp $
    */
   public class XSParticleDecl {
   
  @@ -286,5 +286,15 @@
               }
               break;
           }
  +    }
  +
  +
  +    public void reset(){
  +        fType = PARTICLE_EMPTY;
  +        fValue = null;
  +        fOtherValue = null;
  +        fMinOccurs = 1;
  +        fMaxOccurs = 1;
  +
       }
   } // class XSParticle
  
  
  
  1.3       +12 -4     xml-xerces/java/src/org/apache/xerces/impl/xs/dom/DOMParser.java
  
  Index: DOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/dom/DOMParser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DOMParser.java	18 Feb 2002 20:59:27 -0000	1.2
  +++ DOMParser.java	3 Apr 2002 23:48:27 -0000	1.3
  @@ -58,7 +58,7 @@
   package org.apache.xerces.impl.xs.dom;
   
   import org.apache.xerces.impl.Constants;
  -import org.apache.xerces.parsers.StandardParserConfiguration;
  +import org.apache.xerces.parsers.NonValidatingConfiguration;
   import org.apache.xerces.impl.xs.SchemaSymbols;
   import org.apache.xerces.xni.XMLLocator;
   import org.apache.xerces.xni.QName;
  @@ -72,7 +72,7 @@
    * 
    * @author Sandy Gao, IBM
    * 
  - * @version $Id: DOMParser.java,v 1.2 2002/02/18 20:59:27 sandygao Exp $
  + * @version $Id: DOMParser.java,v 1.3 2002/04/03 23:48:27 elena Exp $
    */
   public class DOMParser extends org.apache.xerces.parsers.DOMParser {
   
  @@ -93,7 +93,9 @@
       
       // our own document implementation, which knows how to create Element
       // with line/column information
  -    protected DocumentImpl fDocumentImpl;
  +    public DocumentImpl fDocumentImpl;
  +
  +    private DOMNodePool fNodePool;
       
       //
       // Constructors
  @@ -103,17 +105,22 @@
        * Constructs a DOM parser using the dtd/xml schema parser configuration.
        */
       public DOMParser() {
  -        super(new StandardParserConfiguration(new SchemaSymbols.SchemaSymbolTable()));
  +        super(new NonValidatingConfiguration(new SchemaSymbols.SchemaSymbolTable()));
           try {
               // use our own document implementation
               setProperty(DOCUMENT_CLASS, "org.apache.xerces.impl.xs.dom.DocumentImpl");
               // don't defer DOM expansion
               setFeature(DEFER_EXPANSION, false);
  +
           }
           catch (Exception e) {
           }
       } // <init>()
   
  +    public void setPool(DOMNodePool nodePool){
  +        fNodePool = nodePool;
  +    }
  +
       /**
        * The start of the document.
        *
  @@ -134,6 +141,7 @@
           super.startDocument(locator, encoding, augs);
           // get a handle to the document created
           fDocumentImpl = (DocumentImpl)super.fDocumentImpl;
  +        fDocumentImpl.fNodePool=fNodePool;
           fLocator = locator;
   
       } // startDocument(XMLLocator,String,Augmentations)
  
  
  
  1.2       +52 -3     xml-xerces/java/src/org/apache/xerces/impl/xs/dom/DocumentImpl.java
  
  Index: DocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/dom/DocumentImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DocumentImpl.java	15 Feb 2002 16:54:29 -0000	1.1
  +++ DocumentImpl.java	3 Apr 2002 23:48:27 -0000	1.2
  @@ -57,8 +57,13 @@
   
   package org.apache.xerces.impl.xs.dom;
   
  +import org.apache.xerces.dom.TextImpl;
  +import org.apache.xerces.dom.AttrNSImpl;
   import org.w3c.dom.DOMException;
   import org.w3c.dom.Element;
  +import org.w3c.dom.Text;
  +import org.w3c.dom.Attr;
  +
   
   /**
    * Our own document implementation, which knows how to create an element
  @@ -66,14 +71,15 @@
    * 
    * @author Sandy Gao, IBM
    * 
  - * @version $Id: DocumentImpl.java,v 1.1 2002/02/15 16:54:29 sandygao Exp $
  + * @version $Id: DocumentImpl.java,v 1.2 2002/04/03 23:48:27 elena Exp $
    */
  -public class DocumentImpl extends org.apache.xerces.dom.DocumentImpl {
  +public class DocumentImpl extends org.apache.xerces.dom.CoreDocumentImpl {
   
  +    protected DOMNodePool fNodePool;
       //
       // Constructors
       //
  -
  +    
       /**
        * Create a document
        */
  @@ -81,6 +87,7 @@
           super();
       }
   
  +
       /**
        * create an element with line/colument information
        */
  @@ -89,8 +96,50 @@
                                      int lineNum, int columnNum)
           throws DOMException
       {
  +        if (fNodePool !=null) {
  +            ElementNSImpl element = fNodePool.getElementNode();
  +            element.setValues(this, namespaceURI, qualifiedName,
  +                                 localpart, lineNum, columnNum);
  +            return element;
  +        } 
           return new ElementNSImpl(this, namespaceURI, qualifiedName,
                                    localpart, lineNum, columnNum);
       }
  +
  +    /**
  +     * Create a text node. If node pool is available use text node from the pool.
  +     * 
  +     * @param data
  +     * @return 
  +     */
  +    public Text createTextNode(String data) {
  +        if (fNodePool != null) {
  +            TextImpl text = fNodePool.getTextNode();
  +            text.setValues(this, data);
  +            return text;
  +        }
  +        return new TextImpl(this, data);
  +    }  
  +      
  +
  +    /**
  +     * Create attribute node. If node pool is available use 
  +     * attribute node from the pool.
  +     * 
  +     * @param namespaceURI
  +     * @param qualifiedName
  +     * @param localName
  +     * @return 
  +     * @exception DOMException
  +     */
  +    public Attr createAttributeNS(String namespaceURI, String qualifiedName,
  +                                  String localName)  throws DOMException {
  +        if (fNodePool != null) {
  +            AttrNSImpl attr = fNodePool.getAttrNode();
  +            attr.setValues(this, namespaceURI, qualifiedName, localName);
  +            return attr;
  +        }
  +        return new AttrNSImpl(this, namespaceURI, qualifiedName, localName);
  +    } 
       
   } // class DocumentImpl
  
  
  
  1.2       +15 -1     xml-xerces/java/src/org/apache/xerces/impl/xs/dom/ElementNSImpl.java
  
  Index: ElementNSImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/dom/ElementNSImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ElementNSImpl.java	15 Feb 2002 16:54:29 -0000	1.1
  +++ ElementNSImpl.java	3 Apr 2002 23:48:27 -0000	1.2
  @@ -65,7 +65,7 @@
    * 
    * @author Sandy Gao, IBM
    * 
  - * @version $Id: ElementNSImpl.java,v 1.1 2002/02/15 16:54:29 sandygao Exp $
  + * @version $Id: ElementNSImpl.java,v 1.2 2002/04/03 23:48:27 elena Exp $
    */
   public class ElementNSImpl extends org.apache.xerces.dom.ElementNSImpl {
   
  @@ -77,6 +77,10 @@
       
       protected int columnNum;
       
  +    public ElementNSImpl(){
  +        super();
  +    }
  +
       /**
        * DOM2: Constructor for line/column information.
        */
  @@ -90,6 +94,16 @@
           this.lineNum = lineNum;
           this.columnNum = columnNum;
       }
  +
  +    protected void setValues(CoreDocumentImpl ownerDocument, 
  +                            String namespaceURI, String qualifiedName,
  +                            String localpart, int lineNum, int columnNum){
  +        super.setValues(ownerDocument, namespaceURI, qualifiedName, localpart);
  +        this.lineNum = lineNum;
  +        this.columnNum = columnNum;
  +
  +    }
  +
   
       /** Returns the line number. */
       public int getLineNumber() {
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/impl/xs/dom/DOMNodePool.java
  
  Index: DOMNodePool.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2002 International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.impl.xs.dom;
  
  import org.apache.xerces.dom.TextImpl;
  import org.apache.xerces.dom.AttrNSImpl;
  
  
  /**
   * This class is pool that enables caching of DOM nodes, such as Element, Attr, 
   * Text, that are used to parse and later traverse XML Schemas.
   * The pool is reset before a new set of schemas is traversed.
   * Note: pool is not reset during traversals of imported/included
   * schemas.
   * 
   * @author Elena Litani, IBM
   * @version $Id: DOMNodePool.java,v 1.1 2002/04/03 23:48:27 elena Exp $
   */
  public final class DOMNodePool {
      /** Chunk shift (8). */
      private static final int CHUNK_SHIFT = 8; // 2^8 = 256
  
      /** Chunk size (1 << CHUNK_SHIFT). */
      private static final int CHUNK_SIZE = 1 << CHUNK_SHIFT;
  
      /** Chunk mask (CHUNK_SIZE - 1). */
      private static final int CHUNK_MASK = CHUNK_SIZE - 1;
  
      /** Initial chunk count (). */
      private static final int INITIAL_CHUNK_COUNT = (1 << (10 - CHUNK_SHIFT)); // 2^10 = 1k
  
      /** Element nodes pool*/
      private ElementNSImpl fElements[][] = new ElementNSImpl[INITIAL_CHUNK_COUNT][];
      private int fElementIndex = 0;
  
  
      /** Text nodes pool*/
      private TextImpl fTextNode[][] = new TextImpl[INITIAL_CHUNK_COUNT][];
      private int fTextNodeIndex = 0;
  
  
      /** Attribute nodes pool*/
      private AttrNSImpl fAttrNode[][] = new AttrNSImpl[INITIAL_CHUNK_COUNT][];
      private int fAttrNodeIndex = 0;
  
      
  
      /**
       * This method creates a new element node or provides a 
       * free element node if such exists in the pool.
       * 
       * @return 
       */
      public final  ElementNSImpl getElementNode(){
          int     chunk       = fElementIndex >> CHUNK_SHIFT;
          int     index       = fElementIndex &  CHUNK_MASK;
          ensureElementsCapacity(chunk);
          if (fElements[chunk][index] == null) {
              fElements[chunk][index] = new ElementNSImpl();
          } 
          fElementIndex++;
          return fElements[chunk][index];
      }
  
      private boolean ensureElementsCapacity(int chunk) {
          try {
              return fElements[chunk][0] == null;
          } catch (ArrayIndexOutOfBoundsException ex) {
              fElements = resize(fElements, fElements.length * 2);
          } catch (NullPointerException ex) {
              // ignore
          }
  
          fElements[chunk] = new ElementNSImpl[CHUNK_SIZE];
          return true;
      }
  
      private static ElementNSImpl[][] resize(ElementNSImpl array[][], int newsize) {
          ElementNSImpl newarray[][] = new ElementNSImpl[newsize][];
          System.arraycopy(array, 0, newarray, 0, array.length);
          return newarray;
      }
  
      /**
       * This methods creates text node or provides a free
       * text node if such exists in the pool.
       * 
       * @return 
       */
      public final  TextImpl getTextNode(){
          int     chunk       = fTextNodeIndex >> CHUNK_SHIFT;
          int     index       = fTextNodeIndex &  CHUNK_MASK;
          ensureTextCapacity(chunk);
          if (fTextNode[chunk][index] == null) {
              fTextNode[chunk][index] = new TextImpl();
          } 
          fTextNodeIndex++;
          return fTextNode[chunk][index];
      }
  
      private boolean ensureTextCapacity(int chunk) {
          try {
              return fTextNode[chunk][0] == null;
          } catch (ArrayIndexOutOfBoundsException ex) {
              fTextNode = resize(fTextNode, fTextNode.length * 2);
          } catch (NullPointerException ex) {
              // ignore
          }
  
          fTextNode[chunk] = new TextImpl[CHUNK_SIZE];
          return true;
      }
  
      private static TextImpl[][] resize(TextImpl array[][], int newsize) {
          TextImpl newarray[][] = new TextImpl[newsize][];
          System.arraycopy(array, 0, newarray, 0, array.length);
          return newarray;
      }
  
      /**
       * This methods creates attribute node or provides a free
       * attribute node if such exists in the pool.
       * 
       * @return 
       */
      public final  AttrNSImpl getAttrNode(){
          int     chunk       = fAttrNodeIndex >> CHUNK_SHIFT;
          int     index       = fAttrNodeIndex &  CHUNK_MASK;
          ensureAttrsCapacity(chunk);
          if (fAttrNode[chunk][index] == null) {
              fAttrNode[chunk][index] = new AttrNSImpl();
          } 
          fAttrNodeIndex++;
          return fAttrNode[chunk][index];
      }
  
      private boolean ensureAttrsCapacity(int chunk) {
          try {
              return fAttrNode[chunk][0] == null;
          } catch (ArrayIndexOutOfBoundsException ex) {
              fAttrNode = resize(fAttrNode, fAttrNode.length * 2);
          } catch (NullPointerException ex) {
              // ignore
          }
  
          fAttrNode[chunk] = new AttrNSImpl[CHUNK_SIZE];
          return true;
      }
  
      private static AttrNSImpl[][] resize(AttrNSImpl array[][], int newsize) {
          AttrNSImpl newarray[][] = new AttrNSImpl[newsize][];
          System.arraycopy(array, 0, newarray, 0, array.length);
          return newarray;
      }
  
  
      /**
       * Reset the pool. The nodes in the pool become 'free' nodes.
       */
      public void reset(){
          fElementIndex = 0;
          fTextNodeIndex = 0;
          fAttrNodeIndex = 0;
      }
  
  
  }
  
  
  
  1.7       +18 -4     xml-xerces/java/src/org/apache/xerces/impl/xs/models/CMBuilder.java
  
  Index: CMBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/models/CMBuilder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CMBuilder.java	15 Mar 2002 23:01:57 -0000	1.6
  +++ CMBuilder.java	3 Apr 2002 23:48:27 -0000	1.7
  @@ -70,7 +70,7 @@
    * This class constructs content models for a given grammar.
    *
    * @author Elena Litani, IBM
  - * @version $Id: CMBuilder.java,v 1.6 2002/03/15 23:01:57 sandygao Exp $
  + * @version $Id: CMBuilder.java,v 1.7 2002/04/03 23:48:27 elena Exp $
    */
   public class CMBuilder {
   
  @@ -81,11 +81,15 @@
   
       // needed for DFA construction
       private int fLeafCount;
  -
  +                           
       public CMBuilder (XSDeclarationPool pool){
           fDeclPool = pool;
       }
   
  +    public void setDeclPool (XSDeclarationPool declPool){
  +        fDeclPool = declPool;
  +    }
  +
       /**
        * Get content model for the a given type
        *
  @@ -182,7 +186,12 @@
               if (right == null)
                   return expandContentModel((XSParticleDecl)left, minOccurs, maxOccurs);
   
  -            XSParticleDecl newParticle = new XSParticleDecl();
  +            XSParticleDecl newParticle;
  +            if (fDeclPool !=null) {
  +                newParticle = fDeclPool.getParticleDecl();
  +            } else {            
  +                newParticle = new XSParticleDecl();
  +            }
               newParticle.fType = particle.fType;
               newParticle.fValue = left;
               newParticle.fOtherValue = right;
  @@ -448,7 +457,12 @@
                                              XSParticleDecl left,
                                              XSParticleDecl right) {
   
  -        XSParticleDecl newParticle = new XSParticleDecl();
  +        XSParticleDecl newParticle;
  +        if (fDeclPool !=null) {
  +            newParticle = fDeclPool.getParticleDecl();
  +        } else {            
  +            newParticle = new XSParticleDecl();
  +        }
           newParticle.fType = type;
           newParticle.fValue = (Object) left;
           newParticle.fOtherValue = (Object)right;
  
  
  
  1.6       +21 -5     xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java
  
  Index: XSDAbstractParticleTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XSDAbstractParticleTraverser.java	15 Feb 2002 22:08:48 -0000	1.5
  +++ XSDAbstractParticleTraverser.java	3 Apr 2002 23:48:27 -0000	1.6
  @@ -67,7 +67,7 @@
   /**
    * @author Elena Litani, IBM
    * @author Sandy Gao, IBM
  - * @version $Id: XSDAbstractParticleTraverser.java,v 1.5 2002/02/15 22:08:48 sandygao Exp $
  + * @version $Id: XSDAbstractParticleTraverser.java,v 1.6 2002/04/03 23:48:27 elena Exp $
    */
   abstract class XSDAbstractParticleTraverser extends XSDAbstractTraverser {
   
  @@ -131,7 +131,11 @@
                   right = particle;
               }
               else {
  -                temp = new XSParticleDecl();
  +                if (fSchemaHandler.fDeclPool !=null) {
  +                    temp = fSchemaHandler.fDeclPool.getParticleDecl();
  +                } else {        
  +                    temp = new XSParticleDecl();
  +                }
                   temp.fType = XSParticleDecl.PARTICLE_ALL;
                   temp.fValue = left;
                   temp.fOtherValue = right;
  @@ -141,7 +145,11 @@
           }
   
           if (left != null) {
  -            temp = new XSParticleDecl();
  +            if (fSchemaHandler.fDeclPool !=null) {
  +                temp = fSchemaHandler.fDeclPool.getParticleDecl();
  +            } else {        
  +                temp = new XSParticleDecl();
  +            }
               temp.fType = XSParticleDecl.PARTICLE_ALL;
               temp.fValue = left;
               temp.fOtherValue = right;
  @@ -303,7 +311,11 @@
                   right = particle;
               }
               else {
  -                temp = new XSParticleDecl();
  +                if (fSchemaHandler.fDeclPool !=null) {
  +                    temp = fSchemaHandler.fDeclPool.getParticleDecl();
  +                } else {        
  +                    temp = new XSParticleDecl();
  +                }
                   if (choice)
                       temp.fType = XSParticleDecl.PARTICLE_CHOICE;
                   else
  @@ -320,7 +332,11 @@
           // For now we return null. In the future we might want to return model group decl.
   
           if (left != null) {
  -            temp = new XSParticleDecl();
  +            if (fSchemaHandler.fDeclPool !=null) {
  +                temp = fSchemaHandler.fDeclPool.getParticleDecl();
  +            } else {        
  +                temp = new XSParticleDecl();
  +            }
               if (choice)
                   temp.fType = XSParticleDecl.PARTICLE_CHOICE;
               else
  
  
  
  1.14      +3 -2      xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
  
  Index: XSDAbstractTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- XSDAbstractTraverser.java	21 Mar 2002 17:13:20 -0000	1.13
  +++ XSDAbstractTraverser.java	3 Apr 2002 23:48:27 -0000	1.14
  @@ -92,7 +92,7 @@
    * @author Rahul Srivastava, Sun Microsystems Inc.
    * @author Neeraj Bajaj, Sun Microsystems Inc.
    *
  - * @version $Id: XSDAbstractTraverser.java,v 1.13 2002/03/21 17:13:20 sandygao Exp $
  + * @version $Id: XSDAbstractTraverser.java,v 1.14 2002/04/03 23:48:27 elena Exp $
    */
   abstract class XSDAbstractTraverser {
   
  @@ -431,7 +431,8 @@
                   if(tempAttrGrp == null ) break;
                   XSAttributeUse[] attrUseS = tempAttrGrp.getAttributeUses();
                   XSAttributeUse existingAttrUse = null;
  -                for (int i=0; i<attrUseS.length; i++) {
  +                int attrCount = (attrUseS !=null)?attrUseS.length:0;
  +                for (int i=0; i<attrCount; i++) {
                       existingAttrUse = attrGrp.getAttributeUse(attrUseS[i].fAttrDecl.fTargetNamespace,
                                                                 attrUseS[i].fAttrDecl.fName);
                       if (existingAttrUse == null) {
  
  
  
  1.12      +15 -8     xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
  
  Index: XSDAttributeTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XSDAttributeTraverser.java	15 Feb 2002 22:08:48 -0000	1.11
  +++ XSDAttributeTraverser.java	3 Apr 2002 23:48:27 -0000	1.12
  @@ -93,7 +93,7 @@
    *
    * @author Sandy Gao, IBM
    * @author Neeraj Bajaj, Sun Microsystems, inc.
  - * @version $Id: XSDAttributeTraverser.java,v 1.11 2002/02/15 22:08:48 sandygao Exp $
  + * @version $Id: XSDAttributeTraverser.java,v 1.12 2002/04/03 23:48:27 elena Exp $
    */
   class XSDAttributeTraverser extends XSDAbstractTraverser {
   
  @@ -122,7 +122,7 @@
                   attribute = (XSAttributeDecl)fSchemaHandler.getGlobalDecl(schemaDoc, XSDHandler.ATTRIBUTE_TYPE, refAtt, attrDecl);
   
                   Element child = DOMUtil.getFirstChildElement(attrDecl);
  -                if(child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
  +                if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
                       traverseAnnotationDecl(child, attrValues, false, schemaDoc);
                       child = DOMUtil.getNextSiblingElement(child);
                   }
  @@ -151,7 +151,11 @@
   
           XSAttributeUse attrUse = null;
           if (attribute != null) {
  -            attrUse = new XSAttributeUse();
  +            if (fSchemaHandler.fDeclPool !=null) {
  +                attrUse = fSchemaHandler.fDeclPool.getAttributeUse();            
  +            } else {
  +                attrUse = new XSAttributeUse();
  +            }
               attrUse.fAttrDecl = attribute;
               attrUse.fUse = useAtt.shortValue();
               attrUse.fConstraintType = consType;
  @@ -244,7 +248,12 @@
           QName   typeAtt    = (QName)  attrValues[XSAttributeChecker.ATTIDX_TYPE];
   
           // Step 1: get declaration information
  -        XSAttributeDecl attribute = new XSAttributeDecl();
  +        XSAttributeDecl attribute = null;
  +        if (fSchemaHandler.fDeclPool !=null) {
  +            attribute = fSchemaHandler.fDeclPool.getAttributeDecl();            
  +        } else {
  +            attribute = new XSAttributeDecl();
  +        }
   
           // get 'name'
           if (nameAtt != null)
  @@ -253,8 +262,7 @@
           // get 'target namespace'
           if (isGlobal) {
               attribute.fTargetNamespace = schemaDoc.fTargetNamespace;
  -        }
  -        else if (formAtt != null) {
  +        } else if (formAtt != null) {
               if (formAtt.intValue() == SchemaSymbols.FORM_QUALIFIED)
                   attribute.fTargetNamespace = schemaDoc.fTargetNamespace;
               else
  @@ -264,7 +272,6 @@
           } else {
               attribute.fTargetNamespace = null;
           }
  -
           // get 'value constraint'
           // for local named attribute, value constraint is absent
           if (isGlobal) {
  @@ -283,7 +290,7 @@
   
           // get 'annotation'
           Element child = DOMUtil.getFirstChildElement(attrDecl);
  -        if(child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
  +        if (child != null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
               traverseAnnotationDecl(child, attrValues, false, schemaDoc);
               child = DOMUtil.getNextSiblingElement(child);
           }
  
  
  
  1.16      +4 -3      xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
  
  Index: XSDComplexTypeTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XSDComplexTypeTraverser.java	21 Mar 2002 17:13:20 -0000	1.15
  +++ XSDComplexTypeTraverser.java	3 Apr 2002 23:48:27 -0000	1.16
  @@ -91,7 +91,7 @@
    *            ((group | all | choice | sequence)?,
    *            ((attribute | attributeGroup)*, anyAttribute?))))
    * </complexType>
  - * @version $Id: XSDComplexTypeTraverser.java,v 1.15 2002/03/21 17:13:20 sandygao Exp $
  + * @version $Id: XSDComplexTypeTraverser.java,v 1.16 2002/04/03 23:48:27 elena Exp $
    */
   
   class  XSDComplexTypeTraverser extends XSDAbstractParticleTraverser {
  @@ -762,10 +762,12 @@
   
           XSAttributeUse[] attrUseS = fromAttrGrp.getAttributeUses();
           XSAttributeUse existingAttrUse, duplicateAttrUse =  null;
  -        for (int i=0; i<attrUseS.length; i++) {
  +        int attrCount = (attrUseS!=null)?attrUseS.length:0;
  +        for (int i=0; i<attrCount; i++) {
               existingAttrUse = toAttrGrp.getAttributeUse(attrUseS[i].fAttrDecl.fTargetNamespace,
                                                           attrUseS[i].fAttrDecl.fName);
               if (existingAttrUse == null) {
  +
                   String idName = toAttrGrp.addAttributeUse(attrUseS[i]);
                   if (idName != null) {
                       throw new ComplexTypeRecoverableError("ct-props-correct.5",
  @@ -781,7 +783,6 @@
                   }
               }
           }
  -
           // For extension, the wildcard must be formed by doing a union of the wildcards
           if (extension) {
               if (toAttrGrp.fAttributeWC==null) {
  
  
  
  1.15      +16 -7     xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
  
  Index: XSDElementTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XSDElementTraverser.java	15 Mar 2002 23:01:58 -0000	1.14
  +++ XSDElementTraverser.java	3 Apr 2002 23:48:27 -0000	1.15
  @@ -97,12 +97,12 @@
    *
    * @author Sandy Gao, IBM
    *
  - * @version $Id: XSDElementTraverser.java,v 1.14 2002/03/15 23:01:58 sandygao Exp $
  + * @version $Id: XSDElementTraverser.java,v 1.15 2002/04/03 23:48:27 elena Exp $
    */
   class XSDElementTraverser extends XSDAbstractTraverser {
   
  -    protected XSElementDecl  fTempElementDecl  = new XSElementDecl();
  -    protected XSParticleDecl fTempParticleDecl = new XSParticleDecl();
  +    protected final XSElementDecl  fTempElementDecl  = new XSElementDecl();
  +    protected final XSParticleDecl fTempParticleDecl = new XSParticleDecl();
   
       // this controls what happens when a local element is encountered.
       // We may not encounter all local elements when first parsing.
  @@ -131,8 +131,12 @@
                                    SchemaGrammar grammar,
                                    int allContextFlags) {
   
  -        XSParticleDecl particle = new XSParticleDecl();
  -
  +        XSParticleDecl particle = null;
  +        if (fSchemaHandler.fDeclPool !=null) {
  +            particle = fSchemaHandler.fDeclPool.getParticleDecl();            
  +        } else {        
  +            particle = new XSParticleDecl();
  +        }
           if(fDeferTraversingLocalElements) {
               fSchemaHandler.fillInLocalElemInfo(elmDecl, schemaDoc, allContextFlags, particle);
           } else {
  @@ -253,8 +257,13 @@
           QName   typeAtt      = (QName)   attrValues[XSAttributeChecker.ATTIDX_TYPE];
   
           // Step 1: get declaration information
  -        XSElementDecl element = new XSElementDecl();
  -
  +        
  +        XSElementDecl element = null;
  +        if (fSchemaHandler.fDeclPool !=null) {
  +            element = fSchemaHandler.fDeclPool.getElementDecl();
  +        } else {        
  +            element = new XSElementDecl();
  +        }
           // get 'name'
           if (nameAtt != null)
               element.fName = fSymbolTable.addSymbol(nameAtt);
  
  
  
  1.9       +6 -2      xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java
  
  Index: XSDGroupTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XSDGroupTraverser.java	18 Feb 2002 22:30:25 -0000	1.8
  +++ XSDGroupTraverser.java	3 Apr 2002 23:48:27 -0000	1.9
  @@ -77,7 +77,7 @@
    * @author Rahul Srivastava, Sun Microsystems Inc.
    * @author Elena Litani, IBM
    * @author Lisa Martin,  IBM
  - * @version $Id: XSDGroupTraverser.java,v 1.8 2002/02/18 22:30:25 sandygao Exp $
  + * @version $Id: XSDGroupTraverser.java,v 1.9 2002/04/03 23:48:27 elena Exp $
    */
   class  XSDGroupTraverser extends XSDAbstractParticleTraverser {
   
  @@ -128,7 +128,11 @@
               else if (!( minOccurs == 1 && maxOccurs == 1)) {
                   // if minOccurs==maxOccurs==1 we don't need to create new particle
                   // create new particle in the grammar if minOccurs<maxOccurs
  -                particle = new XSParticleDecl();
  +                if (fSchemaHandler.fDeclPool !=null) {
  +                    particle = fSchemaHandler.fDeclPool.getParticleDecl();
  +                } else {        
  +                    particle = new XSParticleDecl();
  +                }
                   particle.fType = group.fParticle.fType;
                   particle.fValue = group.fParticle;
                   particle.fMinOccurs = minOccurs;
  
  
  
  1.34      +20 -2     xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
  
  Index: XSDHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- XSDHandler.java	27 Mar 2002 18:08:32 -0000	1.33
  +++ XSDHandler.java	3 Apr 2002 23:48:27 -0000	1.34
  @@ -60,6 +60,7 @@
   import org.apache.xerces.impl.xs.XSGrammarBucket;
   import org.apache.xerces.impl.xs.XSParticleDecl;
   import org.apache.xerces.impl.xs.XSElementDecl;
  +import org.apache.xerces.impl.xs.XSDeclarationPool;
   import org.apache.xerces.impl.xs.SchemaNamespaceSupport;
   import org.apache.xerces.impl.xs.SchemaGrammar;
   import org.apache.xerces.impl.xs.XSComplexTypeDecl;
  @@ -87,6 +88,7 @@
   import org.apache.xerces.xni.XMLLocator;
   
   import org.apache.xerces.impl.xs.dom.DOMParser;
  +import org.apache.xerces.impl.xs.dom.DOMNodePool;
   import org.apache.xerces.impl.xs.dom.ElementNSImpl;
   import org.apache.xerces.impl.xs.util.SimpleLocator;
   import org.w3c.dom.Document;
  @@ -117,7 +119,7 @@
    *
    * @author Neil Graham, IBM
    * @author Pavani Mukthipudi, Sun Microsystems
  - * @version $Id: XSDHandler.java,v 1.33 2002/03/27 18:08:32 sandygao Exp $
  + * @version $Id: XSDHandler.java,v 1.34 2002/04/03 23:48:27 elena Exp $
    */
   public class XSDHandler {
   
  @@ -129,6 +131,8 @@
       protected static final String JAXP_SCHEMA_SOURCE =
           Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
   
  +    protected static final boolean DEBUG_NODE_POOL = false;
  +                              
       // data
   
       // different sorts of declarations; should make lookup and
  @@ -157,6 +161,8 @@
       // stores <notation> decl
       protected Hashtable fNotationRegistry = new Hashtable();
   
  +    protected XSDeclarationPool fDeclPool = null;
  +
       // These tables correspond to the symbol spaces defined in the
       // spec.
       // They are keyed with a QName (that is, String("URI,localpart) and
  @@ -316,6 +322,7 @@
       XSDWildcardTraverser fWildCardTraverser;
   
       DOMParser fSchemaParser;
  +    final DOMNodePool fDOMPool = new DOMNodePool();
   
       // these data members are needed for the deferred traversal
       // of local elements.
  @@ -371,6 +378,8 @@
       // this object (i.e., clean the registries, etc.).
       public SchemaGrammar parseSchema(XSDDescription desc) {
           XMLInputSource schemaSource=null;
  +        fDOMPool.reset();
  +        fSchemaParser.setPool(fDOMPool);
           try {
               schemaSource = fLocationResolver.resolveEntity(desc);
           }
  @@ -933,6 +942,9 @@
                                      QName declToTraverse,
                                      Element elmNode) {
   
  +        if (DEBUG_NODE_POOL) {
  +            System.out.println("TRAVERSE_GL: "+declToTraverse.toString());
  +        }
           // from the schema spec, all built-in types are present in all schemas,
           // so if the requested component is a type, and could be found in the
           // default schema grammar, we should return that type.
  @@ -1362,7 +1374,9 @@
           fRedefinedRestrictedAttributeGroupRegistry.clear();
           fRedefinedRestrictedGroupRegistry.clear();
       }
  -    
  +    public void setDeclPool (XSDeclarationPool declPool){
  +        fDeclPool = declPool;
  +    }
       // this method reset properties that might change between parses.
       // and process the jaxp schemaSource property
       public void reset(XMLErrorReporter errorReporter,
  @@ -1728,6 +1742,10 @@
       // @param:  decl:  the declaration being ref'd.
       private XSDocumentInfo findXSDocumentForDecl(XSDocumentInfo currSchema,
                                                    Element decl) {
  +
  +        if (DEBUG_NODE_POOL) {
  +            System.out.println("DOCUMENT NS:"+ currSchema.fTargetNamespace+" hashcode:"+ ((Object)currSchema.fSchemaDoc).hashCode());
  +        }
           Document declDoc = DOMUtil.getDocument(decl);
           Object temp = fDoc2XSDocumentMap.get(declDoc);
           if (temp == null) {
  
  
  
  1.15      +5 -1      xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java
  
  Index: XSDSimpleTypeTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDSimpleTypeTraverser.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- XSDSimpleTypeTraverser.java	21 Mar 2002 17:13:20 -0000	1.14
  +++ XSDSimpleTypeTraverser.java	3 Apr 2002 23:48:27 -0000	1.15
  @@ -65,6 +65,7 @@
   import org.apache.xerces.impl.xs.SchemaGrammar;
   import org.apache.xerces.impl.xs.SchemaSymbols;
   import org.apache.xerces.impl.xs.XSTypeDecl;
  +import org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl;
   
   import org.apache.xerces.util.DOMUtil;
   import org.apache.xerces.impl.xs.util.XInt;
  @@ -117,7 +118,7 @@
    * @author Neeraj Bajaj, Sun Microsystems, Inc.
    * @author Sandy Gao, IBM
    * 
  - * @version $Id: XSDSimpleTypeTraverser.java,v 1.14 2002/03/21 17:13:20 sandygao Exp $
  + * @version $Id: XSDSimpleTypeTraverser.java,v 1.15 2002/04/03 23:48:27 elena Exp $
    */
   class XSDSimpleTypeTraverser extends XSDAbstractTraverser {
   
  @@ -127,6 +128,9 @@
       XSDSimpleTypeTraverser (XSDHandler handler,
                               XSAttributeChecker gAttrCheck) {
           super(handler, gAttrCheck);
  +        if (schemaFactory instanceof SchemaDVFactoryImpl) {
  +            ((SchemaDVFactoryImpl)schemaFactory).setDeclPool(handler.fDeclPool);
  +        }
       }
   
       //return qualified name of simpleType or empty string if error occured
  
  
  
  1.6       +6 -2      xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDWildcardTraverser.java
  
  Index: XSDWildcardTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDWildcardTraverser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XSDWildcardTraverser.java	15 Feb 2002 22:08:48 -0000	1.5
  +++ XSDWildcardTraverser.java	3 Apr 2002 23:48:27 -0000	1.6
  @@ -91,7 +91,7 @@
    * @author Rahul Srivastava, Sun Microsystems Inc.
    * @author Sandy Gao, IBM
    *
  - * @version $Id: XSDWildcardTraverser.java,v 1.5 2002/02/15 22:08:48 sandygao Exp $
  + * @version $Id: XSDWildcardTraverser.java,v 1.6 2002/04/03 23:48:27 elena Exp $
    */
   class XSDWildcardTraverser extends XSDAbstractTraverser {
   
  @@ -130,7 +130,11 @@
               int min = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]).intValue();
               int max = ((XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]).intValue();
               if (max != 0) {
  -                particle = new XSParticleDecl();
  +                if (fSchemaHandler.fDeclPool !=null) {
  +                    particle = fSchemaHandler.fDeclPool.getParticleDecl();
  +                } else {        
  +                    particle = new XSParticleDecl();
  +                }
                   particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
                   particle.fValue = wildcard;
                   particle.fMinOccurs = min;
  
  
  
  1.46      +9 -5      xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java
  
  Index: AbstractDOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- AbstractDOMParser.java	1 Apr 2002 21:44:38 -0000	1.45
  +++ AbstractDOMParser.java	3 Apr 2002 23:48:27 -0000	1.46
  @@ -59,6 +59,7 @@
   
   import org.apache.xerces.dom.AttrImpl;
   import org.apache.xerces.dom.DeferredDocumentImpl;
  +import org.apache.xerces.dom.CoreDocumentImpl;
   import org.apache.xerces.dom.DocumentImpl;
   import org.apache.xerces.dom.DocumentTypeImpl;
   import org.apache.xerces.dom.ElementDefinitionImpl;
  @@ -106,7 +107,7 @@
    * @author Andy Clark, IBM
    * @author Elena Litani, IBM
    *
  - * @version $Id: AbstractDOMParser.java,v 1.45 2002/04/01 21:44:38 neilg Exp $
  + * @version $Id: AbstractDOMParser.java,v 1.46 2002/04/03 23:48:27 elena Exp $
    */
   public abstract class AbstractDOMParser
       extends AbstractXMLDocumentParser {
  @@ -160,6 +161,8 @@
       protected static final String DEFAULT_DOCUMENT_CLASS_NAME =
           "org.apache.xerces.dom.DocumentImpl";
   
  +    protected static final String CORE_DOCUMENT_CLASS_NAME =
  +        "org.apache.xerces.dom.CoreDocumentImpl";
   
       // debugging
   
  @@ -195,7 +198,7 @@
       protected Document fDocument;
   
       /** The default Xerces document implementation, if used. */
  -    protected DocumentImpl fDocumentImpl;
  +    protected CoreDocumentImpl fDocumentImpl;
   
       /** The document class name to use. */
       protected String  fDocumentClassName;
  @@ -609,7 +612,7 @@
           if (!fDeferNodeExpansion) {
               if (fDocumentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME)) {
                   fDocument = new DocumentImpl();
  -                fDocumentImpl = (DocumentImpl)fDocument;
  +                fDocumentImpl = (CoreDocumentImpl)fDocument;
                   // REVISIT: when DOM Level 3 is REC rely on Document.support
                   //          instead of specific class
                   // set DOM error checking off
  @@ -622,11 +625,12 @@
                   try {
                       Class documentClass = Class.forName(fDocumentClassName);
                       fDocument = (Document)documentClass.newInstance();
  +
                       // if subclass of our own class that's cool too
                       Class defaultDocClass =
  -                        Class.forName(DEFAULT_DOCUMENT_CLASS_NAME);
  +                        Class.forName(CORE_DOCUMENT_CLASS_NAME);
                       if (defaultDocClass.isAssignableFrom(documentClass)) {
  -                        fDocumentImpl = (DocumentImpl)fDocument;
  +                        fDocumentImpl = (CoreDocumentImpl)fDocument;
                           // REVISIT: when DOM Level 3 is REC rely on
                           //          Document.support instead of specific class
                           // set DOM error checking off
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/parsers/NonValidatingConfiguration.java
  
  Index: NonValidatingConfiguration.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001, 2002 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.parsers;
  
  import java.io.IOException;
  import java.util.Locale;
  
  import org.apache.xerces.impl.Constants;
  import org.apache.xerces.impl.XMLDocumentScannerImpl;
  import org.apache.xerces.impl.XMLDTDScannerImpl;
  import org.apache.xerces.impl.XMLErrorReporter;
  import org.apache.xerces.impl.XMLEntityManager;
  import org.apache.xerces.impl.XMLNamespaceBinder;
  import org.apache.xerces.impl.msg.XMLMessageFormatter;
  import org.apache.xerces.impl.validation.ValidationManager;
  import org.apache.xerces.impl.dv.DTDDVFactory;
  import org.apache.xerces.xni.grammars.XMLGrammarPool;
  import org.apache.xerces.impl.validation.XMLGrammarPoolImpl;
  
  import org.apache.xerces.util.SymbolTable;
  import org.apache.xerces.xni.XMLLocator;
  import org.apache.xerces.xni.XNIException;
  import org.apache.xerces.xni.parser.XMLComponent;
  import org.apache.xerces.xni.parser.XMLComponentManager;
  import org.apache.xerces.xni.parser.XMLConfigurationException;
  import org.apache.xerces.xni.parser.XMLDocumentScanner;
  import org.apache.xerces.xni.parser.XMLDTDScanner;
  import org.apache.xerces.xni.parser.XMLInputSource;
  import org.apache.xerces.xni.parser.XMLPullParserConfiguration;
  
  /**
   * This is the non validating parser configuration. It extends the basic
   * configuration with the set of following parser components:
   * Document scanner, DTD scanner, namespace binder, document handler.
   * 
   * @author Elena Litani, IBM
   * @version $Id: NonValidatingConfiguration.java,v 1.1 2002/04/03 23:48:27 elena Exp $
   */
  public class NonValidatingConfiguration
      extends BasicParserConfiguration 
      implements XMLPullParserConfiguration {
  
      //
      // Constants
      //
  
      // feature identifiers
  
      /** Feature identifier: warn on duplicate attribute definition. */
      protected static final String WARN_ON_DUPLICATE_ATTDEF =
          Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE;
      
      /** Feature identifier: warn on undeclared element definition. */
      protected static final String WARN_ON_UNDECLARED_ELEMDEF =
          Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE;
      
      /** Feature identifier: allow Java encodings. */
      protected static final String ALLOW_JAVA_ENCODINGS = 
          Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
      
      /** Feature identifier: continue after fatal error. */
      protected static final String CONTINUE_AFTER_FATAL_ERROR = 
          Constants.XERCES_FEATURE_PREFIX + Constants.CONTINUE_AFTER_FATAL_ERROR_FEATURE;
  
      /** Feature identifier: load external DTD. */
      protected static final String LOAD_EXTERNAL_DTD =
          Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE;
  
      /** Feature identifier: notify built-in refereces. */
      protected static final String NOTIFY_BUILTIN_REFS =
          Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_BUILTIN_REFS_FEATURE;
      
      /** Feature identifier: notify character refereces. */
      protected static final String NOTIFY_CHAR_REFS =
          Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE;
      
  
      /** Feature identifier: expose schema normalized value */
      protected static final String NORMALIZE_DATA =
      Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE;
  
  
      /** Feature identifier: send element default value via characters() */
      protected static final String SCHEMA_ELEMENT_DEFAULT =
      Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
  
      // property identifiers
  
      /** Property identifier: error reporter. */
      protected static final String ERROR_REPORTER = 
          Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
  
      /** Property identifier: entity manager. */
      protected static final String ENTITY_MANAGER = 
          Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
      
      /** Property identifier document scanner: */
      protected static final String DOCUMENT_SCANNER = 
          Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
  
      /** Property identifier: DTD scanner. */
      protected static final String DTD_SCANNER = 
          Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
  
      /** Property identifier: grammar pool. */
      protected static final String XMLGRAMMAR_POOL = 
          Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
      
      /** Property identifier: DTD validator. */
      protected static final String DTD_VALIDATOR = 
          Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY;
  
      /** Property identifier: namespace binder. */
      protected static final String NAMESPACE_BINDER =
          Constants.XERCES_PROPERTY_PREFIX + Constants.NAMESPACE_BINDER_PROPERTY;
  
      /** Property identifier: datatype validator factory. */
      protected static final String DATATYPE_VALIDATOR_FACTORY = 
          Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
  
      protected static final String VALIDATION_MANAGER =
          Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY;
  
      /** Property identifier: XML Schema validator. */
      protected static final String SCHEMA_VALIDATOR =
          Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
  
  
      // debugging
  
      /** Set to true and recompile to print exception stack trace. */
      private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
  
      //
      // Data
      //
  
      // components (non-configurable)
  
      /** Grammar pool. */
      protected XMLGrammarPool fGrammarPool;
  
      /** Datatype validator factory. */
      protected DTDDVFactory fDatatypeValidatorFactory;
  
      // components (configurable)
  
      /** Error reporter. */
      protected XMLErrorReporter fErrorReporter;
  
      /** Entity manager. */
      protected XMLEntityManager fEntityManager;
  
      /** Document scanner. */
      protected XMLDocumentScanner fScanner;
  
      /** Input Source */
      protected XMLInputSource fInputSource;
  
      /** DTD scanner. */
      protected XMLDTDScanner fDTDScanner;
  
      /** Namespace binder. */
      protected XMLNamespaceBinder fNamespaceBinder;
  
      protected ValidationManager fValidationManager;
      // state
  
      /** Locator */
      protected XMLLocator fLocator;
  
      /** 
       * True if a parse is in progress. This state is needed because
       * some features/properties cannot be set while parsing (e.g.
       * validation and namespaces).
       */
      protected boolean fParseInProgress = false;
  
      //
      // Constructors
      //
  
      /** Default constructor. */
      public NonValidatingConfiguration() {
          this(null, null, null);
      } // <init>()
  
      /** 
       * Constructs a parser configuration using the specified symbol table. 
       *
       * @param symbolTable The symbol table to use.
       */
      public NonValidatingConfiguration(SymbolTable symbolTable) {
          this(symbolTable, null, null);
      } // <init>(SymbolTable)
  
      /**
       * Constructs a parser configuration using the specified symbol table and
       * grammar pool.
       * <p>
       * <strong>REVISIT:</strong> 
       * Grammar pool will be updated when the new validation engine is
       * implemented.
       *
       * @param symbolTable The symbol table to use.
       * @param grammarPool The grammar pool to use.
       */
      public NonValidatingConfiguration(SymbolTable symbolTable,
                                         XMLGrammarPool grammarPool) {
          this(symbolTable, grammarPool, null);
      } // <init>(SymbolTable,XMLGrammarPool)
  
      /**
       * Constructs a parser configuration using the specified symbol table,
       * grammar pool, and parent settings.
       * <p>
       * <strong>REVISIT:</strong> 
       * Grammar pool will be updated when the new validation engine is
       * implemented.
       *
       * @param symbolTable    The symbol table to use.
       * @param grammarPool    The grammar pool to use.
       * @param parentSettings The parent settings.
       */
      public NonValidatingConfiguration(SymbolTable symbolTable,
                                         XMLGrammarPool grammarPool,
                                         XMLComponentManager parentSettings) {
          super(symbolTable, parentSettings);
  
          // add default recognized features
          final String[] recognizedFeatures = {
              WARN_ON_DUPLICATE_ATTDEF,   WARN_ON_UNDECLARED_ELEMDEF,
              ALLOW_JAVA_ENCODINGS,       CONTINUE_AFTER_FATAL_ERROR,
              LOAD_EXTERNAL_DTD,          NOTIFY_BUILTIN_REFS,
              NOTIFY_CHAR_REFS
          };
          addRecognizedFeatures(recognizedFeatures);
  
          // set state for default features
          setFeature(WARN_ON_DUPLICATE_ATTDEF, false);
          setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);
          setFeature(ALLOW_JAVA_ENCODINGS, false);
          setFeature(CONTINUE_AFTER_FATAL_ERROR, false);
          setFeature(LOAD_EXTERNAL_DTD, true);
          setFeature(NOTIFY_BUILTIN_REFS, false);
          setFeature(NOTIFY_CHAR_REFS, false);
  
          // add default recognized properties
          final String[] recognizedProperties = {
              ERROR_REPORTER,             
              ENTITY_MANAGER, 
              DOCUMENT_SCANNER,
              DTD_SCANNER,
              DTD_VALIDATOR,
              NAMESPACE_BINDER,
              XMLGRAMMAR_POOL,   
              DATATYPE_VALIDATOR_FACTORY,
              VALIDATION_MANAGER
          };
          addRecognizedProperties(recognizedProperties);
  	
          fGrammarPool = grammarPool;
          if(fGrammarPool != null){
          	setProperty(XMLGRAMMAR_POOL, fGrammarPool);
          }
  
          fEntityManager = createEntityManager();
          setProperty(ENTITY_MANAGER, fEntityManager);
          addComponent(fEntityManager);
  
          fErrorReporter = createErrorReporter();
          fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
          setProperty(ERROR_REPORTER, fErrorReporter);
          addComponent(fErrorReporter);
  
          fScanner = createDocumentScanner();
          setProperty(DOCUMENT_SCANNER, fScanner);
          if (fScanner instanceof XMLComponent) {
              addComponent((XMLComponent)fScanner);
          }
  
          fDTDScanner = createDTDScanner();
          if (fDTDScanner != null) {
              setProperty(DTD_SCANNER, fDTDScanner);
              if (fDTDScanner instanceof XMLComponent) {
                  addComponent((XMLComponent)fDTDScanner);
              }
          }
  
          fNamespaceBinder = createNamespaceBinder();
          if (fNamespaceBinder != null) {
              setProperty(NAMESPACE_BINDER, fNamespaceBinder);
              addComponent(fNamespaceBinder);
          }
          
          fDatatypeValidatorFactory = createDatatypeValidatorFactory();
          if (fDatatypeValidatorFactory != null) {
              setProperty(DATATYPE_VALIDATOR_FACTORY,
                          fDatatypeValidatorFactory);
          }
          fValidationManager = createValidationManager();
  
          if (fValidationManager != null) {
              setProperty (VALIDATION_MANAGER, fValidationManager);
          }
          // add message formatters
          if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
              XMLMessageFormatter xmft = new XMLMessageFormatter();
              fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
              fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
          }
  
          // set locale
          try {
              setLocale(Locale.getDefault());
          }
          catch (XNIException e) {
              // do nothing
              // REVISIT: What is the right thing to do? -Ac
          }
  
      } // <init>(SymbolTable,XMLGrammarPool)
  
      //
      // Public methods
      //
  
      /**
       * Set the locale to use for messages.
       *
       * @param locale The locale object to use for localization of messages.
       *
       * @exception XNIException Thrown if the parser does not support the
       *                         specified locale.
       */
      public void setLocale(Locale locale) throws XNIException {
          super.setLocale(locale);
          fErrorReporter.setLocale(locale);
      } // setLocale(Locale)
  
      //
      // XMLPullParserConfiguration methods
      //
  
      // parsing
  
      /**
       * Sets the input source for the document to parse.
       *
       * @param inputSource The document's input source.
       *
       * @exception XMLConfigurationException Thrown if there is a 
       *                        configuration error when initializing the
       *                        parser.
       * @exception IOException Thrown on I/O error.
       *
       * @see #parse(boolean)
       */
      public void setInputSource(XMLInputSource inputSource)
          throws XMLConfigurationException, IOException {
          
          // REVISIT: this method used to reset all the components and
          //          construct the pipeline. Now reset() is called
          //          in parse (boolean) just before we parse the document
          //          Should this method still throw exceptions..?
  
          fInputSource = inputSource;
          
      } // setInputSource(XMLInputSource)
  
      /**
       * Parses the document in a pull parsing fashion.
       *
       * @param complete True if the pull parser should parse the
       *                 remaining document completely.
       *
       * @returns True if there is more document to parse.
       *
       * @exception XNIException Any XNI exception, possibly wrapping 
       *                         another exception.
       * @exception IOException  An IO exception from the parser, possibly
       *                         from a byte stream or character stream
       *                         supplied by the parser.
       *
       * @see #setInputSource
       */
      public boolean parse(boolean complete) throws XNIException, IOException {
          //
          // reset and configure pipeline and set InputSource.
          if (fInputSource !=null) {
              try {
                  // resets and sets the pipeline.
                  reset();
                  fScanner.setInputSource(fInputSource);
                  fInputSource = null;
              } 
              catch (XNIException ex) {
                  if (PRINT_EXCEPTION_STACK_TRACE)
                      ex.printStackTrace();
                  throw ex;
              } 
              catch (IOException ex) {
                  if (PRINT_EXCEPTION_STACK_TRACE)
                      ex.printStackTrace();
                  throw ex;
              } 
              catch (RuntimeException ex) {
                  if (PRINT_EXCEPTION_STACK_TRACE)
                      ex.printStackTrace();
                  throw ex;
              }
              catch (Exception ex) {
                  if (PRINT_EXCEPTION_STACK_TRACE)
                      ex.printStackTrace();
                  throw new XNIException(ex);
              }
          }
  
          try {
              return fScanner.scanDocument(complete);
          } 
          catch (XNIException ex) {
              if (PRINT_EXCEPTION_STACK_TRACE)
                  ex.printStackTrace();
              throw ex;
          } 
          catch (IOException ex) {
              if (PRINT_EXCEPTION_STACK_TRACE)
                  ex.printStackTrace();
              throw ex;
          } 
          catch (RuntimeException ex) {
              if (PRINT_EXCEPTION_STACK_TRACE)
                  ex.printStackTrace();
              throw ex;
          }
          catch (Exception ex) {
              if (PRINT_EXCEPTION_STACK_TRACE)
                  ex.printStackTrace();
              throw new XNIException(ex);
          }
  
      } // parse(boolean):boolean
  
      /**
       * If the application decides to terminate parsing before the xml document
       * is fully parsed, the application should call this method to free any
       * resource allocated during parsing. For example, close all opened streams.
       */
      public void cleanup() {
          fEntityManager.closeReaders();
      }
      
      //
      // XMLParserConfiguration methods
      //
  
      /**
       * Parses the specified input source.
       *
       * @param source The input source.
       *
       * @exception XNIException Throws exception on XNI error.
       * @exception java.io.IOException Throws exception on i/o error.
       */
      public void parse(XMLInputSource source) throws XNIException, IOException {
  
          if (fParseInProgress) {
              // REVISIT - need to add new error message
              throw new XNIException("FWK005 parse may not be called while parsing.");
          }
          fParseInProgress = true;
  
          try {
              setInputSource(source);
              parse(true);
          } 
          catch (XNIException ex) {
              if (PRINT_EXCEPTION_STACK_TRACE)
                  ex.printStackTrace();
              throw ex;
          } 
          catch (IOException ex) {
              if (PRINT_EXCEPTION_STACK_TRACE)
                  ex.printStackTrace();
              throw ex;
          }
          catch (RuntimeException ex) {
              if (PRINT_EXCEPTION_STACK_TRACE)
                  ex.printStackTrace();
              throw ex;
          }              
          catch (Exception ex) {
              if (PRINT_EXCEPTION_STACK_TRACE)
                  ex.printStackTrace();
              throw new XNIException(ex);
          }
          finally {
              fParseInProgress = false;
              // close all streams opened by xerces
              this.cleanup();
          }
  
      } // parse(InputSource)
  
      //
      // Protected methods
      //
      
      /** 
       * Reset all components before parsing. 
       *
       * @throws XNIException Thrown if an error occurs during initialization.
       */
      protected void reset() throws XNIException {
  
          // configure the pipeline and initialize the components
          configurePipeline();
          super.reset();
  
      } // reset()
  
      /** Configures the pipeline. */
      protected void configurePipeline() {
  
          // REVISIT: This should be better designed. In other words, we
          //          need to figure out what is the best way for people to
          //          re-use *most* of the standard configuration but do 
          //          things common things such as remove a component (e.g.
          //          the validator), insert a new component (e.g. XInclude), 
          //          etc... -Ac
  
          // setup document pipeline
          fScanner.setDocumentHandler(fNamespaceBinder);
          fNamespaceBinder.setDocumentHandler(fDocumentHandler);
          
  
          fLastComponent = fNamespaceBinder;
  
          // setup dtd pipeline
          if (fDTDScanner != null) {
                  fDTDScanner.setDTDHandler(fDTDHandler);
                  fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler);
          }
  
  
      } // configurePipeline()
  
      // features and properties
  
      /**
       * Check a feature. If feature is know and supported, this method simply
       * returns. Otherwise, the appropriate exception is thrown.
       *
       * @param featureId The unique identifier (URI) of the feature.
       *
       * @throws XMLConfigurationException Thrown for configuration error.
       *                                   In general, components should
       *                                   only throw this exception if
       *                                   it is <strong>really</strong>
       *                                   a critical error.
       */
      protected void checkFeature(String featureId)
          throws XMLConfigurationException {
  
          //
          // Xerces Features
          //
  
          if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
              String feature = featureId.substring(Constants.XERCES_FEATURE_PREFIX.length());
              //
              // http://apache.org/xml/features/validation/dynamic
              //   Allows the parser to validate a document only when it
              //   contains a grammar. Validation is turned on/off based
              //   on each document instance, automatically.
              //
              if (feature.equals(Constants.DYNAMIC_VALIDATION_FEATURE)) {
                  return;
              }
              //
              // http://apache.org/xml/features/validation/default-attribute-values
              //
              if (feature.equals(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
                  // REVISIT
                  short type = XMLConfigurationException.NOT_SUPPORTED;
                  throw new XMLConfigurationException(type, featureId);
              }
              //
              // http://apache.org/xml/features/validation/default-attribute-values
              //
              if (feature.equals(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
                  // REVISIT
                  short type = XMLConfigurationException.NOT_SUPPORTED;
                  throw new XMLConfigurationException(type, featureId);
              }
              //
              // http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
              //
              if (feature.equals(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
                  return;
              }
              //
              // http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
              //
              if (feature.equals(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
                  return;
              }
  
              //
              // http://apache.org/xml/features/validation/default-attribute-values
              //
              if (feature.equals(Constants.VALIDATE_DATATYPES_FEATURE)) {
                  short type = XMLConfigurationException.NOT_SUPPORTED;
                  throw new XMLConfigurationException(type, featureId);
              }
          }
  
          //
          // Not recognized
          //
  
          super.checkFeature(featureId);
  
      } // checkFeature(String)
  
      /**
       * Check a property. If the property is know and supported, this method
       * simply returns. Otherwise, the appropriate exception is thrown.
       *
       * @param propertyId The unique identifier (URI) of the property
       *                   being set.
       *
       * @throws XMLConfigurationException Thrown for configuration error.
       *                                   In general, components should
       *                                   only throw this exception if
       *                                   it is <strong>really</strong>
       *                                   a critical error.
       */
      protected void checkProperty(String propertyId)
          throws XMLConfigurationException {
  
          //
          // Xerces Properties
          //
  
          if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
              String property = propertyId.substring(Constants.XERCES_PROPERTY_PREFIX.length());
              if (property.equals(Constants.DTD_SCANNER_PROPERTY)) {
                  return;
              }
          }
  
          if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
              String property =
                  propertyId.substring(Constants.JAXP_PROPERTY_PREFIX.length());
              if (property.equals(Constants.SCHEMA_SOURCE)) {
                  return;
              }
          }
  
          //
          // Not recognized
          //
  
          super.checkProperty(propertyId);
  
      } // checkProperty(String)
  
      // factory methods
  
      /** Creates an entity manager. */
      protected XMLEntityManager createEntityManager() {
          return new XMLEntityManager();
      } // createEntityManager():XMLEntityManager
  
      /** Creates an error reporter. */
      protected XMLErrorReporter createErrorReporter() {
          return new XMLErrorReporter();
      } // createErrorReporter():XMLErrorReporter
  
      /** Create a document scanner. */
      protected XMLDocumentScanner createDocumentScanner() {
          return new XMLDocumentScannerImpl();
      } // createDocumentScanner():XMLDocumentScanner
  
      /** Create a DTD scanner. */
      protected XMLDTDScanner createDTDScanner() {
          return new XMLDTDScannerImpl();
      } // createDTDScanner():XMLDTDScanner
  
  
      /** Create a namespace binder. */
      protected XMLNamespaceBinder createNamespaceBinder() {
          return new XMLNamespaceBinder();
      } // createNamespaceBinder():XMLNamespaceBinder
  
      /** Create a datatype validator factory. */
      protected DTDDVFactory createDatatypeValidatorFactory() {
          return DTDDVFactory.getInstance();
      } // createDatatypeValidatorFactory():DatatypeValidatorFactory
      protected ValidationManager createValidationManager(){
          return new ValidationManager();
      }
  
  } // class NonValidatingConfiguration
  
  
  

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