cachingparserpool.java
来自「JAVA 所有包」· Java 代码 · 共 428 行 · 第 1/2 页
JAVA
428 行
// retrieve the initial set of grammars for the validator // to work with. // REVISIT: does this need to be synchronized since it's just reading? // @param grammarType type of the grammars to be retrieved. // @return the initial grammar set the validator may place in its "bucket" public Grammar [] retrieveInitialGrammarSet(String grammarType ) { synchronized (fGrammarPool) { return fGrammarPool.retrieveInitialGrammarSet(grammarType); } } // retrieveInitialGrammarSet(String): Grammar[] // retrieve a particular grammar. // REVISIT: does this need to be synchronized since it's just reading? // @param gDesc description of the grammar to be retrieved // @return Grammar corresponding to gDesc, or null if none exists. public Grammar retrieveGrammar(XMLGrammarDescription gDesc) { synchronized (fGrammarPool) { return fGrammarPool.retrieveGrammar(gDesc); } } // retrieveGrammar(XMLGrammarDesc): Grammar // give the grammarPool the option of caching these grammars. // This certainly must be synchronized. // @param grammarType The type of the grammars to be cached. // @param grammars the Grammars that may be cached (unordered, Grammars previously // given to the validator may be included). public void cacheGrammars(String grammarType, Grammar[] grammars) { synchronized (fGrammarPool) { 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) * grammarPool have been commented out. */ /** * Puts the specified grammar into the grammar pool. * * @param key Key to associate with grammar. * @param grammar Grammar object. */ /****** public void putGrammar(String key, Grammar grammar) { synchronized (fGrammarPool) { fGrammarPool.putGrammar(key, grammar); } } // putGrammar(String,Grammar) *******/ /** * Returns the grammar associated to the specified key. * * @param key The key of the grammar. */ /********** public Grammar getGrammar(String key) { synchronized (fGrammarPool) { return fGrammarPool.getGrammar(key); } } // getGrammar(String):Grammar ***********/ /** * Removes the grammar associated to the specified key from the * grammar pool and returns the removed grammar. * * @param key The key of the grammar. */ /********** public Grammar removeGrammar(String key) { synchronized (fGrammarPool) { return fGrammarPool.removeGrammar(key); } } // removeGrammar(String):Grammar ******/ /** * Returns true if the grammar pool contains a grammar associated * to the specified key. * * @param key The key of the grammar. */ /********** public boolean containsGrammar(String key) { synchronized (fGrammarPool) { return fGrammarPool.containsGrammar(key); } } // containsGrammar(String):boolean ********/ } // class SynchronizedGrammarPool /** * Shadowed grammar pool. * This class is predicated on the existence of a concrete implementation; * so using our own doesn't seem to bad an idea. * * @author Andy Clark, IBM * @author Neil Graham, IBM */ public static final class ShadowedGrammarPool extends XMLGrammarPoolImpl { // // Data // /** Main grammar pool. */ private XMLGrammarPool fGrammarPool; // // Constructors // /** Constructs a shadowed grammar pool. */ public ShadowedGrammarPool(XMLGrammarPool grammarPool) { fGrammarPool = grammarPool; } // <init>(GrammarPool) // // GrammarPool methods // /** * Retrieve the initial set of grammars for the validator to work with. * REVISIT: does this need to be synchronized since it's just reading? * * @param grammarType Type of the grammars to be retrieved. * @return The initial grammar set the validator may place in its "bucket" */ public Grammar [] retrieveInitialGrammarSet(String grammarType ) { Grammar [] grammars = super.retrieveInitialGrammarSet(grammarType); if (grammars != null) return grammars; return fGrammarPool.retrieveInitialGrammarSet(grammarType); } // retrieveInitialGrammarSet(String): Grammar[] /** * Retrieve a particular grammar. * REVISIT: does this need to be synchronized since it's just reading? * * @param gDesc Description of the grammar to be retrieved * @return Grammar corresponding to gDesc, or null if none exists. */ public Grammar retrieveGrammar(XMLGrammarDescription gDesc) { Grammar g = super.retrieveGrammar(gDesc); if(g != null) return g; return fGrammarPool.retrieveGrammar(gDesc); } // retrieveGrammar(XMLGrammarDesc): Grammar /** * Give the grammarPool the option of caching these grammars. * This certainly must be synchronized. * * @param grammarType The type of the grammars to be cached. * @param grammars The Grammars that may be cached (unordered, Grammars previously * given to the validator may be included). */ public void cacheGrammars(String grammarType, Grammar[] grammars) { // better give both grammars a shot... super.cacheGrammars(grammarType, grammars); fGrammarPool.cacheGrammars(grammarType, grammars); } // cacheGrammars(grammarType, Grammar[]); /** * Returns the grammar associated to the specified description. * * @param desc The description of the grammar. */ public Grammar getGrammar(XMLGrammarDescription desc) { if (super.containsGrammar(desc)) { return super.getGrammar(desc); } return null; } // getGrammar(XMLGrammarDescription):Grammar /** * Returns true if the grammar pool contains a grammar associated * to the specified description. * * @param desc The description of the grammar. */ public boolean containsGrammar(XMLGrammarDescription desc) { return super.containsGrammar(desc); } // containsGrammar(XMLGrammarDescription):boolean } // class ShadowedGrammarPool} // class CachingParserPool
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?