Package org.apache.xerces.util
Class XMLGrammarPoolImpl
java.lang.Object
org.apache.xerces.util.XMLGrammarPoolImpl
- All Implemented Interfaces:
org.apache.xerces.xni.grammars.XMLGrammarPool
- Direct Known Subclasses:
CachingParserPool.ShadowedGrammarPool,XSGrammarPool
public class XMLGrammarPoolImpl
extends Object
implements org.apache.xerces.xni.grammars.XMLGrammarPool
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.
- Version:
- $Id: XMLGrammarPoolImpl.java 447241 2006-09-18 05:12:57Z mrglavas $
- Author:
- Jeffrey Rodriguez, IBM, Andy Clark, IBM, Neil Graham, IBM, Pavani Mukthipudi, Sun Microsystems, Neeraj Bajaj, SUN Microsystems
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classThis class is a grammar pool entry. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected XMLGrammarPoolImpl.Entry[]Grammars.protected booleanprotected static final intDefault size. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a grammar pool with a default number of buckets.XMLGrammarPoolImpl(int initialCapacity) Constructs a grammar pool with a specified number of buckets. -
Method Summary
Modifier and TypeMethodDescriptionvoidcacheGrammars(String grammarType, org.apache.xerces.xni.grammars.Grammar[] grammars) return the final set of grammars that the validator ended up with.voidclear()Removes all grammars from the pool.booleancontainsGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) Returns true if the grammar pool contains a grammar associated to the specified grammar description.booleanequals(org.apache.xerces.xni.grammars.XMLGrammarDescription desc1, org.apache.xerces.xni.grammars.XMLGrammarDescription desc2) This method checks whether two grammars are the same.org.apache.xerces.xni.grammars.GrammargetGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) Returns the grammar associated to the specified grammar description.inthashCode(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) Returns the hash code value for the given grammar description.voidlockPool()Causes the XMLGrammarPool not to store any grammars when the cacheGrammars(String, Grammar[[]) method is called.voidputGrammar(org.apache.xerces.xni.grammars.Grammar grammar) Puts the specified grammar into the grammar pool and associates it to its root element name or its target namespace.org.apache.xerces.xni.grammars.GrammarremoveGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) Removes the grammar associated to the specified grammar description from the grammar pool and returns the removed grammar.org.apache.xerces.xni.grammars.GrammarretrieveGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) This method requests that the application retrieve a grammar corresponding to the given GrammarIdentifier from its cache.org.apache.xerces.xni.grammars.Grammar[]retrieveInitialGrammarSet(String grammarType) retrieve the initial known set of grammars.voidAllows the XMLGrammarPool to store grammars when its cacheGrammars(String, Grammar[]) method is called.
-
Field Details
-
TABLE_SIZE
protected static final int TABLE_SIZEDefault size.- See Also:
-
fGrammars
Grammars. -
fPoolIsLocked
protected boolean fPoolIsLocked -
fGrammarCount
protected int fGrammarCount
-
-
Constructor Details
-
XMLGrammarPoolImpl
public XMLGrammarPoolImpl()Constructs a grammar pool with a default number of buckets. -
XMLGrammarPoolImpl
public XMLGrammarPoolImpl(int initialCapacity) Constructs a grammar pool with a specified number of buckets.
-
-
Method Details
-
retrieveInitialGrammarSet
Description copied from interface:org.apache.xerces.xni.grammars.XMLGrammarPoolretrieve 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.
- Specified by:
retrieveInitialGrammarSetin interfaceorg.apache.xerces.xni.grammars.XMLGrammarPool- Parameters:
grammarType- the type of the grammar, from theorg.apache.xerces.xni.grammars.Grammarinterface.- Returns:
- the set of grammars the validator may put in its "bucket"
-
cacheGrammars
Description copied from interface:org.apache.xerces.xni.grammars.XMLGrammarPoolreturn 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.
- Specified by:
cacheGrammarsin interfaceorg.apache.xerces.xni.grammars.XMLGrammarPool- Parameters:
grammarType- the type of the grammars being returned;grammars- an array containing the set of grammars being returned; order is not significant.
-
retrieveGrammar
public org.apache.xerces.xni.grammars.Grammar retrieveGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) Description copied from interface:org.apache.xerces.xni.grammars.XMLGrammarPoolThis 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. An application must not call its EntityResolver itself from this method; this may result in infinite recursions.
- Specified by:
retrieveGrammarin interfaceorg.apache.xerces.xni.grammars.XMLGrammarPool- Parameters:
desc- The description of the Grammar being requested.- Returns:
- the Grammar corresponding to this description or null if no such Grammar is known.
-
putGrammar
public void putGrammar(org.apache.xerces.xni.grammars.Grammar grammar) Puts the specified grammar into the grammar pool and associates it to its root element name or its target namespace.- Parameters:
grammar- The Grammar.
-
getGrammar
public org.apache.xerces.xni.grammars.Grammar getGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) 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.- Parameters:
desc- The Grammar Description.
-
removeGrammar
public org.apache.xerces.xni.grammars.Grammar removeGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) 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.- Parameters:
desc- The Grammar Description.- Returns:
- The removed grammar.
-
containsGrammar
public boolean containsGrammar(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) 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.- Parameters:
desc- The Grammar Description.
-
lockPool
public void lockPool()Description copied from interface:org.apache.xerces.xni.grammars.XMLGrammarPoolCauses the XMLGrammarPool not to store any grammars when the cacheGrammars(String, Grammar[[]) method is called.- Specified by:
lockPoolin interfaceorg.apache.xerces.xni.grammars.XMLGrammarPool
-
unlockPool
public void unlockPool()Description copied from interface:org.apache.xerces.xni.grammars.XMLGrammarPoolAllows the XMLGrammarPool to store grammars when its cacheGrammars(String, Grammar[]) method is called. This is the default state of the object.- Specified by:
unlockPoolin interfaceorg.apache.xerces.xni.grammars.XMLGrammarPool
-
clear
public void clear()Description copied from interface:org.apache.xerces.xni.grammars.XMLGrammarPoolRemoves all grammars from the pool.- Specified by:
clearin interfaceorg.apache.xerces.xni.grammars.XMLGrammarPool
-
equals
public boolean equals(org.apache.xerces.xni.grammars.XMLGrammarDescription desc1, org.apache.xerces.xni.grammars.XMLGrammarDescription desc2) 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.- Parameters:
desc1- The grammar descriptiondesc2- The grammar description of the grammar to be compared to- Returns:
- True if the grammars are equal, otherwise false
-
hashCode
public int hashCode(org.apache.xerces.xni.grammars.XMLGrammarDescription desc) Returns the hash code value for the given grammar description.- Parameters:
desc- The grammar description- Returns:
- The hash code value
-