gnu.xml.pipeline

Class TeeConsumer

Implemented Interfaces:
ContentHandler, DeclHandler, DTDHandler, EventConsumer, LexicalHandler

public final class TeeConsumer
extends java.lang.Object
implements EventConsumer, ContentHandler, DTDHandler, LexicalHandler, DeclHandler

Fans its events out to two other consumers, a "tee" filter stage in an event pipeline. Networks can be assembled with multiple output points.

Error handling should be simple if you remember that exceptions you throw will cancel later stages in that callback's pipeline, and generally the producer will stop if it sees such an exception. You may want to protect your pipeline against such backflows, making a kind of reverse filter (or valve?) so that certain exceptions thrown by your pipeline will caught and handled before the producer sees them. Just use a "try/catch" block, rememebering that really important cleanup tasks should be in "finally" clauses.

That issue isn't unique to "tee" consumers, but tee consumers have the additional twist that exceptions thrown by the first consumer will cause the second consumer not to see the callback (except for the endDocument callback, which signals state cleanup).

Constructor Summary

TeeConsumer(EventConsumer car, EventConsumer cdr)
Constructs a consumer which sends all its events to the first consumer, and then the second one.

Method Summary

void
attributeDecl(String eName, String aName, String type, String mode, String value)
void
characters(ch[] , int start, int length)
void
comment(ch[] , int start, int length)
void
elementDecl(String name, String model)
void
endCDATA()
void
endDTD()
void
endDocument()
void
endElement(String uri, String localName, String qName)
void
endEntity(String name)
void
endPrefixMapping(String prefix)
void
externalEntityDecl(String name, String publicId, String systemId)
ContentHandler
getContentHandler()
Returns the content handler being used.
DTDHandler
getDTDHandler()
Returns the dtd handler being used.
EventConsumer
getFirst()
Returns the first pipeline to get event calls.
Object
getProperty(String id)
Returns the declaration or lexical handler being used.
EventConsumer
getRest()
Returns the second pipeline to get event calls.
void
ignorableWhitespace(ch[] , int start, int length)
void
internalEntityDecl(String name, String value)
void
notationDecl(String name, String publicId, String systemId)
void
processingInstruction(String target, String data)
void
setDocumentLocator(Locator locator)
void
setErrorHandler(ErrorHandler handler)
Provides the error handler to both subsequent nodes of this filter stage.
void
skippedEntity(String name)
void
startCDATA()
void
startDTD(String name, String publicId, String systemId)
void
startDocument()
void
startElement(String uri, String localName, String qName, Attributes atts)
void
startEntity(String name)
void
startPrefixMapping(String prefix, String uri)
void
unparsedEntityDecl(String name, String publicId, String systemId, String notationName)

Constructor Details

TeeConsumer

public TeeConsumer(EventConsumer car,
                   EventConsumer cdr)
Constructs a consumer which sends all its events to the first consumer, and then the second one. If the first consumer throws an exception, the second one will not see the event which caused that exception to be reported.

Parameters:
car - The first consumer to get the events
cdr - The second consumer to get the events

Method Details

attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String mode,
                          String value)
            throws SAXException
Specified by:
attributeDecl in interface DeclHandler


characters

public void characters(ch[] ,
                       int start,
                       int length)
            throws SAXException
Specified by:
characters in interface ContentHandler


comment

public void comment(ch[] ,
                    int start,
                    int length)
            throws SAXException
Specified by:
comment in interface LexicalHandler


elementDecl

public void elementDecl(String name,
                        String model)
            throws SAXException
Specified by:
elementDecl in interface DeclHandler


endCDATA

public void endCDATA()
            throws SAXException
Specified by:
endCDATA in interface LexicalHandler


endDTD

public void endDTD()
            throws SAXException
Specified by:
endDTD in interface LexicalHandler


endDocument

public void endDocument()
            throws SAXException
Specified by:
endDocument in interface ContentHandler


endElement

public void endElement(String uri,
                       String localName,
                       String qName)
            throws SAXException
Specified by:
endElement in interface ContentHandler


endEntity

public void endEntity(String name)
            throws SAXException
Specified by:
endEntity in interface LexicalHandler


endPrefixMapping

public void endPrefixMapping(String prefix)
            throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler


externalEntityDecl

public void externalEntityDecl(String name,
                               String publicId,
                               String systemId)
            throws SAXException
Specified by:
externalEntityDecl in interface DeclHandler


getContentHandler

public final ContentHandler getContentHandler()
Returns the content handler being used.
Specified by:
getContentHandler in interface EventConsumer


getDTDHandler

public final DTDHandler getDTDHandler()
Returns the dtd handler being used.
Specified by:
getDTDHandler in interface EventConsumer


getFirst

public EventConsumer getFirst()
Returns the first pipeline to get event calls.


getProperty

public final Object getProperty(String id)
            throws SAXNotRecognizedException
Returns the declaration or lexical handler being used.
Specified by:
getProperty in interface EventConsumer


getRest

public EventConsumer getRest()
Returns the second pipeline to get event calls.


ignorableWhitespace

public void ignorableWhitespace(ch[] ,
                                int start,
                                int length)
            throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler


internalEntityDecl

public void internalEntityDecl(String name,
                               String value)
            throws SAXException
Specified by:
internalEntityDecl in interface DeclHandler


notationDecl

public void notationDecl(String name,
                         String publicId,
                         String systemId)
            throws SAXException
Specified by:
notationDecl in interface DTDHandler


processingInstruction

public void processingInstruction(String target,
                                  String data)
            throws SAXException
Specified by:
processingInstruction in interface ContentHandler


setDocumentLocator

public void setDocumentLocator(Locator locator)
Specified by:
setDocumentLocator in interface ContentHandler


setErrorHandler

public void setErrorHandler(ErrorHandler handler)
Provides the error handler to both subsequent nodes of this filter stage.
Specified by:
setErrorHandler in interface EventConsumer


skippedEntity

public void skippedEntity(String name)
            throws SAXException
Specified by:
skippedEntity in interface ContentHandler


startCDATA

public void startCDATA()
            throws SAXException
Specified by:
startCDATA in interface LexicalHandler


startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
            throws SAXException
Specified by:
startDTD in interface LexicalHandler


startDocument

public void startDocument()
            throws SAXException
Specified by:
startDocument in interface ContentHandler


startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes atts)
            throws SAXException
Specified by:
startElement in interface ContentHandler


startEntity

public void startEntity(String name)
            throws SAXException
Specified by:
startEntity in interface LexicalHandler


startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
            throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler


unparsedEntityDecl

public void unparsedEntityDecl(String name,
                               String publicId,
                               String systemId,
                               String notationName)
            throws SAXException
Specified by:
unparsedEntityDecl in interface DTDHandler