package.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <html><head><title>
  2. blah
  3. <!--
  4. /*
  5. * Copyright (C) 1999-2001 The Free Software Foundation, Inc.
  6. */
  7. -->
  8. </title></head><body>
  9. <p>This package exposes a kind of XML processing pipeline, based on sending
  10. SAX events, which can be used as components of application architectures.
  11. Pipelines are used to convey streams of processing events from a producer
  12. to one or more consumers, and to let each consumer control the data seen by
  13. later consumers.
  14. <p> There is a <a href="PipelineFactory.html">PipelineFactory</a> class which
  15. accepts a syntax describing how to construct some simple pipelines. Strings
  16. describing such pipelines can be used in command line tools (see the
  17. <a href="../util/DoParse.html">DoParse</a> class)
  18. and in other places that it is
  19. useful to let processing be easily reconfigured. Pipelines can of course
  20. be constructed programmatically, providing access to options that the
  21. factory won't.
  22. <p> Web applications are supported by making it easy for servlets (or
  23. non-Java web application components) to be part of a pipeline. They can
  24. originate XML (or XHTML) data through an <em>InputSource</em> or in
  25. response to XML messages sent from clients using <em>CallFilter</em>
  26. pipeline stages. Such facilities are available using the simple syntax
  27. for pipeline construction.
  28. <h2> Programming Models </h2>
  29. <p> Pipelines should be simple to understand.
  30. <ul>
  31. <li> XML content, typically entire documents,
  32. is pushed through consumers by producers.
  33. <li> Pipelines are basically about consuming SAX2 callback events,
  34. where the events encapsulate XML infoset-level data.<ul>
  35. <li> Pipelines are constructed by taking one or more consumer
  36. stages and combining them to produce a composite consumer.
  37. <li> A pipeline is presumed to have pending tasks and state from
  38. the beginning of its ContentHandler.startDocument() callback until
  39. it's returned from its ContentHandler.doneDocument() callback.
  40. <li> Pipelines may have multiple output stages ("fan-out")
  41. or multiple input stages ("fan-in") when appropriate.
  42. <li> Pipelines may be long-lived, but need not be.
  43. </ul>
  44. <li> There is flexibility about event production. <ul>
  45. <li> SAX2 XMLReader objects are producers, which
  46. provide a high level "pull" model: documents (text or DOM) are parsed,
  47. and the parser pushes individual events through the pipeline.
  48. <li> Events can be pushed directly to event consumer components
  49. by application modules, if they invoke SAX2 callbacks directly.
  50. That is, application modules use the XML Infoset as exposed
  51. through SAX2 event callbacks.
  52. </ul>
  53. <li> Multiple producer threads may concurrently access a pipeline,
  54. if they coordinate appropriately.
  55. <li> Pipeline processing is not the only framework applications
  56. will use.
  57. </ul>
  58. <h3> Producers: XMLReader or Custom </h3>
  59. <p> Many producers will be SAX2 XMLReader objects, and
  60. will read (pull) data which is then written (pushed) as events.
  61. Typically these will parse XML text (acquired from
  62. <code>org.xml.sax.helpers.XMLReaderFactory</code>) or a DOM tree
  63. (using a <code><a href="../util/DomParser.html">DomParser</a></code>)
  64. These may be bound to event consumer using a convenience routine,
  65. <em><a href="EventFilter.html">EventFilter</a>.bind()</em>.
  66. Once bound, these producers may be given additional documents to
  67. sent through its pipeline.
  68. <p> In other cases, you will write producers yourself. For example, some
  69. data structures might know how to write themselves out using one or
  70. more XML models, expressed as sequences of SAX2 event callbacks.
  71. An application module might
  72. itself be a producer, issuing startDocument and endDocument events
  73. and then asking those data structures to write themselves out to a
  74. given EventConsumer, or walking data structures (such as JDBC query
  75. results) and applying its own conversion rules. WAP format XML
  76. (WBMXL) can be directly converted to producer output.
  77. <p> SAX2 introduced an "XMLFilter" interface, which is a kind of XMLReader.
  78. It is most useful in conjunction with its XMLFilterImpl helper class;
  79. see the <em><a href="EventFilter.html">EventFilter</a></em> javadoc
  80. for information contrasting that XMLFilterImpl approach with the
  81. relevant parts of this pipeline framework. Briefly, such XMLFilterImpl
  82. children can be either producers or consumers, and are more limited in
  83. configuration flexibility. In this framework, the focus of filters is
  84. on the EventConsumer side; see the section on
  85. <a href="#fitting">pipe fitting</a> below.
  86. <h3> Consume to Standard or Custom Data Representations </h3>
  87. <p> Many consumers will be used to create standard representations of XML
  88. data. The <a href="TextConsumer.html">TextConsumer</a> takes its events
  89. and writes them as text for a single XML document,
  90. using an internal <a href="../util/XMLWriter.html">XMLWriter</a>.
  91. The <a href="DomConsumer.html">DomConsumer</a> takes its events and uses
  92. them to create and populate a DOM Document.
  93. <p> In other cases, you will write consumers yourself. For example,
  94. you might use a particular unmarshaling filter to produce objects
  95. that fit your application's requirements, instead of using DOM.
  96. Such consumers work at the level of XML data models, rather than with
  97. specific representations such as XML text or a DOM tree. You could
  98. convert your output directly to WAP format data (WBXML).
  99. <h3><a name="fitting">Pipe Fitting</a></h3>
  100. <p> Pipelines are composite event consumers, with each stage having
  101. the opportunity to transform the data before delivering it to any
  102. subsequent stages.
  103. <p> The <a href="PipelineFactory.html">PipelineFactory</a> class
  104. provides access to much of this functionality through a simple syntax.
  105. See the table in that class's javadoc describing a number of standard
  106. components. Direct API calls are still needed for many of the most
  107. interesting pipeline configurations, including ones leveraging actual
  108. or logical concurrency.
  109. <p> Four basic types of pipe fitting are directly supported. These may
  110. be used to construct complex pipeline networks. <ul>
  111. <li> <a href="TeeConsumer.html">TeeConsumer</a> objects split event
  112. flow so it goes to two two different consumers, one before the other.
  113. This is a basic form of event fan-out; you can use this class to
  114. copy events to any number of output pipelines.
  115. <li> Clients can call remote components through HTTP or HTTPS using
  116. the <a href="CallFilter.html">CallFilter</a> component, and Servlets
  117. can implement such components by extending the
  118. <a href="XmlServlet.html">XmlServlet</a> component. Java is not
  119. required on either end, and transport protocols other than HTTP may
  120. also be used.
  121. <li> <a href="EventFilter.html">EventFilter</a> objects selectively
  122. provide handling for callbacks, and can pass unhandled ones to a
  123. subsequent stage. They are often subclassed, since much of the
  124. basic filtering machinery is already in place in the base class.
  125. <li> Applications can merge two event flows by just using the same
  126. consumer in each one. If multiple threads are in use, synchronization
  127. needs to be addressed by the appropriate application level policy.
  128. </ul>
  129. <p> Note that filters can be as complex as
  130. <a href="XsltFilter.html">XSLT transforms</a>
  131. available) on input data, or as simple as removing simple syntax data
  132. such as ignorable whitespace, comments, and CDATA delimiters.
  133. Some simple "built-in" filters are part of this package.
  134. <h3> Coding Conventions: Filter and Terminus Stages</h3>
  135. <p> If you follow these coding conventions, your classes may be used
  136. directly (give the full class name) in pipeline descriptions as understood
  137. by the PipelineFactory. There are four constructors the factory may
  138. try to use; in order of decreasing numbers of parameters, these are: <ul>
  139. <li> Filters that need a single String setup parameter should have
  140. a public constructor with two parameters: that string, then the
  141. EventConsumer holding the "next" consumer to get events.
  142. <li> Filters that don't need setup parameters should have a public
  143. constructor that accepts a single EventConsumer holding the "next"
  144. consumer to get events when they are done.
  145. <li> Terminus stages may have a public constructor taking a single
  146. paramter: the string value of that parameter.
  147. <li> Terminus stages may have a public no-parameters constructor.
  148. </ul>
  149. <p> Of course, classes may support more than one such usage convention;
  150. if they do, they can automatically be used in multiple modes. If you
  151. try to use a terminus class as a filter, and that terminus has a constructor
  152. with the appropriate number of arguments, it is automatically wrapped in
  153. a "tee" filter.
  154. <h2> Debugging Tip: "Tee" Joints can Snapshot Data</h2>
  155. <p> It can sometimes be hard to see what's happening, when something
  156. goes wrong. Easily fixed: just snapshot the data. Then you can find
  157. out where things start to go wrong.
  158. <p> If you're using pipeline descriptors so that they're easily
  159. administered, just stick a <em>write&nbsp;(&nbsp;filename&nbsp;)</em>
  160. filter into the pipeline at an appropriate point.
  161. <p> Inside your programs, you can do the same thing directly: perhaps
  162. by saving a Writer (perhaps a StringWriter) in a variable, using that
  163. to create a TextConsumer, and making that the first part of a tee --
  164. splicing that into your pipeline at a convenient location.
  165. <p> You can also use a DomConsumer to buffer the data, but remember
  166. that DOM doesn't save all the information that XML provides, so that DOM
  167. snapshots are relatively low fidelity. They also are substantially more
  168. expensive in terms of memory than a StringWriter holding similar data.
  169. <h2> Debugging Tip: Non-XML Producers</h2>
  170. <p> Producers in pipelines don't need to start from XML
  171. data structures, such as text in XML syntax (likely coming
  172. from some <em>XMLReader</em> that parses XML) or a
  173. DOM representation (perhaps with a
  174. <a href="../util/DomParser.html">DomParser</a>).
  175. <p> One common type of event producer will instead make
  176. direct calls to SAX event handlers returned from an
  177. <a href="EventConsumer.html">EventConsumer</a>.
  178. For example, making <em>ContentHandler.startElement</em>
  179. calls and matching <em>ContentHandler.endElement</em> calls.
  180. <p> Applications making such calls can catch certain
  181. common "syntax errors" by using a
  182. <a href="WellFormednessFilter.html">WellFormednessFilter</a>.
  183. That filter will detect (and report) erroneous input data
  184. such as mismatched document, element, or CDATA start/end calls.
  185. Use such a filter near the head of the pipeline that your
  186. producer feeds, at least while debugging, to help ensure that
  187. you're providing legal XML Infoset data.
  188. <p> You can also arrange to validate data on the fly.
  189. For DTD validation, you can configure a
  190. <a href="ValidationConsumer.html">ValidationConsumer</a>
  191. to work as a filter, using any DTD you choose.
  192. Other validation schemes can be handled with other
  193. validation filters.
  194. </body></html>