You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2002/05/16 21:56:11 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/util XMLGrammarPoolImpl.java

neilg       02/05/16 12:56:10

  Modified:    java/src/org/apache/xerces/xni/grammars XMLGrammarPool.java
               java/src/org/apache/xerces/parsers
                        XMLGrammarCachingConfiguration.java
                        CachingParserPool.java
                        NonValidatingConfiguration.java
                        DOMASBuilderImpl.java
               java/src/org/apache/xerces/impl/xs XMLSchemaValidator.java
  Added:       java/src/org/apache/xerces/util XMLGrammarPoolImpl.java
  Removed:     java/src/org/apache/xerces/impl/validation
                        XMLGrammarPoolImpl.java
  Log:
  first of the agreed-upon grammar preparsing framework changes that were discussed on xerces-j-dev in the last couple of months.  Here, I have moved XMLGrammarPoolImpl from impl/validation to util, where it will perhaps be more accessible to users.  I have also added three methods to the XMLGrammarPool interface for locking, unlocking and clearing grammar pools.
  
  Revision  Changes    Path
  1.2       +17 -1     xml-xerces/java/src/org/apache/xerces/xni/grammars/XMLGrammarPool.java
  
  Index: XMLGrammarPool.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xni/grammars/XMLGrammarPool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLGrammarPool.java	17 Jan 2002 23:54:59 -0000	1.1
  +++ XMLGrammarPool.java	16 May 2002 19:56:09 -0000	1.2
  @@ -79,7 +79,7 @@
    * it may return some grammars that were retrieved from the GrammarPool in earlier operations). </li> </ul> </p>
    *
    * @author Neil Graham, IBM
  - * @version $Id: XMLGrammarPool.java,v 1.1 2002/01/17 23:54:59 neilg Exp $
  + * @version $Id: XMLGrammarPool.java,v 1.2 2002/05/16 19:56:09 neilg Exp $
    */
   
   public interface XMLGrammarPool {
  @@ -118,5 +118,21 @@
       //  no such Grammar is known.
       public Grammar retrieveGrammar(XMLGrammarDescription desc);
   
  +    /*
  +     * Causes the XMLGrammarPool not to store any grammars when
  +     * the cacheGrammars(String, Grammar[[]) method is called.
  +     */
  +    public void lockPool();
  +
  +    /*
  +     * Allows the XMLGrammarPool to store grammars when its cacheGrammars(String, Grammar[])
  +     * method is called.  This is the default state of the object.
  +     */
  +    public void unlockPool();
  +
  +    /*
  +     * Removes all grammars from the pool.
  +     */
  +    public void clear();
   } // XMLGrammarPool
   
  
  
  
  1.8       +14 -41    xml-xerces/java/src/org/apache/xerces/parsers/XMLGrammarCachingConfiguration.java
  
  Index: XMLGrammarCachingConfiguration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/XMLGrammarCachingConfiguration.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLGrammarCachingConfiguration.java	27 Mar 2002 20:32:26 -0000	1.7
  +++ XMLGrammarCachingConfiguration.java	16 May 2002 19:56:09 -0000	1.8
  @@ -63,7 +63,7 @@
   import org.apache.xerces.xni.grammars.XMLGrammarPool;
   import org.apache.xerces.xni.grammars.XMLGrammarDescription;
   import org.apache.xerces.xni.grammars.Grammar;
  -import org.apache.xerces.impl.validation.XMLGrammarPoolImpl;
  +import org.apache.xerces.util.XMLGrammarPoolImpl;
   import org.apache.xerces.impl.xs.traversers.XSDHandler;
   import org.apache.xerces.impl.xs.models.CMBuilder;
   import org.apache.xerces.impl.xs.SchemaSymbols;
  @@ -104,7 +104,7 @@
    *
    * @author Neil Graham, IBM
    *
  - * @version $Id: XMLGrammarCachingConfiguration.java,v 1.7 2002/03/27 20:32:26 neilg Exp $
  + * @version $Id: XMLGrammarCachingConfiguration.java,v 1.8 2002/05/16 19:56:09 neilg Exp $
    */
   public class XMLGrammarCachingConfiguration 
       extends StandardParserConfiguration {
  @@ -226,53 +226,26 @@
   
       /*
        * lock the XMLGrammarPoolImpl object so that it does not
  -     * accept any more grammars from the validators.  This isn't
  -     * a part of the XMLGrammarPool interface, so this method
  -     * returns true if the operation succeeded, false otherwise
  -     * (i.e., the grammar pool isn't our XMLGrammarPoolImpl)
  -     * @return:  true on success, false on failure
  -     */
  -    public boolean lockGrammarPool() {
  -        if(fGrammarPool instanceof org.apache.xerces.impl.validation.XMLGrammarPoolImpl) {
  -            // call appropriate method on class
  -            ((org.apache.xerces.impl.validation.XMLGrammarPoolImpl)fGrammarPool).lockPool();
  -            return true;
  -        }
  -        return false;
  +     * accept any more grammars from the validators.  
  +     */
  +    public void lockGrammarPool() {
  +        fGrammarPool.lockPool();
       } // lockGrammarPool()
   
       /*
        * clear the XMLGrammarPoolImpl object so that it does not
  -     * contain any more grammars.  This isn't
  -     * a part of the XMLGrammarPool interface, so this method
  -     * returns true if the operation succeeded, false otherwise
  -     * (i.e., the grammar pool isn't our XMLGrammarPoolImpl or descended from it)
  -     * @return:  true on success, false on failure
  -     */
  -    public boolean clearGrammarPool() {
  -        if(fGrammarPool instanceof org.apache.xerces.impl.validation.XMLGrammarPoolImpl) {
  -            // call appropriate method on class
  -            ((org.apache.xerces.impl.validation.XMLGrammarPoolImpl)fGrammarPool).clear();
  -            return true;
  -        }
  -        return false;
  +     * contain any more grammars.  
  +     */
  +    public void clearGrammarPool() {
  +        fGrammarPool.clear();
       } // clearGrammarPool()
   
       /*
        * unlock the XMLGrammarPoolImpl object so that it  
  -     * accepts more grammars from the validators.  This isn't
  -     * a part of the XMLGrammarPool interface, so this method
  -     * returns true if the operation succeeded, false otherwise
  -     * (i.e., the grammar pool isn't our XMLGrammarPoolImpl)
  -     * @return:  true on success, false on failure
  -     */
  -    public boolean unlockGrammarPool() {
  -        if(fGrammarPool instanceof org.apache.xerces.impl.validation.XMLGrammarPoolImpl) {
  -            // call appropriate method on class
  -            ((org.apache.xerces.impl.validation.XMLGrammarPoolImpl)fGrammarPool).unlockPool();
  -            return true;
  -        }
  -        return false;
  +     * accepts more grammars from the validators.  
  +     */
  +    public void unlockGrammarPool() {
  +        fGrammarPool.unlockPool();
       } // unlockGrammarPool()
   
       /**
  
  
  
  1.10      +23 -2     xml-xerces/java/src/org/apache/xerces/parsers/CachingParserPool.java
  
  Index: CachingParserPool.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/CachingParserPool.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CachingParserPool.java	19 Feb 2002 21:03:39 -0000	1.9
  +++ CachingParserPool.java	16 May 2002 19:56:09 -0000	1.10
  @@ -60,7 +60,7 @@
   import org.apache.xerces.xni.grammars.Grammar;
   import org.apache.xerces.xni.grammars.XMLGrammarPool;
   import org.apache.xerces.xni.grammars.XMLGrammarDescription;
  -import org.apache.xerces.impl.validation.XMLGrammarPoolImpl;
  +import org.apache.xerces.util.XMLGrammarPoolImpl;
   
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.util.SynchronizedSymbolTable;
  @@ -94,7 +94,7 @@
    *
    * @author Andy Clark, IBM
    *
  - * @version $Id: CachingParserPool.java,v 1.9 2002/02/19 21:03:39 neeraj Exp $
  + * @version $Id: CachingParserPool.java,v 1.10 2002/05/16 19:56:09 neilg Exp $
    */
   public class CachingParserPool {
   
  @@ -377,6 +377,27 @@
                   fGrammarPool.cacheGrammars(grammarType, grammars);
               }
           } // cacheGrammars(String, Grammar[]);
  +
  +        /** lock the grammar pool */
  +        public void lockPool() {
  +            synchronized (fGrammarPool) {
  +                fGrammarPool.lockPool();
  +            }
  +        } // lockPool()
  +
  +        /** clear the grammar pool */
  +        public void clear() {
  +            synchronized (fGrammarPool) {
  +                fGrammarPool.clear();
  +            }
  +        } // lockPool()
  +
  +        /** unlock the grammar pool */
  +        public void unlockPool() {
  +            synchronized (fGrammarPool) {
  +                fGrammarPool.unlockPool();
  +            }
  +        } // unlockPool()
   
           /***
            * Methods corresponding to original (pre Xerces2.0.0final)
  
  
  
  1.2       +2 -2      xml-xerces/java/src/org/apache/xerces/parsers/NonValidatingConfiguration.java
  
  Index: NonValidatingConfiguration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/NonValidatingConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NonValidatingConfiguration.java	3 Apr 2002 23:48:27 -0000	1.1
  +++ NonValidatingConfiguration.java	16 May 2002 19:56:09 -0000	1.2
  @@ -70,7 +70,7 @@
   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.XMLGrammarPoolImpl;
   
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.xni.XMLLocator;
  @@ -89,7 +89,7 @@
    * 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 $
  + * @version $Id: NonValidatingConfiguration.java,v 1.2 2002/05/16 19:56:09 neilg Exp $
    */
   public class NonValidatingConfiguration
       extends BasicParserConfiguration 
  
  
  
  1.17      +2 -2      xml-xerces/java/src/org/apache/xerces/parsers/DOMASBuilderImpl.java
  
  Index: DOMASBuilderImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMASBuilderImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DOMASBuilderImpl.java	11 Apr 2002 20:14:54 -0000	1.16
  +++ DOMASBuilderImpl.java	16 May 2002 19:56:09 -0000	1.17
  @@ -74,7 +74,7 @@
   
   import org.apache.xerces.impl.Constants;
   import org.apache.xerces.impl.XMLErrorReporter;
  -import org.apache.xerces.impl.validation.XMLGrammarPoolImpl;
  +import org.apache.xerces.util.XMLGrammarPoolImpl;
   import org.apache.xerces.impl.xs.traversers.XSDHandler;
   import org.apache.xerces.impl.xs.XSDDescription;
   import org.apache.xerces.impl.xs.XSGrammarBucket;
  @@ -93,7 +93,7 @@
    *
    * @author Pavani Mukthipudi, Sun Microsystems Inc.
    * @author Neil Graham, IBM
  - * @version $Id: DOMASBuilderImpl.java,v 1.16 2002/04/11 20:14:54 sandygao Exp $
  + * @version $Id: DOMASBuilderImpl.java,v 1.17 2002/05/16 19:56:09 neilg Exp $
    *
    */
   
  
  
  
  1.63      +2 -2      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.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- XMLSchemaValidator.java	16 May 2002 18:25:54 -0000	1.62
  +++ XMLSchemaValidator.java	16 May 2002 19:56:10 -0000	1.63
  @@ -64,7 +64,7 @@
   import org.apache.xerces.impl.xs.identity.*;
   import org.apache.xerces.impl.Constants;
   import org.apache.xerces.impl.validation.ValidationManager;
  -import org.apache.xerces.impl.validation.XMLGrammarPoolImpl;
  +import org.apache.xerces.util.XMLGrammarPoolImpl;
   import org.apache.xerces.impl.XMLErrorReporter;
   import org.apache.xerces.impl.xs.traversers.XSDHandler;
   import org.apache.xerces.impl.xs.traversers.XSAttributeChecker;
  @@ -142,7 +142,7 @@
    * @author Elena Litani IBM
    * @author Andy Clark IBM
    * @author Neeraj Bajaj, Sun Microsystems, inc.
  - * @version $Id: XMLSchemaValidator.java,v 1.62 2002/05/16 18:25:54 sandygao Exp $
  + * @version $Id: XMLSchemaValidator.java,v 1.63 2002/05/16 19:56:10 neilg Exp $
    */
   public class XMLSchemaValidator
                implements XMLComponent, XMLDocumentFilter, FieldActivator {
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/util/XMLGrammarPoolImpl.java
  
  Index: XMLGrammarPoolImpl.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-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.util;
  
  import org.apache.xerces.xni.grammars.Grammar;
  import org.apache.xerces.xni.grammars.XMLGrammarPool;
  import org.apache.xerces.xni.grammars.XMLGrammarDescription;
  
  import org.apache.xerces.impl.dtd.XMLDTDDescription;
  import org.apache.xerces.impl.xs.XSDDescription;
  
  import java.util.Hashtable;
  import java.util.Enumeration;
  
  /**
   * Stores grammars in a pool associated to a specific key. This grammar pool
   * implementation stores two types of grammars: those keyed by the root element
   * name, and those keyed by the grammar's target namespace.
   *
   * This is the default implementation of the GrammarPool interface.  
   * As we move forward, this will become more function-rich and robust.
   *
   * @author Jeffrey Rodriguez, IBM
   * @author Andy Clark, IBM
   * @author Neil Graham, IBM
   * @author Pavani Mukthipudi, Sun Microsystems
   * @author Neeraj Bajaj, SUN Microsystems
   *
   * @version $Id: XMLGrammarPoolImpl.java,v 1.1 2002/05/16 19:56:10 neilg Exp $
   */
  public class XMLGrammarPoolImpl implements XMLGrammarPool {
  
      // 
      // Constants
      // 
      
      /** Default size. */
      protected static final int TABLE_SIZE = 11;
  
      //
      // Data
      //
      
      /** Grammars. */
      protected Entry[] fGrammars = null;
      
      // whether this pool is locked
      protected boolean fPoolIsLocked;
  
      private static final boolean DEBUG = false ;
  	
      //
      // Constructors
      //
  
      /** Constructs a grammar pool with a default number of buckets. */
      public XMLGrammarPoolImpl() {
      	fGrammars = new Entry[TABLE_SIZE];
          fPoolIsLocked = false;
      } // <init>()
      
      /** Constructs a grammar pool with a specified number of buckets. */
      public XMLGrammarPoolImpl(int initialCapacity) {
          fGrammars = new Entry[initialCapacity];
          fPoolIsLocked = false;
      }
  
      //
      // XMLGrammarPool methods
      //
      
      /* <p> Retrieve the initial known set of grammars. This method is
       * called by a validator before the validation starts. The application 
       * can provide an initial set of grammars available to the current 
       * validation attempt. </p>
       * 
       * @param grammarType The type of the grammar, from the
       *  		  <code>org.apache.xerces.xni.grammars.XMLGrammarDescription</code> 
       *  		  interface.
       * @return 		  The set of grammars the validator may put in its "bucket"
       */
      public Grammar [] retrieveInitialGrammarSet (String grammarType) {
          synchronized (fGrammars) {
              int grammarSize = fGrammars.length ;
              Grammar [] tempGrammars = new Grammar[grammarSize];
              int pos = 0;
              for (int i = 0; i < grammarSize; i++) {
                  for (Entry e = fGrammars[i]; e != null; e = e.next) {
                      if (e.desc.getGrammarType().equals(grammarType)) {
                          tempGrammars[pos++] = e.grammar;
                      }
                  }
              }
              Grammar[] toReturn = new Grammar[pos];
              System.arraycopy(tempGrammars, 0, toReturn, 0, pos);
              return toReturn;
          }
      } // retrieveInitialGrammarSet (String): Grammar[]
  
      /* <p> Return the final set of grammars that the validator ended up
       * with. This method is called after the validation finishes. The 
       * application may then choose to cache some of the returned grammars.</p>
       * <p>In this implementation, we make our choice based on whether this object
       * is "locked"--that is, whether the application has instructed
       * us not to accept any new grammars.</p>
       *
       * @param grammarType The type of the grammars being returned;
       * @param grammars 	  An array containing the set of grammars being
       *  		  returned; order is not significant.
       */
      public void cacheGrammars(String grammarType, Grammar[] grammars) {
          if(!fPoolIsLocked) {
      	    for (int i = 0; i < grammars.length; i++) {
                  if(DEBUG) {
      	            System.out.println("CACHED GRAMMAR " + (i+1) ) ;
      	            Grammar temp = grammars[i] ;
      	            print(temp.getGrammarDescription());
                  }
      	        putGrammar(grammars[i]);
              }
      	}
      } // cacheGrammars(String, Grammar[]);
      
      /* <p> This method requests that the application retrieve a grammar
       * corresponding to the given GrammarIdentifier from its cache.
       * If it cannot do so it must return null; the parser will then
       * call the EntityResolver. </p>
       * <strong>An application must not call its EntityResolver itself 
       * from this method; this may result in infinite recursions.</strong>
       * 
       * This implementation chooses to use the root element name to identify a DTD grammar
       * and the target namespace to identify a Schema grammar.
       * 
       * @param desc The description of the Grammar being requested.
       * @return     The Grammar corresponding to this description or null if
       *  	   no such Grammar is known.
       */
      public Grammar retrieveGrammar(XMLGrammarDescription desc) {
          if(DEBUG){
              System.out.println("RETRIEVING GRAMMAR FROM THE APPLICATION WITH FOLLOWING DESCRIPTION :");
              print(desc);
          }
          return getGrammar(desc);
      } // retrieveGrammar(XMLGrammarDescription):  Grammar
  
      //
      // Public methods
      //
  
      /**
       * Puts the specified grammar into the grammar pool and associates it to
       * its root element name or its target namespace.
       *
       * @param grammar The Grammar.
       */
      public void putGrammar(Grammar grammar) {
          if(!fPoolIsLocked) {
              synchronized (fGrammars) {
                  XMLGrammarDescription desc = grammar.getGrammarDescription();
                  int hash = hashCode(desc);
                  int index = (hash & 0x7FFFFFFF) % fGrammars.length;
                  for (Entry entry = fGrammars[index]; entry != null; entry = entry.next) {
                      if (entry.hash == hash && equals(entry.desc, desc)) {
                          entry.grammar = grammar;
                          return;
                      }
                  }
                  // create a new entry
                  Entry entry = new Entry(hash, desc, grammar, fGrammars[index]);
                  fGrammars[index] = entry;
              }
          }
      } // putGrammar(Grammar)
  
      /**
       * Returns the grammar associated to the specified grammar description.
       * Currently, the root element name is used as the key for DTD grammars 
       * and the target namespace  is used as the key for Schema grammars.
       *
       * @param desc The Grammar Description.
       */
      public Grammar getGrammar(XMLGrammarDescription desc) {
          synchronized (fGrammars) {
              int hash = hashCode(desc);
  	    int index = (hash & 0x7FFFFFFF) % fGrammars.length;
  	    for (Entry entry = fGrammars[index] ; entry != null ; entry = entry.next) {
  	        if ((entry.hash == hash) && equals(entry.desc, desc)) {
  	            return entry.grammar;
  	        }
  	    }
  	    return null;
  	}
      } // getGrammar(XMLGrammarDescription):Grammar
  
      /**
       * Removes the grammar associated to the specified grammar description from the
       * grammar pool and returns the removed grammar. Currently, the root element name 
       * is used as the key for DTD grammars and the target namespace  is used 
       * as the key for Schema grammars.
       * 
       * @param desc The Grammar Description.
       * @return     The removed grammar.
       */
      public Grammar removeGrammar(XMLGrammarDescription desc) {
          synchronized (fGrammars) {
      	    int hash = hashCode(desc);
  	    int index = (hash & 0x7FFFFFFF) % fGrammars.length;
  	    for (Entry entry = fGrammars[index], prev = null ; entry != null ; prev = entry, entry = entry.next) {
  	        if ((entry.hash == hash) && equals(entry.desc, desc)) {
  	            if (prev != null) {
                          prev.next = entry.next;
  		    } 
  		    else {
  		        fGrammars[index] = entry.next;
  		    }
  	    	    Grammar tempGrammar = entry.grammar;
  	    	    entry.grammar = null;
  	            return tempGrammar;
  	        }
  	    }
  	    return null;
          }
      } // removeGrammar(XMLGrammarDescription):Grammar
  
      /**
       * Returns true if the grammar pool contains a grammar associated
       * to the specified grammar description. Currently, the root element name 
       * is used as the key for DTD grammars and the target namespace  is used 
       * as the key for Schema grammars.
       *
       * @param desc The Grammar Description.
       */
      public boolean containsGrammar(XMLGrammarDescription desc) {
          synchronized (fGrammars) {
      	    int hash = hashCode(desc);
  	    int index = (hash & 0x7FFFFFFF) % fGrammars.length;
  	    for (Entry entry = fGrammars[index] ; entry != null ; entry = entry.next) {
  	        if ((entry.hash == hash) && equals(entry.desc, desc)) {
  	            return true;
  	        }
  	    }
  	    return false;
  	}
      } // containsGrammar(XMLGrammarDescription):boolean
  
      /* <p> Sets this grammar pool to a "locked" state--i.e.,
       * no new grammars will be added until it is "unlocked".
       */
      public void lockPool() {
          fPoolIsLocked = true;
      } // lockPool()
  
      /* <p> Sets this grammar pool to an "unlocked" state--i.e.,
       * new grammars will be added when putGrammar or cacheGrammars 
       * are called.
       */
      public void unlockPool() {
          fPoolIsLocked = false;
      } // unlockPool()
  
      /* 
       * <p>This method clears the pool-i.e., removes references
       * to all the grammars in it.</p>
       */
      public void clear() {
          for (int i=0; i<fGrammars.length; i++) {
              if(fGrammars[i] != null) {
                  fGrammars[i].clear();
                  fGrammars[i] = null;
              }
          }
      } // clear()
  
      /**
       * This method checks whether two grammars are the same. Currently, we compare 
       * the root element names for DTD grammars and the target namespaces for Schema grammars.
       * The application can override this behaviour and add its own logic.
       *
       * @param gDesc1 The grammar description
       * @param gDesc2 The grammar description of the grammar to be compared to
       * @return       True if the grammars are equal, otherwise false
       */
      public boolean equals(XMLGrammarDescription desc1, XMLGrammarDescription desc2) {
          return desc1.equals(desc2);
      }
      
      /**
       * Returns the hash code value for the given grammar description.
       *
       * @param desc The grammar description
       * @return     The hash code value
       */
      public int hashCode(XMLGrammarDescription desc) {
          return desc.hashCode();
      }
      
      /**
       * This class is a grammar pool entry. Each entry acts as a node
       * in a linked list.
       */
      protected static final class Entry {
          public int hash;
          public XMLGrammarDescription desc;
          public Grammar grammar;
          public Entry next;
  	
          protected Entry(int hash, XMLGrammarDescription desc, Grammar grammar, Entry next) {
              this.hash = hash;
              this.desc = desc;
              this.grammar = grammar;
              this.next = next;
          }
  
          // clear this entry; useful to promote garbage collection
          // since reduces reference count of objects to be destroyed
          protected void clear () {
              desc = null;
              grammar = null;
              if(next != null) {
                  next.clear();
                  next = null;
              }
          } // clear()
      } // class Entry
      
      /* This is just for testing */
      public void print(XMLGrammarDescription description){
      	if(description.getGrammarType().equals(XMLGrammarDescription.XML_DTD)){
      	
      	}
      	else if(description.getGrammarType().equals(XMLGrammarDescription.XML_SCHEMA)){
      		XSDDescription schema = (XSDDescription)description ;
      		System.out.println("Context = " + schema.getContextType());
      		System.out.println("TargetNamespace = " + schema.getTargetNamespace());
      		String [] temp = schema.getLocationHints();
      		
      		for (int i = 0 ; (temp != null && i < temp.length) ; i++){
      			System.out.println("LocationHint " + i + " = "+ temp[i]);
      		}
      		    		
      		System.out.println("Triggering Component = " + schema.getTriggeringComponent());
      		System.out.println("EnclosingElementName =" + schema.getEnclosingElementName());
      	
      	}
      
      }//print
      
  } // class XMLGrammarPoolImpl
  
  
  

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