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
ConstructorsConstructorDescriptionUses 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) voidcharacters(char[] data, int offset, int length) voidcomment(char[] ch, int start, int length) final voidconsume()Must only be called after (at least) one invocation oflookahead().Consumes any chararcter data event, and returns the data.voidVisits 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).voiddrainTo(ContentHandler drain) Write all stored SAX events to one receiver.voiddump(PrintStream os) For Debugging: print all events currently in queue.voidendCDATA()voidWrite the very last tag (a special "end document" tag) to the queue, because now it must have all its Ethereals.voidendDTD()voidendElement(String uri, String name, String qName) voidvoidendPrefixMapping(String prefix) voidPass through the error message immediately toerrorHandler, if any; not in sync with the queue throughput.voidPass 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 next Event.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.voidignorableWhitespace(char[] data, int offset, int length) booleanReturns whether the next SAX event represents character data.booleanReturns whether the next SAX event is the "End of Document" element.booleanReturns whether the next SAX event is any end element event (= close element tag)booleanReturns whether the next SAX event is a certain end element event (= close element tag)booleanlookaheadEndElement(String qname) Returns whether the next SAX event is a certain end element event (= close element tag)booleanReturns whether the next SAX event is any start element event (= open element tag)booleanReturns whether the next SAX event is a certain start element event (= open element tag)booleanlookaheadStartElement(String qname) Returns whether the next SAX event is a certain start element event (= open element tag)voidConsumes the first element (if it is the indicated end document element).voidmatchEndElement(NamespaceName name) Consumes the first element (if it is the indicated end element).voidmatchEndElement(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.voidprocessingInstruction(String target, String body) protected voidCan be overwritten by a sub-class when an interrupt is received with blocked writing.voidsetDocumentLocator(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.voidsetErrorHandler(ErrorHandler errorHandler) Set the outgoing error handler.voidsink()Set sink flag so that from now on all incoming data is ingonred.voidskippedEntity(String name) voidvoidvoidvoidstartElement(String uri, String name, String qName, Attributes atts) voidstartEntity(String name) voidstartPrefixMapping(String prefix, String uri) voidPass through the error message immediately toerrorHandler, if any; not in sync with the queue throughput.protected voidCan 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, waitMethods 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.- See Also:
-
getErrorHandler
Get the outgoing error handler. May be null.- See Also:
-
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:
charactersin interfaceContentHandler
-
startDocument
public void startDocument()- Specified by:
startDocumentin 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:
endDocumentin interfaceContentHandler
-
startPrefixMapping
- Specified by:
startPrefixMappingin interfaceContentHandler
-
endPrefixMapping
- Specified by:
endPrefixMappingin interfaceContentHandler
-
ignorableWhitespace
public void ignorableWhitespace(char[] data, int offset, int length) - Specified by:
ignorableWhitespacein interfaceContentHandler
-
processingInstruction
- Specified by:
processingInstructionin interfaceContentHandler
-
skippedEntity
- Specified by:
skippedEntityin 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:
setDocumentLocatorin interfaceContentHandler
-
startElement
- Specified by:
startElementin interfaceContentHandler
-
endElement
- Specified by:
endElementin interfaceContentHandler
-
comment
public void comment(char[] ch, int start, int length) - Specified by:
commentin interfaceLexicalHandler
-
endCDATA
public void endCDATA()- Specified by:
endCDATAin interfaceLexicalHandler
-
endDTD
public void endDTD()- Specified by:
endDTDin interfaceLexicalHandler
-
endEntity
- Specified by:
endEntityin interfaceLexicalHandler
-
startCDATA
public void startCDATA()- Specified by:
startCDATAin interfaceLexicalHandler
-
startDTD
- Specified by:
startDTDin interfaceLexicalHandler
-
startEntity
- Specified by:
startEntityin interfaceLexicalHandler
-
warning
Pass through the error message immediately toerrorHandler, if any; not in sync with the queue throughput.- Specified by:
warningin interfaceErrorHandler- Throws:
SAXException
-
error
Pass through the error message immediately toerrorHandler, if any; not in sync with the queue throughput.- Specified by:
errorin interfaceErrorHandler- Throws:
SAXException
-
fatalError
Pass through the error message immediately toerrorHandler, if any; not in sync with the queue throughput.- Specified by:
fatalErrorin interfaceErrorHandler- Throws:
SAXException
-
lookaheadCharacters
public boolean lookaheadCharacters()Description copied from interface:SAXEventStreamReturns whether the next SAX event represents character data.- Specified by:
lookaheadCharactersin interfaceSAXEventStream
-
lookaheadStartElement
Description copied from interface:SAXEventStreamReturns whether the next SAX event is a certain start element event (= open element tag)- Specified by:
lookaheadStartElementin interfaceSAXEventStream
-
lookaheadStartElement
Description copied from interface:SAXEventStreamReturns whether the next SAX event is a certain start element event (= open element tag)- Specified by:
lookaheadStartElementin interfaceSAXEventStream
-
lookaheadStartElement
public boolean lookaheadStartElement()Description copied from interface:SAXEventStreamReturns whether the next SAX event is any start element event (= open element tag)- Specified by:
lookaheadStartElementin interfaceSAXEventStream
-
matchStartElement
Description copied from interface:SAXEventStreamConsumes the first element (if it is the indicated start element) and returns its attribute set.- Specified by:
matchStartElementin interfaceSAXEventStream- Throws:
SAXEventStream.MatchException
-
matchStartElement
Description copied from interface:SAXEventStreamConsumes the first element (if it is the indicated start element) and returns its attribute set.- Specified by:
matchStartElementin interfaceSAXEventStream- Throws:
SAXEventStream.MatchException
-
lookaheadEndElement
Description copied from interface:SAXEventStreamReturns whether the next SAX event is a certain end element event (= close element tag)- Specified by:
lookaheadEndElementin interfaceSAXEventStream
-
lookaheadEndElement
Description copied from interface:SAXEventStreamReturns whether the next SAX event is a certain end element event (= close element tag)- Specified by:
lookaheadEndElementin interfaceSAXEventStream
-
lookaheadEndElement
public boolean lookaheadEndElement()Description copied from interface:SAXEventStreamReturns whether the next SAX event is any end element event (= close element tag)- Specified by:
lookaheadEndElementin interfaceSAXEventStream
-
matchEndElement
Description copied from interface:SAXEventStreamConsumes the first element (if it is the indicated end element).- Specified by:
matchEndElementin interfaceSAXEventStream- Throws:
SAXEventStream.MatchException
-
matchEndElement
Description copied from interface:SAXEventStreamConsumes the first element (if it is the indicated end element).- Specified by:
matchEndElementin interfaceSAXEventStream- Throws:
SAXEventStream.MatchException
-
lookaheadEndDocument
public boolean lookaheadEndDocument()Description copied from interface:SAXEventStreamReturns whether the next SAX event is the "End of Document" element.- Specified by:
lookaheadEndDocumentin interfaceSAXEventStream
-
matchEndDocument
Description copied from interface:SAXEventStreamConsumes the first element (if it is the indicated end document element).- Specified by:
matchEndDocumentin interfaceSAXEventStream- Throws:
SAXEventStream.MatchException
-
consumeCharacters
Description copied from interface:SAXEventStreamConsumes any chararcter data event, and returns the data.- Specified by:
consumeCharactersin interfaceSAXEventStream
-
getAttributes
-
getNamespaceURI
Description copied from interface:SAXEventStreamReturns the namespace URI of the current head, i.e. the next element to consume.- Specified by:
getNamespaceURIin interfaceSAXEventStream
-
getLocalName
Description copied from interface:SAXEventStreamReturns the local name of the current head, i.e. the next element to consume.- Specified by:
getLocalNamein interfaceSAXEventStream
-
getQualifiedName
Description copied from interface:SAXEventStreamReturns the qualified name of the current head, i.e. the next element to consume.- Specified by:
getQualifiedNamein 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:
getNamespaceNamein 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:
consumein 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:
consumedEtherealsin interfaceSAXEventStream
-
matchedEtherealLocation
- Specified by:
matchedEtherealLocationin interfaceSAXEventStream
-
getDocumentId
CHECK FIXME ist das wirklich "public" notwendig? -
_getDocumentId
-
getLocation
Delivers the location of the next Event. This is the event which will be considered when callinglookahead<XX>(..)and consumed when callingmatch<XX>(..).- Specified by:
getLocationin interfaceSAXEventStream
-
headToString
Description copied from interface:SAXEventStreamReturns the conventional textual representation of the current head. Raises Nullpointer Exception if no such exists.- Specified by:
headToStringin interfaceSAXEventStream
-
drainTo
Write all stored SAX events to one receiver. Does currently NOT support Ethereals, FIXME.- Throws:
SAXException
-