Save This Page
Home » openjdk-7 » com.sun.org.apache.xml.internal » dtm » ref » [javadoc | source]
com.sun.org.apache.xml.internal.dtm.ref
final class: IncrementalSAXSource_Filter [javadoc | source]
java.lang.Object
   com.sun.org.apache.xml.internal.dtm.ref.IncrementalSAXSource_Filter

All Implemented Interfaces:
    ContentHandler, DTDHandler, IncrementalSAXSource, Runnable, ErrorHandler, LexicalHandler

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. This class is final and package private for security reasons. Please see CR 6537912 for further details.
Nested Class Summary:
class  IncrementalSAXSource_Filter.StopException  Used to quickly terminate parse when running under a startParse() thread. Only its type is important. 
Field Summary
 boolean DEBUG     
Constructor:
 public 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 from com.sun.org.apache.xml.internal.dtm.ref.IncrementalSAXSource_Filter Summary:
characters,   comment,   count_and_yield,   createIncrementalSAXSource,   deliverMoreNodes,   endCDATA,   endDTD,   endDocument,   endElement,   endEntity,   endPrefixMapping,   error,   fatalError,   getControllerCoroutineID,   getCoroutineManager,   getSourceCoroutineID,   ignorableWhitespace,   init,   notationDecl,   processingInstruction,   run,   setContentHandler,   setDTDHandler,   setDocumentLocator,   setErrHandler,   setLexicalHandler,   setReturnFrequency,   setXMLReader,   skippedEntity,   startCDATA,   startDTD,   startDocument,   startElement,   startEntity,   startParse,   startPrefixMapping,   unparsedEntityDecl,   warning
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.sun.org.apache.xml.internal.dtm.ref.IncrementalSAXSource_Filter Detail:
 public  void characters(char[] ch,
    int start,
    int length) throws SAXException 
 public  void comment(char[] ch,
    int start,
    int length) throws SAXException 
 protected  void count_and_yield(boolean moreExpected) throws SAXException 

    In the SAX delegation code, I've inlined the count-down in the hope of encouraging compilers to deliver better performance. However, if we subclass (eg to directly connect the output to a DTM builder), that would require calling super in order to run that logic... which seems inelegant. Hence this routine for the convenience of subclasses: every [frequency] invocations, issue a co_yield.

 public static IncrementalSAXSource createIncrementalSAXSource(CoroutineManager co,
    int controllerCoroutineID) 
 public 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.
 public  void endCDATA() throws SAXException 
 public  void endDTD() throws SAXException 
 public  void endDocument() throws SAXException 
 public  void endElement(String namespaceURI,
    String localName,
    String qName) throws SAXException 
 public  void endEntity(String name) throws SAXException 
 public  void endPrefixMapping(String prefix) throws SAXException 
 public  void error(SAXParseException exception) throws SAXException 
 public  void fatalError(SAXParseException exception) throws SAXException 
 public int getControllerCoroutineID() 
 public CoroutineManager getCoroutineManager() 
 public int getSourceCoroutineID() 
 public  void ignorableWhitespace(char[] ch,
    int start,
    int length) throws SAXException 
 public  void init(CoroutineManager co,
    int controllerCoroutineID,
    int sourceCoroutineID) 
 public  void notationDecl(String a,
    String b,
    String c) throws SAXException 
 public  void processingInstruction(String target,
    String data) throws SAXException 
 public  void run() 
 public  void setContentHandler(ContentHandler handler) 
 public  void setDTDHandler(DTDHandler handler) 
 public  void setDocumentLocator(Locator locator) 
 public  void setErrHandler(ErrorHandler handler) 
 public  void setLexicalHandler(LexicalHandler handler) 
 public  void setReturnFrequency(int events) 
 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.
 public  void skippedEntity(String name) throws SAXException 
 public  void startCDATA() throws SAXException 
 public  void startDTD(String name,
    String publicId,
    String systemId) throws SAXException 
 public  void startDocument() throws SAXException 
 public  void startElement(String namespaceURI,
    String localName,
    String qName,
    Attributes atts) throws SAXException 
 public  void startEntity(String name) throws SAXException 
 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.
 public  void startPrefixMapping(String prefix,
    String uri) throws SAXException 
 public  void unparsedEntityDecl(String a,
    String b,
    String c,
    String d) throws SAXException 
 public  void warning(SAXParseException exception) throws SAXException