Class SAXEventQueue
- All Implemented Interfaces:
SAXEventStream
,ContentHandler
,ErrorHandler
,LexicalHandler
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!
-
Nested Class Summary
Nested classes/interfaces inherited from interface eu.bandm.tools.util.xml.SAXEventStream
SAXEventStream.EtherealMatcher, SAXEventStream.MatchException
-
Constructor Summary
ConstructorDescriptionUses a queue without limitation of size or capacity.SAXEventQueue
(int size) Uses a queue with permatent limitation of capacity = max size.. -
Method Summary
Modifier and TypeMethodDescription(package private) @Opt XMLDocumentIdentifier
_getDocumentId
(eu.bandm.tools.util.xml.SAXEventQueue.Item item) void
characters
(char[] data, int offset, int length) void
comment
(char[] ch, int start, int length) final void
consume()
Must only be called after (at least) one invocation oflookahead()
.Consumes any chararcter data event, and returns the data.void
Visits all ethereals which have been collected immediately PRECEDING the last consumed event (start tag/end tag/char data/end of document) Visit them in source text order (=reverse order of the linked list).void
drainTo
(ContentHandler drain) Write all stored SAX events to one receiver.void
dump
(PrintStream os) For Debugging: print all events currently in queue.void
endCDATA()
void
Write the very last tag (a special "end document" tag) to the queue, because now it must have all its Ethereals.void
endDTD()
void
endElement
(String uri, String name, String qName) void
void
endPrefixMapping
(String prefix) void
Pass through the error message immediately toerrorHandler
, if any; not in sync with the queue throughput.void
Pass through the error message immediately toerrorHandler
, if any; not in sync with the queue throughput.CHECK FIXME ist das wirklich "public" notwendig?Get the outgoing error handler.Returns the local name of the current head, i.e.Delivers the location of the current NEXT Event, i.e.Get the NamespaceName of the next element to deliver (=the head of the queue=the result of look-ahead).Returns the namespace URI of the current head, i.e.Returns the qualified name of the current head, i.e.Returns the conventional textual representation of the current head.void
ignorableWhitespace
(char[] data, int offset, int length) boolean
Returns whether the next SAX event represents character data.boolean
Returns whether the next SAX event is the "End of Document" element.boolean
Returns whether the next SAX event is any end element event (= close element tag)boolean
Returns whether the next SAX event is a certain end element event (= close element tag)boolean
lookaheadEndElement
(String qname) Returns whether the next SAX event is a certain end element event (= close element tag)boolean
Returns whether the next SAX event is any start element event (= open element tag)boolean
Returns whether the next SAX event is a certain start element event (= open element tag)boolean
lookaheadStartElement
(String qname) Returns whether the next SAX event is a certain start element event (= open element tag)void
Consumes the first element (if it is the indicated end document element).void
matchEndElement
(NamespaceName name) Consumes the first element (if it is the indicated end element).void
matchEndElement
(String name) Consumes the first element (if it is the indicated end element).Consumes the first element (if it is the indicated start element) and returns its attribute set.matchStartElement
(String qname) Consumes the first element (if it is the indicated start element) and returns its attribute set.void
processingInstruction
(String target, String body) protected void
Can be overwritten by a sub-class when an interrupt is received with blocked writing.void
setDocumentLocator
(Locator locator) According to SAX documentation, this is called-back automatically by any standard XML parser when this ContentHandler is declared to it by its "setContentHandler()" method.void
setErrorHandler
(ErrorHandler errorHandler) Set the outgoing error handler.void
sink()
Set sink flag so that from now on all incoming data is ingonred.void
skippedEntity
(String name) void
void
void
void
startElement
(String uri, String name, String qName, Attributes atts) void
startEntity
(String name) void
startPrefixMapping
(String prefix, String uri) void
Pass through the error message immediately toerrorHandler
, if any; not in sync with the queue throughput.protected void
Can be overwritten by a sub-class when an interrupt is received with blocked reading.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Constructor Details
-
SAXEventQueue
public SAXEventQueue()Uses a queue without limitation of size or capacity. -
SAXEventQueue
public SAXEventQueue(int size) Uses a queue with permatent limitation of capacity = max size..
-
-
Method Details
-
setErrorHandler
Set the outgoing error handler. May be null. -
getErrorHandler
Get the outgoing error handler. May be null. -
sink
public void sink()Set sink flag so that from now on all incoming data is ingonred. -
dump
For Debugging: print all events currently in queue. -
readInterrupted
protected void readInterrupted()Can be overwritten by a sub-class when an interrupt is received with blocked writing. -
writeInterrupted
protected void writeInterrupted()Can be overwritten by a sub-class when an interrupt is received with blocked reading. -
characters
public void characters(char[] data, int offset, int length) - Specified by:
characters
in interfaceContentHandler
-
startDocument
public void startDocument()- Specified by:
startDocument
in interfaceContentHandler
-
endDocument
public void endDocument()Write the very last tag (a special "end document" tag) to the queue, because now it must have all its Ethereals.- Specified by:
endDocument
in interfaceContentHandler
-
startPrefixMapping
- Specified by:
startPrefixMapping
in interfaceContentHandler
-
endPrefixMapping
- Specified by:
endPrefixMapping
in interfaceContentHandler
-
ignorableWhitespace
public void ignorableWhitespace(char[] data, int offset, int length) - Specified by:
ignorableWhitespace
in interfaceContentHandler
-
processingInstruction
- Specified by:
processingInstruction
in interfaceContentHandler
-
skippedEntity
- Specified by:
skippedEntity
in interfaceContentHandler
-
setDocumentLocator
According to SAX documentation, this is called-back automatically by any standard XML parser when this ContentHandler is declared to it by its "setContentHandler()" method. The locator object can be asked for location information whenever a SAX callback (for tags, CDATA, etc.) is instantiated. Argument may be null. If it is != null, every incoming tag, PCDATA, etc., will ask for location info.- Specified by:
setDocumentLocator
in interfaceContentHandler
-
startElement
- Specified by:
startElement
in interfaceContentHandler
-
endElement
- Specified by:
endElement
in interfaceContentHandler
-
comment
public void comment(char[] ch, int start, int length) - Specified by:
comment
in interfaceLexicalHandler
-
endCDATA
public void endCDATA()- Specified by:
endCDATA
in interfaceLexicalHandler
-
endDTD
public void endDTD()- Specified by:
endDTD
in interfaceLexicalHandler
-
endEntity
- Specified by:
endEntity
in interfaceLexicalHandler
-
startCDATA
public void startCDATA()- Specified by:
startCDATA
in interfaceLexicalHandler
-
startDTD
- Specified by:
startDTD
in interfaceLexicalHandler
-
startEntity
- Specified by:
startEntity
in interfaceLexicalHandler
-
warning
Pass through the error message immediately toerrorHandler
, if any; not in sync with the queue throughput.- Specified by:
warning
in interfaceErrorHandler
- Throws:
SAXException
-
error
Pass through the error message immediately toerrorHandler
, if any; not in sync with the queue throughput.- Specified by:
error
in interfaceErrorHandler
- Throws:
SAXException
-
fatalError
Pass through the error message immediately toerrorHandler
, if any; not in sync with the queue throughput.- Specified by:
fatalError
in interfaceErrorHandler
- Throws:
SAXException
-
lookaheadCharacters
public boolean lookaheadCharacters()Description copied from interface:SAXEventStream
Returns whether the next SAX event represents character data.- Specified by:
lookaheadCharacters
in interfaceSAXEventStream
-
lookaheadStartElement
Description copied from interface:SAXEventStream
Returns whether the next SAX event is a certain start element event (= open element tag)- Specified by:
lookaheadStartElement
in interfaceSAXEventStream
-
lookaheadStartElement
Description copied from interface:SAXEventStream
Returns whether the next SAX event is a certain start element event (= open element tag)- Specified by:
lookaheadStartElement
in interfaceSAXEventStream
-
lookaheadStartElement
public boolean lookaheadStartElement()Description copied from interface:SAXEventStream
Returns whether the next SAX event is any start element event (= open element tag)- Specified by:
lookaheadStartElement
in interfaceSAXEventStream
-
matchStartElement
Description copied from interface:SAXEventStream
Consumes the first element (if it is the indicated start element) and returns its attribute set.- Specified by:
matchStartElement
in interfaceSAXEventStream
- Throws:
SAXEventStream.MatchException
-
matchStartElement
Description copied from interface:SAXEventStream
Consumes the first element (if it is the indicated start element) and returns its attribute set.- Specified by:
matchStartElement
in interfaceSAXEventStream
- Throws:
SAXEventStream.MatchException
-
lookaheadEndElement
Description copied from interface:SAXEventStream
Returns whether the next SAX event is a certain end element event (= close element tag)- Specified by:
lookaheadEndElement
in interfaceSAXEventStream
-
lookaheadEndElement
Description copied from interface:SAXEventStream
Returns whether the next SAX event is a certain end element event (= close element tag)- Specified by:
lookaheadEndElement
in interfaceSAXEventStream
-
lookaheadEndElement
public boolean lookaheadEndElement()Description copied from interface:SAXEventStream
Returns whether the next SAX event is any end element event (= close element tag)- Specified by:
lookaheadEndElement
in interfaceSAXEventStream
-
matchEndElement
Description copied from interface:SAXEventStream
Consumes the first element (if it is the indicated end element).- Specified by:
matchEndElement
in interfaceSAXEventStream
- Throws:
SAXEventStream.MatchException
-
matchEndElement
Description copied from interface:SAXEventStream
Consumes the first element (if it is the indicated end element).- Specified by:
matchEndElement
in interfaceSAXEventStream
- Throws:
SAXEventStream.MatchException
-
lookaheadEndDocument
public boolean lookaheadEndDocument()Description copied from interface:SAXEventStream
Returns whether the next SAX event is the "End of Document" element.- Specified by:
lookaheadEndDocument
in interfaceSAXEventStream
-
matchEndDocument
Description copied from interface:SAXEventStream
Consumes the first element (if it is the indicated end document element).- Specified by:
matchEndDocument
in interfaceSAXEventStream
- Throws:
SAXEventStream.MatchException
-
consumeCharacters
Description copied from interface:SAXEventStream
Consumes any chararcter data event, and returns the data.- Specified by:
consumeCharacters
in interfaceSAXEventStream
-
getAttributes
-
getNamespaceURI
Description copied from interface:SAXEventStream
Returns the namespace URI of the current head, i.e. the next element to consume.- Specified by:
getNamespaceURI
in interfaceSAXEventStream
-
getLocalName
Description copied from interface:SAXEventStream
Returns the local name of the current head, i.e. the next element to consume.- Specified by:
getLocalName
in interfaceSAXEventStream
-
getQualifiedName
Description copied from interface:SAXEventStream
Returns the qualified name of the current head, i.e. the next element to consume.- Specified by:
getQualifiedName
in interfaceSAXEventStream
-
getNamespaceName
Get the NamespaceName of the next element to deliver (=the head of the queue=the result of look-ahead). Since NamespaceName objects are not cheap to construct, there is a cachenscache
.- Specified by:
getNamespaceName
in interfaceSAXEventStream
-
consume
public final void consume()Must only be called after (at least) one invocation oflookahead()
. Lookahead copies the head of the queue into the fieldhead
, and this method clears this field again. Afterwards,lookahead()
may block again. GLO OUT consumedEthereals- Specified by:
consume
in interfaceSAXEventStream
-
consumedEthereals
Visits all ethereals which have been collected immediately PRECEDING the last consumed event (start tag/end tag/char data/end of document) Visit them in source text order (=reverse order of the linked list).- Specified by:
consumedEthereals
in interfaceSAXEventStream
-
matchedEtherealLocation
- Specified by:
matchedEtherealLocation
in interfaceSAXEventStream
-
getDocumentId
CHECK FIXME ist das wirklich "public" notwendig? -
_getDocumentId
-
getLocation
Delivers the location of the current NEXT Event, i.e. the event which will be considered when calling "lookahead(..)" and consumed when calling "match (..)". - Specified by:
getLocation
in interfaceSAXEventStream
-
headToString
Description copied from interface:SAXEventStream
Returns the conventional textual representation of the current head. Raises Nullpointer Exception if no such exists.- Specified by:
headToString
in interfaceSAXEventStream
-
drainTo
Write all stored SAX events to one receiver. Does currently NOT support Ethereals, FIXME.- Throws:
SAXException
-