Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.xml.dtm.ref
Class IncrementalSAXSource_Filter

    java.lang.Object
      |
      +--org.apache.xml.dtm.ref.IncrementalSAXSource_Filter

public class IncrementalSAXSource_Filter
extends java.lang.Object
implements IncrementalSAXSource, ContentHandler, DTDHandler, LexicalHandler, ErrorHandler, java.lang.Runnable

IncrementalSAXSource_Filter implements IncrementalSAXSource, using a standard SAX2 event source as its input and parcelling out those events gradually in reponse to deliverMoreNodes() requests. Output from the filter will be passed along to a SAX handler registered as our listener, but those callbacks will pass through a counting stage which periodically yields control back to the controller coroutine.

%REVIEW%: This filter is not currenly intended to be reusable for parsing additional streams/documents. We may want to consider making it resettable at some point in the future. But it's a small object, so that'd be mostly a convenience issue; the cost of allocating each time is trivial compared to the cost of processing any nontrival stream.

For a brief usage example, see the unit-test main() method.

This is a simplification of the old CoroutineSAXParser, focusing specifically on filtering. The resulting controller protocol is _far_ simpler and less error-prone; the only controller operation is deliverMoreNodes(), and the only requirement is that deliverMoreNodes(false) be called if you want to discard the rest of the stream and the previous deliverMoreNodes() didn't return false.

Constructor Summary
`IncrementalSAXSource_Filter()`
`IncrementalSAXSource_Filter(CoroutineManager co, int controllerCoroutineID)` Create a IncrementalSAXSource_Filter which is not yet bound to a specific SAX event source.

Method Summary
`void` | `characters(char[] ch, int start, int length)`
`void` | `comment(char[] ch, int start, int length)`
`static IncrementalSAXSource` | `createIncrementalSAXSource(CoroutineManager co, int controllerCoroutineID)`
`java.lang.Object` | `deliverMoreNodes(boolean parsemore)` deliverMoreNodes() is a simple API which tells the coroutine parser that we need more nodes.
`void` | `endCDATA()`
`void` | `endDocument()`
`void` | `endDTD()`
`void` | `endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)`
`void` | `endEntity(java.lang.String name)`
`void` | `endPrefixMapping(java.lang.String prefix)`
`void` | `error(SAXParseException exception)`
`void` | `fatalError(SAXParseException exception)`
`int` | `getControllerCoroutineID()`
`CoroutineManager` | `getCoroutineManager()`
`int` | `getSourceCoroutineID()`
`void` | `ignorableWhitespace(char[] ch, int start, int length)`
`void` | `init(CoroutineManager co, int controllerCoroutineID, int sourceCoroutineID)`
`void` | `notationDecl(java.lang.String a, java.lang.String b, java.lang.String c)`
`void` | `processingInstruction(java.lang.String target, java.lang.String data)`
`void` | `run()`
`void` | `setContentHandler(ContentHandler handler)`
`void` | `setDocumentLocator(Locator locator)`
`void` | `setDTDHandler(DTDHandler handler)`
`void` | `setErrHandler(ErrorHandler handler)`
`void` | `setLexicalHandler(LexicalHandler handler)`
`void` | `setReturnFrequency(int events)`
`void` | `setXMLReader(XMLReader eventsource)` Bind our input streams to an XMLReader.
`void` | `skippedEntity(java.lang.String name)`
`void` | `startCDATA()`
`void` | `startDocument()`
`void` | `startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)`
`void` | `startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, Attributes atts)`
`void` | `startEntity(java.lang.String name)`
`void` | `startParse(InputSource source)` Launch a thread that will run an XMLReader's parse() operation within a thread, feeding events to this IncrementalSAXSource_Filter.
`void` | `startPrefixMapping(java.lang.String prefix, java.lang.String uri)`
`void` | `unparsedEntityDecl(java.lang.String a, java.lang.String b, java.lang.String c, java.lang.String d)`
`void` | `warning(SAXParseException exception)`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### IncrementalSAXSource_Filter

    public IncrementalSAXSource_Filter()

### IncrementalSAXSource_Filter

    public IncrementalSAXSource_Filter(CoroutineManager co,
                                       int controllerCoroutineID)

  Create a IncrementalSAXSource_Filter which is not yet bound to a specific SAX event source.

Method Detail

### createIncrementalSAXSource

    public static IncrementalSAXSource createIncrementalSAXSource(CoroutineManager co,
                                                                  int controllerCoroutineID)

### init

    public void init(CoroutineManager co,
                     int controllerCoroutineID,
                     int sourceCoroutineID)

### setXMLReader

    public void setXMLReader(XMLReader eventsource)

  Bind our input streams to an XMLReader. Just a convenience routine; obviously you can explicitly register this as a listener with the same effect.

### setContentHandler

    public void setContentHandler(ContentHandler handler)

  Specified by:
    setContentHandler in interface IncrementalSAXSource

### setDTDHandler

    public void setDTDHandler(DTDHandler handler)

  Specified by:
    setDTDHandler in interface IncrementalSAXSource

### setLexicalHandler

    public void setLexicalHandler(LexicalHandler handler)

  Specified by:
    setLexicalHandler in interface IncrementalSAXSource

### setErrHandler

    public void setErrHandler(ErrorHandler handler)

### setReturnFrequency

    public void setReturnFrequency(int events)

### characters

    public void characters(char[] ch,
                           int start,
                           int length)
                    throws SAXException

  Specified by:
    characters in interface ContentHandler

### endDocument

    public void endDocument()
                     throws SAXException

  Specified by:
    endDocument in interface ContentHandler

### endElement

    public void endElement(java.lang.String namespaceURI,
                           java.lang.String localName,
                           java.lang.String qName)
                    throws SAXException

  Specified by:
    endElement in interface ContentHandler

### endPrefixMapping

    public void endPrefixMapping(java.lang.String prefix)
                          throws SAXException

  Specified by:
    endPrefixMapping in interface ContentHandler

### ignorableWhitespace

    public void ignorableWhitespace(char[] ch,
                                    int start,
                                    int length)
                             throws SAXException

  Specified by:
    ignorableWhitespace in interface ContentHandler

### processingInstruction

    public void processingInstruction(java.lang.String target,
                                      java.lang.String data)
                               throws SAXException

  Specified by:
    processingInstruction in interface ContentHandler

### setDocumentLocator

    public void setDocumentLocator(Locator locator)

  Specified by:
    setDocumentLocator in interface ContentHandler

### skippedEntity

    public void skippedEntity(java.lang.String name)
                       throws SAXException

  Specified by:
    skippedEntity in interface ContentHandler

### startDocument

    public void startDocument()
                       throws SAXException

  Specified by:
    startDocument in interface ContentHandler

### startElement

    public void startElement(java.lang.String namespaceURI,
                             java.lang.String localName,
                             java.lang.String qName,
                             Attributes atts)
                      throws SAXException

  Specified by:
    startElement in interface ContentHandler

### startPrefixMapping

    public void startPrefixMapping(java.lang.String prefix,
                                   java.lang.String uri)
                            throws SAXException

  Specified by:
    startPrefixMapping in interface ContentHandler

### comment

    public void comment(char[] ch,
                        int start,
                        int length)
                 throws SAXException

  Specified by:
    comment in interface LexicalHandler

### endCDATA

    public void endCDATA()
                  throws SAXException

  Specified by:
    endCDATA in interface LexicalHandler

### endDTD

    public void endDTD()
                throws SAXException

  Specified by:
    endDTD in interface LexicalHandler

### endEntity

    public void endEntity(java.lang.String name)
                   throws SAXException

  Specified by:
    endEntity in interface LexicalHandler

### startCDATA

    public void startCDATA()
                    throws SAXException

  Specified by:
    startCDATA in interface LexicalHandler

### startDTD

    public void startDTD(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws SAXException

  Specified by:
    startDTD in interface LexicalHandler

### startEntity

    public void startEntity(java.lang.String name)
                     throws SAXException

  Specified by:
    startEntity in interface LexicalHandler

### notationDecl

    public void notationDecl(java.lang.String a,
                             java.lang.String b,
                             java.lang.String c)
                      throws SAXException

  Specified by:
    notationDecl in interface DTDHandler

### unparsedEntityDecl

    public void unparsedEntityDecl(java.lang.String a,
                                   java.lang.String b,
                                   java.lang.String c,
                                   java.lang.String d)
                            throws SAXException

  Specified by:
    unparsedEntityDecl in interface DTDHandler

### error

    public void error(SAXParseException exception)
               throws SAXException

  Specified by:
    error in interface ErrorHandler

### fatalError

    public void fatalError(SAXParseException exception)
                    throws SAXException

  Specified by:
    fatalError in interface ErrorHandler

### warning

    public void warning(SAXParseException exception)
                 throws SAXException

  Specified by:
    warning in interface ErrorHandler

### getSourceCoroutineID

    public int getSourceCoroutineID()

### getControllerCoroutineID

    public int getControllerCoroutineID()

### getCoroutineManager

    public CoroutineManager getCoroutineManager()

  Returns:
    the CoroutineManager this CoroutineFilter object is bound to. If you're using the do...() methods, applications should only need to talk to the CoroutineManager once, to obtain the application's Coroutine ID.

### startParse

    public void startParse(InputSource source)
                    throws SAXException

  Launch a thread that will run an XMLReader's parse() operation within a thread, feeding events to this IncrementalSAXSource_Filter. Mostly a convenience routine, but has the advantage that -- since we invoked parse() -- we can halt parsing quickly via a StopException rather than waiting for the SAX stream to end by itself.
  Specified by:
    startParse in interface IncrementalSAXSource
  Throws:
    SAXException - is parse thread is already in progress or parsing can not be started.

### run

    public void run()

  Specified by:
    run in interface java.lang.Runnable

### deliverMoreNodes

    public java.lang.Object deliverMoreNodes(boolean parsemore)

  deliverMoreNodes() is a simple API which tells the coroutine parser that we need more nodes. This is intended to be called from one of our partner routines, and serves to encapsulate the details of how incremental parsing has been achieved.
  Specified by:
    deliverMoreNodes in interface IncrementalSAXSource
  Parameters:
    `parsemore` - If true, tells the incremental filter to generate another chunk of output. If false, tells the filter that we're satisfied and it can terminate parsing of this document.
  Returns:
    Boolean.TRUE if there may be more events available by invoking deliverMoreNodes() again. Boolean.FALSE if parsing has run to completion (or been terminated by deliverMoreNodes(false). Or an exception object if something malfunctioned. %REVIEW% We _could_ actually throw the exception, but that would require runinng deliverMoreNodes() in a try/catch... and for many applications, exception will be simply be treated as "not TRUE" in any case.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2006 Apache XML Project. All Rights Reserved.