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.util2.SAXEventStream
SAXEventStream.EtherealMatcher, SAXEventStream.MatchException
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) @Opt XMLDocumentIdentifier
_getDocumentId
(eu.bandm.tools.util2.SAXEventQueue.Item item) void
characters
(char[] data, int offset, int length) void
clear()
FIXME benötigt??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 colleced 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) void
dump
(PrintStream os) void
endCDATA()
void
Write the last tag (a close 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
void
CHECK FIXME ist das wirklich "public" notwendig?Returns the local name of the current head, i.e.Delivers the location of the current NEXT Event, i.e.Returns the namespace name of the current head, i.e.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
void
setDocumentLocator
(Locator locator) void
setErrorHandler
(ErrorHandler errorHandler) void
sink()
FIXME DOKU WAS SOLL DAS ?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
protected void
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() -
SAXEventQueue
public SAXEventQueue(int size)
-
-
Method Details
-
setErrorHandler
-
getErrorHandler
-
clear
public void clear()FIXME benötigt?? -
sink
public void sink()FIXME DOKU WAS SOLL DAS ? -
dump
-
readInterrupted
protected void readInterrupted() -
writeInterrupted
protected void writeInterrupted() -
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 last tag (a close 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
- 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
- Specified by:
warning
in interfaceErrorHandler
- Throws:
SAXException
-
error
- Specified by:
error
in interfaceErrorHandler
- Throws:
SAXException
-
fatalError
- 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
Description copied from interface:SAXEventStream
Returns the namespace name of the current head, i.e. the next element to consume.- Specified by:
getNamespaceName
in interfaceSAXEventStream
-
consume
public final void consume()Must only be called after (at least) one invocation oflookahead()
. Afterwards,lookahead()
may may block again. GLO OUT consumedEthereals- Specified by:
consume
in interfaceSAXEventStream
-
consumedEthereals
Visits all ethereals which have been colleced 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
- Throws:
SAXException
-