View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2000-2002,2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package com.sun.org.apache.xerces.internal.xni.grammars;
21  
22  /**
23   * <p> This interface specifies how the parser and the application
24   * interact with respect to Grammar objects that the application
25   * possesses--either by having precompiled them or by having stored them
26   * from a previous validation of an instance document.  It makes no
27   * assumptions about the kind of Grammar involved, or about how the
28   * application's storage mechanism works.</p>
29   *
30   * <p>The interaction works as follows:
31   * <ul>
32   * <li>When a validator considers a document, it is expected to request
33   * grammars of the type it can handle from this object using the
34   * <code>retrieveInitialGrammarSet</code> method. </li>
35   * <li>If it requires a grammar
36   * not in this set, it will request it from this Object using the
37   * <code>retrieveGrammar</code> method.  </li>
38   * <li> After successfully validating an
39   * instance, the validator should make any new grammars it has compiled
40   * available to this object using the <code>cacheGrammars</code>
41   * method; for ease of implementation it may make other Grammars it holds references to as well (i.e.,
42   * it may return some grammars that were retrieved from the GrammarPool in earlier operations). </li> </ul> </p>
43   *
44   * @author Neil Graham, IBM
45   */
46  
47  public interface XMLGrammarPool {
48  
49      // <p>we are trying to make this XMLGrammarPool work for all kinds of
50      // grammars, so we have a parameter "grammarType" for each of the
51      // methods. </p>
52  
53      /**
54       * <p> retrieve the initial known set of grammars. this method is
55       * called by a validator before the validation starts. the application
56       * can provide an initial set of grammars available to the current
57       * validation attempt. </p>
58       * @param grammarType the type of the grammar, from the
59       *  <code>com.sun.org.apache.xerces.internal.xni.grammars.Grammar</code> interface.
60       * @return the set of grammars the validator may put in its "bucket"
61       */
62      public Grammar[] retrieveInitialGrammarSet(String grammarType);
63  
64      /**
65       * <p>return the final set of grammars that the validator ended up
66       * with.
67       * This method is called after the
68       * validation finishes. The application may then choose to cache some
69       * of the returned grammars. </p>
70       * @param grammarType the type of the grammars being returned;
71       * @param grammars an array containing the set of grammars being
72       *  returned; order is not significant.
73       */
74      public void cacheGrammars(String grammarType, Grammar[] grammars);
75  
76      /**
77       * <p> This method requests that the application retrieve a grammar
78       * corresponding to the given GrammarIdentifier from its cache.
79       * If it cannot do so it must return null; the parser will then
80       * call the EntityResolver.  <strong>An application must not call its
81       * EntityResolver itself from this method; this may result in infinite
82       * recursions.</strong>
83       * @param desc The description of the Grammar being requested.
84       * @return the Grammar corresponding to this description or null if
85       *  no such Grammar is known.
86       */
87      public Grammar retrieveGrammar(XMLGrammarDescription desc);
88  
89      /**
90       * Causes the XMLGrammarPool not to store any grammars when
91       * the cacheGrammars(String, Grammar[[]) method is called.
92       */
93      public void lockPool();
94  
95      /**
96       * Allows the XMLGrammarPool to store grammars when its cacheGrammars(String, Grammar[])
97       * method is called.  This is the default state of the object.
98       */
99      public void unlockPool();
100 
101     /**
102      * Removes all grammars from the pool.
103      */
104     public void clear();
105 } // XMLGrammarPool