Once the caching parser pool is constructed, specific parser instances are created by calling the appropriate factory method on the parser pool.
Note
There is a performance penalty for using a caching parser pool due to thread safety. Access to the symbol table and grammar pool must be synchronized to ensure the safe operation of the symbol table and grammar pool.
Note
If performance is critical, then another mechanism needs to be used instead of the caching parser pool. One approach would be to create parser instances that do not share these structures. Instead, each instance would get its own copy to use while parsing. This avoids the synchronization overhead at the expense of more memory and the time required to copy the structures for each new parser instance. And even when a parser instance is re-used, there is a potential for a memory leak due to new symbols being added to the symbol table over time. In other words, always take caution to make sure that your application is thread-safe and avoids leaking memory.
| Modifier and Type | Class and Description |
|---|---|
| public static class | CachingParserPool.ShadowedGrammarPool
Shadowed grammar pool. |
| public static class | CachingParserPool.SynchronizedGrammarPool
Synchronized grammar pool. |
| Modifier and Type | Field and Description |
|---|---|
| public static final boolean | DEFAULT_SHADOW_GRAMMAR_POOL
Default shadow grammar pool (false). |
| public static final boolean | DEFAULT_SHADOW_SYMBOL_TABLE
Default shadow symbol table (false). |
| protected boolean | fShadowGrammarPool
Shadow the grammar pool for new parser instances. |
| protected boolean | fShadowSymbolTable
Shadow the symbol table for new parser instances. |
| protected XMLGrammarPool | fSynchronizedGrammarPool
Grammar pool. |
| protected SymbolTable | fSynchronizedSymbolTable
Symbol table. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | CachingParserPool(SymbolTable
The symbol table. symbolTable, XMLGrammarPool The grammar pool. grammarPool)Constructs a caching parser pool with the specified symbol table and grammar pool. |
| Modifier and Type | Method and Description |
|---|---|
| public DOMParser | |
| public SAXParser | createSAXParser()
Deprecated
as a consequence of
Creates a new SAX parser.
SAXParser being deprecated.
|
| public SymbolTable | |
| public XMLGrammarPool | |
| public void | setShadowSymbolTable(boolean
If true, new parser instances use shadow copies
of the main symbol table and are not allowed to
add new symbols to the main symbol table. New
symbols are added to the shadow symbol table and
are local to the parser instance. If false, new
parser instances are allowed to add new symbols
to the main symbol table. shadow)Sets whether new parser instance receive shadow copies of the main symbol table. |
| DEFAULT_SHADOW_GRAMMAR_POOL | back to summary |
|---|---|
| public static final boolean DEFAULT_SHADOW_GRAMMAR_POOL Default shadow grammar pool (false). | |
| DEFAULT_SHADOW_SYMBOL_TABLE | back to summary |
|---|---|
| public static final boolean DEFAULT_SHADOW_SYMBOL_TABLE Default shadow symbol table (false). | |
| fShadowGrammarPool | back to summary |
|---|---|
| protected boolean fShadowGrammarPool Shadow the grammar pool for new parser instances. If true, new parser instances use shadow copies of the main grammar pool and are not allowed to add new grammars to the main grammar pool. New grammars are added to the shadow grammar pool and are local to the parser instance. | |
| fShadowSymbolTable | back to summary |
|---|---|
| protected boolean fShadowSymbolTable Shadow the symbol table for new parser instances. If true, new parser instances use shadow copies of the main symbol table and are not allowed to add new symbols to the main symbol table. New symbols are added to the shadow symbol table and are local to the parser instance. | |
| fSynchronizedGrammarPool | back to summary |
|---|---|
| protected XMLGrammarPool fSynchronizedGrammarPool Grammar pool. The grammar pool that the caching parser pool is constructed with is automatically wrapped in a synchronized version for thread-safety. | |
| fSynchronizedSymbolTable | back to summary |
|---|---|
| protected SymbolTable fSynchronizedSymbolTable Symbol table. The symbol table that the caching parser pool is constructed with is automatically wrapped in a synchronized version for thread-safety. | |
| CachingParserPool | back to summary |
|---|---|
| public CachingParserPool() Default constructor. | |
| CachingParserPool | back to summary |
|---|---|
| public CachingParserPool(SymbolTable symbolTable, XMLGrammarPool grammarPool) Constructs a caching parser pool with the specified symbol table and grammar pool.
| |
| createDOMParser | back to summary |
|---|---|
| public DOMParser createDOMParser() Creates a new DOM parser. | |
| createSAXParser | back to summary |
|---|---|
| public SAXParser createSAXParser()
Deprecated as a consequence of Creates a new SAX parser. | |
| getSymbolTable | back to summary |
|---|---|
| public SymbolTable getSymbolTable() Returns the symbol table. | |
| getXMLGrammarPool | back to summary |
|---|---|
| public XMLGrammarPool getXMLGrammarPool() Returns the grammar pool. | |
| setShadowSymbolTable | back to summary |
|---|---|
| public void setShadowSymbolTable(boolean shadow) Sets whether new parser instance receive shadow copies of the main symbol table.
| |
| Modifier and Type | Field and Description |
|---|---|
| private XMLGrammarPool | fGrammarPool
Main grammar pool. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | cacheGrammars(String
The type of the grammars to be cached. grammarType, Grammar[] The Grammars that may be cached (unordered, Grammars previously
given to the validator may be included). grammars)Overrides org. Implements org. |
| public boolean | containsGrammar(XMLGrammarDescription
The description of the grammar. desc)Overrides org. |
| public Grammar | getGrammar(XMLGrammarDescription
The description of the grammar. desc)Overrides org. |
| public Grammar | Returns: Grammar corresponding to gDesc, or null if none exists.Description of the grammar to be retrieved gDesc)Overrides org. Implements org. |
| public Grammar[] | Returns: The initial grammar set the validator may place in its "bucket"Type of the grammars to be retrieved. grammarType)Overrides org. Implements org. |
| fGrammarPool | back to summary |
|---|---|
| private XMLGrammarPool fGrammarPool Main grammar pool. | |
| ShadowedGrammarPool | back to summary |
|---|---|
| public ShadowedGrammarPool(XMLGrammarPool grammarPool) Constructs a shadowed grammar pool. | |
| cacheGrammars | back to summary |
|---|---|
| public void cacheGrammars(String grammarType, Grammar[] grammars) Overrides org. Implements org. Give the grammarPool the option of caching these grammars. This certainly must be synchronized. | |
| containsGrammar | back to summary |
|---|---|
| public boolean containsGrammar(XMLGrammarDescription desc) Overrides org. Returns true if the grammar pool contains a grammar associated to the specified description.
| |
| getGrammar | back to summary |
|---|---|
| public Grammar getGrammar(XMLGrammarDescription desc) Overrides org. Returns the grammar associated to the specified description.
| |
| retrieveGrammar | back to summary |
|---|---|
| public Grammar retrieveGrammar(XMLGrammarDescription gDesc) Overrides org. Implements org. Retrieve a particular grammar. REVISIT: does this need to be synchronized since it's just reading?
| |
| retrieveInitialGrammarSet | back to summary |
|---|---|
| public Grammar[] retrieveInitialGrammarSet(String grammarType) Overrides org. Implements org. Retrieve the initial set of grammars for the validator to work with. REVISIT: does this need to be synchronized since it's just reading? | |
| Modifier and Type | Field and Description |
|---|---|
| private XMLGrammarPool | fGrammarPool
Main grammar pool. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | cacheGrammars(String
the type of the grammars being returned; grammarType, Grammar[] an array containing the set of grammars being
returned; order is not significant. grammars)Implements org. return the final set of grammars that the validator ended up with. |
| public void | |
| public void | |
| public Grammar | retrieveGrammar(XMLGrammarDescription
The description of the Grammar being requested. gDesc)Implements org. This method requests that the application retrieve a grammar corresponding to the given GrammarIdentifier from its cache. |
| public Grammar[] | retrieveInitialGrammarSet(String
the type of the grammar, from the
grammarType)org.apache.xerces.xni.grammars.Grammar interface.Implements org. retrieve the initial known set of grammars. |
| public void | unlockPool()
Implements org. |
| fGrammarPool | back to summary |
|---|---|
| private XMLGrammarPool fGrammarPool Main grammar pool. | |
| SynchronizedGrammarPool | back to summary |
|---|---|
| public SynchronizedGrammarPool(XMLGrammarPool grammarPool) Constructs a synchronized grammar pool. | |
| cacheGrammars | back to summary |
|---|---|
| public void cacheGrammars(String grammarType, Grammar[] grammars) Implements org. Doc from org. 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. | |
| clear | back to summary |
|---|---|
| public void clear() Implements org. clear the grammar pool | |
| lockPool | back to summary |
|---|---|
| public void lockPool() Implements org. lock the grammar pool | |
| retrieveGrammar | back to summary |
|---|---|
| public Grammar retrieveGrammar(XMLGrammarDescription gDesc) Implements org. Doc from org. 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. An application must not call its EntityResolver itself from this method; this may result in infinite recursions.
| |
| retrieveInitialGrammarSet | back to summary |
|---|---|
| public Grammar[] retrieveInitialGrammarSet(String grammarType) Implements org. Doc from org. 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. | |
| unlockPool | back to summary |
|---|---|
| public void unlockPool() Implements org. unlock the grammar pool | |