gnu.xml.pipeline

Class TeeConsumer

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

public final class TeeConsumer
extends 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)

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

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

TeeConsumer.java -- Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.