1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: CoroutineParser.java,v 1.8 2004/02/16 23:06:11 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.dtm.ref;
  20. import org.xml.sax.ContentHandler;
  21. import org.xml.sax.InputSource;
  22. import org.xml.sax.XMLReader;
  23. /** <p>CoroutineParser is an API for parser threads that operate as
  24. * coroutines. See CoroutineSAXParser and CoroutineSAXParser_Xerces
  25. * for examples.</p>
  26. *
  27. * <p><grumble> I'd like the interface to require a specific form
  28. * for either the base constructor or a static factory method. Java
  29. * doesn't allow us to specify either, so I'll just document them
  30. * here:
  31. *
  32. * <ul>
  33. * <li>public CoroutineParser(CoroutineManager co, int appCoroutine);</li>
  34. * <li>public CoroutineParser createCoroutineParser(CoroutineManager co, int appCoroutine);</li>
  35. * </ul>
  36. *
  37. * </grumble></p>
  38. *
  39. * @deprecated Since the ability to start a parse via the
  40. * coroutine protocol was not being used and was complicating design.
  41. * See {@link IncrementalSAXSource}.
  42. * */
  43. public interface CoroutineParser {
  44. /** @return the coroutine ID number for this CoroutineParser object.
  45. * Note that this isn't useful unless you know which CoroutineManager
  46. * you're talking to. Also note that the do...() methods encapsulate
  47. * the common transactions with the CoroutineParser, so you shouldn't
  48. * need this in most cases.
  49. * */
  50. public int getParserCoroutineID();
  51. /** @return the CoroutineManager for this CoroutineParser object.
  52. * If you're using the do...() methods, applications should only
  53. * need to talk to the CoroutineManager once, to obtain the
  54. * application's Coroutine ID.
  55. * */
  56. public CoroutineManager getCoroutineManager();
  57. /** Register a SAX-style content handler for us to output to */
  58. public void setContentHandler(ContentHandler handler);
  59. /** Register a SAX-style lexical handler for us to output to
  60. * Not all parsers support this...
  61. *
  62. * %REVIEW% Not called setLexicalHandler because Xalan uses that name
  63. * internally, which causes subclassing nuisances.
  64. */
  65. public void setLexHandler(org.xml.sax.ext.LexicalHandler handler);
  66. /* The run() method is required in CoroutineParsers that run as
  67. * threads (of course)... but it isn't part of our API, and
  68. * shouldn't be declared here.
  69. * */
  70. //================================================================
  71. /** doParse() is a simple API which tells the coroutine parser
  72. * to begin reading from a file. This is intended to be called from one
  73. * of our partner coroutines, and serves both to encapsulate the
  74. * communication protocol and to avoid having to explicitly use the
  75. * CoroutineParser's coroutine ID number.
  76. *
  77. * %REVIEW% Can/should this unify with doMore? (if URI hasn't changed,
  78. * parse more from same file, else end and restart parsing...?
  79. *
  80. * @param source The InputSource to parse from.
  81. * @param appCoroutine The coroutine ID number of the coroutine invoking
  82. * this method, so it can be resumed after the parser has responded to the
  83. * request.
  84. * @return Boolean.TRUE if the CoroutineParser believes more data may be available
  85. * for further parsing. Boolean.FALSE if parsing ran to completion.
  86. * Exception if the parser objected for some reason.
  87. * */
  88. public Object doParse(InputSource source, int appCoroutine);
  89. /** doMore() is a simple API which tells the coroutine parser
  90. * that we need more nodes. This is intended to be called from one
  91. * of our partner coroutines, and serves both to encapsulate the
  92. * communication protocol and to avoid having to explicitly use the
  93. * CoroutineParser's coroutine ID number.
  94. *
  95. * @param parsemore If true, tells the incremental parser to generate
  96. * another chunk of output. If false, tells the parser that we're
  97. * satisfied and it can terminate parsing of this document.
  98. * @param appCoroutine The coroutine ID number of the coroutine invoking
  99. * this method, so it can be resumed after the parser has responded to the
  100. * request.
  101. * @return Boolean.TRUE if the CoroutineParser believes more data may be available
  102. * for further parsing. Boolean.FALSE if parsing ran to completion.
  103. * Exception if the parser objected for some reason.
  104. * */
  105. public Object doMore (boolean parsemore, int appCoroutine);
  106. /** doTerminate() is a simple API which tells the coroutine
  107. * parser to terminate itself. This is intended to be called from
  108. * one of our partner coroutines, and serves both to encapsulate the
  109. * communication protocol and to avoid having to explicitly use the
  110. * CoroutineParser's coroutine ID number.
  111. *
  112. * Returns only after the CoroutineParser has acknowledged the request.
  113. *
  114. * @param appCoroutine The coroutine ID number of the coroutine invoking
  115. * this method, so it can be resumed after the parser has responded to the
  116. * request.
  117. * */
  118. public void doTerminate(int appCoroutine);
  119. /**
  120. * Initialize the coroutine parser. Same parameters could be passed
  121. * in a non-default constructor, or by using using context ClassLoader
  122. * and newInstance and then calling init()
  123. */
  124. public void init( CoroutineManager co, int appCoroutineID, XMLReader parser );
  125. } // class CoroutineParser