1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999,2000 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 org.apache.xml.dtm.ref;
  58. import org.xml.sax.InputSource;
  59. import org.xml.sax.SAXException;
  60. import java.io.IOException;
  61. import org.xml.sax.ext.LexicalHandler;
  62. import org.xml.sax.ContentHandler;
  63. import org.xml.sax.XMLReader;
  64. /** <p>CoroutineParser is an API for parser threads that operate as
  65. * coroutines. See CoroutineSAXParser and CoroutineSAXParser_Xerces
  66. * for examples.</p>
  67. *
  68. * <p><grumble> I'd like the interface to require a specific form
  69. * for either the base constructor or a static factory method. Java
  70. * doesn't allow us to specify either, so I'll just document them
  71. * here:
  72. *
  73. * <ul>
  74. * <li>public CoroutineParser(CoroutineManager co, int appCoroutine);</li>
  75. * <li>public CoroutineParser createCoroutineParser(CoroutineManager co, int appCoroutine);</li>
  76. * </ul>
  77. *
  78. * </grumble></p>
  79. *
  80. * @deprecated Since the ability to start a parse via the
  81. * coroutine protocol was not being used and was complicating design.
  82. * See {@link IncrementalSAXSource}.
  83. * */
  84. public interface CoroutineParser {
  85. /** @return the coroutine ID number for this CoroutineParser object.
  86. * Note that this isn't useful unless you know which CoroutineManager
  87. * you're talking to. Also note that the do...() methods encapsulate
  88. * the common transactions with the CoroutineParser, so you shouldn't
  89. * need this in most cases.
  90. * */
  91. public int getParserCoroutineID();
  92. /** @return the CoroutineManager for this CoroutineParser object.
  93. * If you're using the do...() methods, applications should only
  94. * need to talk to the CoroutineManager once, to obtain the
  95. * application's Coroutine ID.
  96. * */
  97. public CoroutineManager getCoroutineManager();
  98. /** Register a SAX-style content handler for us to output to */
  99. public void setContentHandler(ContentHandler handler);
  100. /** Register a SAX-style lexical handler for us to output to
  101. * Not all parsers support this...
  102. *
  103. * %REVIEW% Not called setLexicalHandler because Xalan uses that name
  104. * internally, which causes subclassing nuisances.
  105. */
  106. public void setLexHandler(org.xml.sax.ext.LexicalHandler handler);
  107. /* The run() method is required in CoroutineParsers that run as
  108. * threads (of course)... but it isn't part of our API, and
  109. * shouldn't be declared here.
  110. * */
  111. //================================================================
  112. /** doParse() is a simple API which tells the coroutine parser
  113. * to begin reading from a file. This is intended to be called from one
  114. * of our partner coroutines, and serves both to encapsulate the
  115. * communication protocol and to avoid having to explicitly use the
  116. * CoroutineParser's coroutine ID number.
  117. *
  118. * %REVIEW% Can/should this unify with doMore? (if URI hasn't changed,
  119. * parse more from same file, else end and restart parsing...?
  120. *
  121. * @param source The InputSource to parse from.
  122. * @param appCoroutine The coroutine ID number of the coroutine invoking
  123. * this method, so it can be resumed after the parser has responded to the
  124. * request.
  125. * @return Boolean.TRUE if the CoroutineParser believes more data may be available
  126. * for further parsing. Boolean.FALSE if parsing ran to completion.
  127. * Exception if the parser objected for some reason.
  128. * */
  129. public Object doParse(InputSource source, int appCoroutine);
  130. /** doMore() is a simple API which tells the coroutine parser
  131. * that we need more nodes. This is intended to be called from one
  132. * of our partner coroutines, and serves both to encapsulate the
  133. * communication protocol and to avoid having to explicitly use the
  134. * CoroutineParser's coroutine ID number.
  135. *
  136. * @param parsemore If true, tells the incremental parser to generate
  137. * another chunk of output. If false, tells the parser that we're
  138. * satisfied and it can terminate parsing of this document.
  139. * @param appCoroutine The coroutine ID number of the coroutine invoking
  140. * this method, so it can be resumed after the parser has responded to the
  141. * request.
  142. * @return Boolean.TRUE if the CoroutineParser believes more data may be available
  143. * for further parsing. Boolean.FALSE if parsing ran to completion.
  144. * Exception if the parser objected for some reason.
  145. * */
  146. public Object doMore (boolean parsemore, int appCoroutine);
  147. /** doTerminate() is a simple API which tells the coroutine
  148. * parser to terminate itself. This is intended to be called from
  149. * one of our partner coroutines, and serves both to encapsulate the
  150. * communication protocol and to avoid having to explicitly use the
  151. * CoroutineParser's coroutine ID number.
  152. *
  153. * Returns only after the CoroutineParser has acknowledged the request.
  154. *
  155. * @param appCoroutine The coroutine ID number of the coroutine invoking
  156. * this method, so it can be resumed after the parser has responded to the
  157. * request.
  158. * */
  159. public void doTerminate(int appCoroutine);
  160. /**
  161. * Initialize the coroutine parser. Same parameters could be passed
  162. * in a non-default constructor, or by using using Class.forName and
  163. * newInstance and then calling init()
  164. */
  165. public void init( CoroutineManager co, int appCoroutineID, XMLReader parser );
  166. } // class CoroutineParser