1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.xni.grammars;
  58. /**
  59. * <p> This interface specifies how the parser and the application
  60. * interact with respect to Grammar objects that the application
  61. * possesses--either by having precompiled them or by having stored them
  62. * from a previous validation of an instance document. It makes no
  63. * assumptions about the kind of Grammar involved, or about how the
  64. * application's storage mechanism works.</p>
  65. *
  66. * <p>The interaction works as follows:
  67. * <ul>
  68. * <li>When a validator considers a document, it is expected to request
  69. * grammars of the type it can handle from this object using the
  70. * <code>retrieveInitialGrammarSet</code> method. </li>
  71. * <li>If it requires a grammar
  72. * not in this set, it will request it from this Object using the
  73. * <code>retrieveGrammar</code> method. </li>
  74. * <li> After successfully validating an
  75. * instance, the validator should make any new grammars it has compiled
  76. * available to this object using the <code>cacheGrammars</code>
  77. * method; for ease of implementation it may make other Grammars it holds references to as well (i.e.,
  78. * it may return some grammars that were retrieved from the GrammarPool in earlier operations). </li> </ul> </p>
  79. *
  80. * @author Neil Graham, IBM
  81. * @version $Id: XMLGrammarPool.java,v 1.3 2003/11/14 16:54:05 mrglavas Exp $
  82. */
  83. public interface XMLGrammarPool {
  84. // <p>we are trying to make this XMLGrammarPool work for all kinds of
  85. // grammars, so we have a parameter "grammarType" for each of the
  86. // methods. </p>
  87. /**
  88. * <p> retrieve the initial known set of grammars. this method is
  89. * called by a validator before the validation starts. the application
  90. * can provide an initial set of grammars available to the current
  91. * validation attempt. </p>
  92. * @param grammarType the type of the grammar, from the
  93. * <code>com.sun.org.apache.xerces.internal.xni.grammars.Grammar</code> interface.
  94. * @return the set of grammars the validator may put in its "bucket"
  95. */
  96. public Grammar[] retrieveInitialGrammarSet(String grammarType);
  97. /**
  98. * <p>return the final set of grammars that the validator ended up
  99. * with.
  100. * This method is called after the
  101. * validation finishes. The application may then choose to cache some
  102. * of the returned grammars. </p>
  103. * @param grammarType the type of the grammars being returned;
  104. * @param grammars an array containing the set of grammars being
  105. * returned; order is not significant.
  106. */
  107. public void cacheGrammars(String grammarType, Grammar[] grammars);
  108. /**
  109. * <p> This method requests that the application retrieve a grammar
  110. * corresponding to the given GrammarIdentifier from its cache.
  111. * If it cannot do so it must return null; the parser will then
  112. * call the EntityResolver. <strong>An application must not call its
  113. * EntityResolver itself from this method; this may result in infinite
  114. * recursions.</strong>
  115. * @param desc The description of the Grammar being requested.
  116. * @return the Grammar corresponding to this description or null if
  117. * no such Grammar is known.
  118. */
  119. public Grammar retrieveGrammar(XMLGrammarDescription desc);
  120. /**
  121. * Causes the XMLGrammarPool not to store any grammars when
  122. * the cacheGrammars(String, Grammar[[]) method is called.
  123. */
  124. public void lockPool();
  125. /**
  126. * Allows the XMLGrammarPool to store grammars when its cacheGrammars(String, Grammar[])
  127. * method is called. This is the default state of the object.
  128. */
  129. public void unlockPool();
  130. /**
  131. * Removes all grammars from the pool.
  132. */
  133. public void clear();
  134. } // XMLGrammarPool