001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.xerces.xni.grammars;
018:
019: /**
020: * <p> This interface specifies how the parser and the application
021: * interact with respect to Grammar objects that the application
022: * possesses--either by having precompiled them or by having stored them
023: * from a previous validation of an instance document. It makes no
024: * assumptions about the kind of Grammar involved, or about how the
025: * application's storage mechanism works.</p>
026: *
027: * <p>The interaction works as follows:
028: * <ul>
029: * <li>When a validator considers a document, it is expected to request
030: * grammars of the type it can handle from this object using the
031: * <code>retrieveInitialGrammarSet</code> method. </li>
032: * <li>If it requires a grammar
033: * not in this set, it will request it from this Object using the
034: * <code>retrieveGrammar</code> method. </li>
035: * <li> After successfully validating an
036: * instance, the validator should make any new grammars it has compiled
037: * available to this object using the <code>cacheGrammars</code>
038: * method; for ease of implementation it may make other Grammars it holds references to as well (i.e.,
039: * it may return some grammars that were retrieved from the GrammarPool in earlier operations). </li> </ul> </p>
040: *
041: * @author Neil Graham, IBM
042: * @version $Id: XMLGrammarPool.java 447245 2006-09-18 05:22:10Z mrglavas $
043: */
044:
045: public interface XMLGrammarPool {
046:
047: // <p>we are trying to make this XMLGrammarPool work for all kinds of
048: // grammars, so we have a parameter "grammarType" for each of the
049: // methods. </p>
050:
051: /**
052: * <p> retrieve the initial known set of grammars. this method is
053: * called by a validator before the validation starts. the application
054: * can provide an initial set of grammars available to the current
055: * validation attempt. </p>
056: * @param grammarType the type of the grammar, from the
057: * <code>org.apache.xerces.xni.grammars.Grammar</code> interface.
058: * @return the set of grammars the validator may put in its "bucket"
059: */
060: public Grammar[] retrieveInitialGrammarSet(String grammarType);
061:
062: /**
063: * <p>return the final set of grammars that the validator ended up
064: * with.
065: * This method is called after the
066: * validation finishes. The application may then choose to cache some
067: * of the returned grammars. </p>
068: * @param grammarType the type of the grammars being returned;
069: * @param grammars an array containing the set of grammars being
070: * returned; order is not significant.
071: */
072: public void cacheGrammars(String grammarType, Grammar[] grammars);
073:
074: /**
075: * <p> This method requests that the application retrieve a grammar
076: * corresponding to the given GrammarIdentifier from its cache.
077: * If it cannot do so it must return null; the parser will then
078: * call the EntityResolver. <strong>An application must not call its
079: * EntityResolver itself from this method; this may result in infinite
080: * recursions.</strong>
081: * @param desc The description of the Grammar being requested.
082: * @return the Grammar corresponding to this description or null if
083: * no such Grammar is known.
084: */
085: public Grammar retrieveGrammar(XMLGrammarDescription desc);
086:
087: /**
088: * Causes the XMLGrammarPool not to store any grammars when
089: * the cacheGrammars(String, Grammar[[]) method is called.
090: */
091: public void lockPool();
092:
093: /**
094: * Allows the XMLGrammarPool to store grammars when its cacheGrammars(String, Grammar[])
095: * method is called. This is the default state of the object.
096: */
097: public void unlockPool();
098:
099: /**
100: * Removes all grammars from the pool.
101: */
102: public void clear();
103: } // XMLGrammarPool
|