|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.xml.dtm.ref.IncrementalSAXSource_Filter
public class IncrementalSAXSource_Filter
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.
Nested Class Summary | |
---|---|
(package private) static class |
IncrementalSAXSource_Filter.StopException
Used to quickly terminate parse when running under a startParse() thread. |
Field Summary | |
---|---|
private org.xml.sax.ContentHandler |
clientContentHandler
|
private org.xml.sax.DTDHandler |
clientDTDHandler
|
private org.xml.sax.ErrorHandler |
clientErrorHandler
|
private org.xml.sax.ext.LexicalHandler |
clientLexicalHandler
|
(package private) boolean |
DEBUG
|
private int |
eventcounter
|
private int |
fControllerCoroutineID
|
private CoroutineManager |
fCoroutineManager
|
private boolean |
fNoMoreEvents
|
private int |
frequency
|
private int |
fSourceCoroutineID
|
private org.xml.sax.XMLReader |
fXMLReader
|
private org.xml.sax.InputSource |
fXMLReaderInputSource
|
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)
|
private void |
co_entry_pause()
co_entry_pause is called in startDocument() before anything else happens. |
private void |
co_yield(boolean moreRemains)
Co_Yield handles coroutine interactions while a parse is in progress. |
void |
comment(char[] ch,
int start,
int length)
|
protected void |
count_and_yield(boolean moreExpected)
In the SAX delegation code, I've inlined the count-down in the hope of encouraging compilers to deliver better performance. |
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(org.xml.sax.SAXParseException exception)
|
void |
fatalError(org.xml.sax.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(org.xml.sax.ContentHandler handler)
Register a SAX-style content handler for us to output to |
void |
setDocumentLocator(org.xml.sax.Locator locator)
|
void |
setDTDHandler(org.xml.sax.DTDHandler handler)
Register a SAX-style DTD handler for us to output to |
void |
setErrHandler(org.xml.sax.ErrorHandler handler)
|
void |
setLexicalHandler(org.xml.sax.ext.LexicalHandler handler)
Register a SAX-style lexical handler for us to output to |
void |
setReturnFrequency(int events)
|
void |
setXMLReader(org.xml.sax.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,
org.xml.sax.Attributes atts)
|
void |
startEntity(java.lang.String name)
|
void |
startParse(org.xml.sax.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(org.xml.sax.SAXParseException exception)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
boolean DEBUG
private CoroutineManager fCoroutineManager
private int fControllerCoroutineID
private int fSourceCoroutineID
private org.xml.sax.ContentHandler clientContentHandler
private org.xml.sax.ext.LexicalHandler clientLexicalHandler
private org.xml.sax.DTDHandler clientDTDHandler
private org.xml.sax.ErrorHandler clientErrorHandler
private int eventcounter
private int frequency
private boolean fNoMoreEvents
private org.xml.sax.XMLReader fXMLReader
private org.xml.sax.InputSource fXMLReaderInputSource
Constructor Detail |
---|
public IncrementalSAXSource_Filter()
public IncrementalSAXSource_Filter(CoroutineManager co, int controllerCoroutineID)
Method Detail |
---|
public static IncrementalSAXSource createIncrementalSAXSource(CoroutineManager co, int controllerCoroutineID)
public void init(CoroutineManager co, int controllerCoroutineID, int sourceCoroutineID)
public void setXMLReader(org.xml.sax.XMLReader eventsource)
public void setContentHandler(org.xml.sax.ContentHandler handler)
IncrementalSAXSource
setContentHandler
in interface IncrementalSAXSource
public void setDTDHandler(org.xml.sax.DTDHandler handler)
IncrementalSAXSource
setDTDHandler
in interface IncrementalSAXSource
public void setLexicalHandler(org.xml.sax.ext.LexicalHandler handler)
IncrementalSAXSource
setLexicalHandler
in interface IncrementalSAXSource
public void setErrHandler(org.xml.sax.ErrorHandler handler)
public void setReturnFrequency(int events)
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
characters
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void endDocument() throws org.xml.sax.SAXException
endDocument
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
endElement
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
endPrefixMapping
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
ignorableWhitespace
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
processingInstruction
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator
in interface org.xml.sax.ContentHandler
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
skippedEntity
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void startDocument() throws org.xml.sax.SAXException
startDocument
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
startElement
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException
startPrefixMapping
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public void comment(char[] ch, int start, int length) throws org.xml.sax.SAXException
comment
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
public void endCDATA() throws org.xml.sax.SAXException
endCDATA
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
public void endDTD() throws org.xml.sax.SAXException
endDTD
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
public void endEntity(java.lang.String name) throws org.xml.sax.SAXException
endEntity
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
public void startCDATA() throws org.xml.sax.SAXException
startCDATA
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
startDTD
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
public void startEntity(java.lang.String name) throws org.xml.sax.SAXException
startEntity
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
public void notationDecl(java.lang.String a, java.lang.String b, java.lang.String c) throws org.xml.sax.SAXException
notationDecl
in interface org.xml.sax.DTDHandler
org.xml.sax.SAXException
public void unparsedEntityDecl(java.lang.String a, java.lang.String b, java.lang.String c, java.lang.String d) throws org.xml.sax.SAXException
unparsedEntityDecl
in interface org.xml.sax.DTDHandler
org.xml.sax.SAXException
public void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
error
in interface org.xml.sax.ErrorHandler
org.xml.sax.SAXException
public void fatalError(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
fatalError
in interface org.xml.sax.ErrorHandler
org.xml.sax.SAXException
public void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
warning
in interface org.xml.sax.ErrorHandler
org.xml.sax.SAXException
public int getSourceCoroutineID()
public int getControllerCoroutineID()
public CoroutineManager getCoroutineManager()
protected void count_and_yield(boolean moreExpected) throws org.xml.sax.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.
moreExepected
- Should always be true unless this is being called
at the end of endDocument() handling.
org.xml.sax.SAXException
private void co_entry_pause() throws org.xml.sax.SAXException
org.xml.sax.SAXException
private void co_yield(boolean moreRemains) throws org.xml.sax.SAXException
org.xml.sax.SAXException
public void startParse(org.xml.sax.InputSource source) throws org.xml.sax.SAXException
startParse
in interface IncrementalSAXSource
org.xml.sax.SAXException
- is parse thread is already in progress
or parsing can not be started.public void run()
run
in interface java.lang.Runnable
public java.lang.Object deliverMoreNodes(boolean parsemore)
deliverMoreNodes
in interface IncrementalSAXSource
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |