Class SAXEventQueue

java.lang.Object
eu.bandm.tools.util2.SAXEventQueue
All Implemented Interfaces:
SAXEventStream, ContentHandler, ErrorHandler, LexicalHandler

public class SAXEventQueue extends Object implements ContentHandler, LexicalHandler, ErrorHandler, SAXEventStream
This class operates as a dynamic storage for SAX events.
It acts passively on both sides:
For receiving, it implements ContentHandler (for receiving open tags, close tags, character data and processing instructions), LexicalHandler (for receiving comments), and ErrorHandler.
On the consumer side it implements SAXEventStream, which must be actively polled by a consumer process, and supports to set a ErrorHandler, to which the incoming errors are transparently propagated.

ATTENTION There is a constructor with and one without (final, not initial!) capacity. The first creates an ArrayBlockingQueue, the other a LinkedBlockingQueue.
Originally, this class was intended for realizing a "buffered pipe" between a producer and a consumer running in two different threads. The producer uses the ContentHandler interface, the consumer the SAXEventStream interface.

It has successfully been "abused" also as a storage for SAX events, ie. producer and consumer running in the same thread, subsequently. Then the accumulated contents is sent to the consumer by a call to drainTo().
In this case it must be well observed that only the LinkedBlockingQueue will expand automatically.
Choosing the ArrayBlockingQueue with too small a capacity will hang the producer process!