public class NGCCRuntime extends java.lang.Object implements org.xml.sax.ContentHandler, NGCCEventSource
Modifier and Type | Field and Description |
---|---|
private java.util.Stack |
attStack
stack of
Attributes . |
private AttributesImpl |
currentAtts
current attributes set.
|
private NGCCEventReceiver |
currentHandler
The current NGCCHandler.
|
(package private) static java.lang.String |
IMPOSSIBLE
Impossible token.
|
private int |
indent |
private org.xml.sax.Locator |
locator |
private java.util.ArrayList |
namespaces
in-scope namespace mapping.
|
private boolean |
needIndent |
private int |
nsEffectivePtr
Index on the namespaces array, which points to
the top of the effective bindings.
|
private java.util.Stack |
nsEffectiveStack
Stack to preserve old nsEffectivePtr values.
|
private org.xml.sax.ContentHandler |
redirect
When redirecting a sub-tree, this value will be non-null.
|
private int |
redirectionDepth
Counts the depth of the elements when we are re-directing
a sub-tree to another ContentHandler.
|
private java.lang.StringBuffer |
text
accumulated text.
|
Constructor and Description |
---|
NGCCRuntime() |
Modifier and Type | Method and Description |
---|---|
void |
characters(char[] ch,
int start,
int length) |
void |
consumeAttribute(int index) |
void |
endDocument() |
void |
endElement(java.lang.String uri,
java.lang.String localname,
java.lang.String qname) |
void |
endPrefixMapping(java.lang.String prefix) |
int |
getAttributeIndex(java.lang.String uri,
java.lang.String localname) |
org.xml.sax.Attributes |
getCurrentAttributes()
Attributes that belong to the current element.
|
org.xml.sax.Locator |
getLocator()
Gets the source location of the current event.
|
void |
ignorableWhitespace(char[] ch,
int start,
int length) |
void |
onEnterElementConsumed(java.lang.String uri,
java.lang.String localName,
java.lang.String qname,
org.xml.sax.Attributes atts)
Called by the generated handler code when an enter element
event is consumed.
|
void |
onLeaveElementConsumed(java.lang.String uri,
java.lang.String localName,
java.lang.String qname) |
private void |
printIndent() |
void |
processingInstruction(java.lang.String target,
java.lang.String data) |
void |
processList(java.lang.String str) |
private void |
processPendingText(boolean ignorable)
Processes buffered text.
|
void |
redirectSubtree(org.xml.sax.ContentHandler child,
java.lang.String uri,
java.lang.String local,
java.lang.String qname)
This method can be called only from the enterElement handler.
|
int |
replace(NGCCEventReceiver o,
NGCCEventReceiver n)
Replaces an old handler with a new handler, and returns
ID of the EventReceiver thread.
|
void |
reset()
Cleans up all the data structure so that the object can be reused later.
|
java.lang.String |
resolveNamespacePrefix(java.lang.String prefix) |
void |
sendEnterAttribute(int threadId,
java.lang.String uri,
java.lang.String local,
java.lang.String qname) |
void |
sendEnterElement(int threadId,
java.lang.String uri,
java.lang.String local,
java.lang.String qname,
org.xml.sax.Attributes atts)
Sends an enter element event to the specified EventReceiver thread.
|
void |
sendLeaveAttribute(int threadId,
java.lang.String uri,
java.lang.String local,
java.lang.String qname) |
void |
sendLeaveElement(int threadId,
java.lang.String uri,
java.lang.String local,
java.lang.String qname) |
void |
sendText(int threadId,
java.lang.String value) |
void |
setDocumentLocator(org.xml.sax.Locator _loc) |
void |
setRootHandler(NGCCHandler rootHandler)
Sets the root handler, which will be used to parse the
root element.
|
void |
skippedEntity(java.lang.String name) |
void |
startDocument() |
void |
startElement(java.lang.String uri,
java.lang.String localname,
java.lang.String qname,
org.xml.sax.Attributes atts) |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri) |
void |
trace(java.lang.String s) |
void |
traceln(java.lang.String s) |
protected void |
unexpectedX(java.lang.String token) |
private org.xml.sax.Locator locator
private final java.util.Stack attStack
Attributes
.private AttributesImpl currentAtts
private java.lang.StringBuffer text
private NGCCEventReceiver currentHandler
static final java.lang.String IMPOSSIBLE
private org.xml.sax.ContentHandler redirect
private int redirectionDepth
private final java.util.ArrayList namespaces
private int nsEffectivePtr
namespaces.size()
.
For example, consider the following schema:
Code fragment X is executed after we see a startElement event, but at this time the namespaces variable already include new namespace bindings declared on "bob".code fragment X
private final java.util.Stack nsEffectiveStack
private int indent
private boolean needIndent
public void setRootHandler(NGCCHandler rootHandler)
This method can be called right after the object is created or the reset method is called. You can't replace the root handler while parsing is in progress.
Usually a generated class that corresponds to the <start> pattern will be used as the root handler, but any NGCCHandler can be a root handler.
java.lang.IllegalStateException
- If this method is called but it doesn't satisfy the
pre-condition stated above.public void reset()
public void setDocumentLocator(org.xml.sax.Locator _loc)
setDocumentLocator
in interface org.xml.sax.ContentHandler
public org.xml.sax.Locator getLocator()
One can call this method from RelaxNGCC handlers to access the line number information. Note that to
public org.xml.sax.Attributes getCurrentAttributes()
It's generally not recommended for applications to use this method. RelaxNGCC internally removes processed attributes, so this doesn't correctly reflect all the attributes an element carries.
public int replace(NGCCEventReceiver o, NGCCEventReceiver n)
NGCCEventSource
replace
in interface NGCCEventSource
private void processPendingText(boolean ignorable) throws org.xml.sax.SAXException
Whitespace handling is a tricky business. Consider the following schema fragment:
This is very difficult to solve in general, but one seemingly easy solution is to use the type of next event. If a text is followed by a start tag, it follows from the constraint on RELAX NG that that text must be either whitespaces or a match to <text/>.
On the contrary, if a text is followed by a end tag, then it cannot be whitespace unless the content model can accept empty, in which case sending a text event will be harmlessly ignored by the NGCCHandler.
Thus this method take one parameter, which controls the behavior of this method.
TODO: according to the constraint of RELAX NG, if characters follow an end tag, then they must be either whitespaces or must match to <text/>.
possiblyWhitespace
- True if the buffered character can be ignorabale. False if
it needs to be consumed.org.xml.sax.SAXException
public void processList(java.lang.String str) throws org.xml.sax.SAXException
org.xml.sax.SAXException
public void startElement(java.lang.String uri, 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 onEnterElementConsumed(java.lang.String uri, java.lang.String localName, java.lang.String qname, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
Pushes a new attribute set.
Note that attributes are NOT pushed at the startElement method, because the processing of the enterElement event can trigger other attribute events and etc.
This method will be called from one of handlers when it truely consumes the enterElement event.
org.xml.sax.SAXException
public void onLeaveElementConsumed(java.lang.String uri, java.lang.String localName, java.lang.String qname) throws org.xml.sax.SAXException
org.xml.sax.SAXException
public void endElement(java.lang.String uri, 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 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 ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
ignorableWhitespace
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
public int getAttributeIndex(java.lang.String uri, java.lang.String localname)
public void consumeAttribute(int index) throws org.xml.sax.SAXException
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 endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
endPrefixMapping
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
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 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 endDocument() throws org.xml.sax.SAXException
endDocument
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 sendEnterAttribute(int threadId, java.lang.String uri, java.lang.String local, java.lang.String qname) throws org.xml.sax.SAXException
sendEnterAttribute
in interface NGCCEventSource
org.xml.sax.SAXException
public void sendEnterElement(int threadId, java.lang.String uri, java.lang.String local, java.lang.String qname, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
NGCCEventSource
sendEnterElement
in interface NGCCEventSource
org.xml.sax.SAXException
public void sendLeaveAttribute(int threadId, java.lang.String uri, java.lang.String local, java.lang.String qname) throws org.xml.sax.SAXException
sendLeaveAttribute
in interface NGCCEventSource
org.xml.sax.SAXException
public void sendLeaveElement(int threadId, java.lang.String uri, java.lang.String local, java.lang.String qname) throws org.xml.sax.SAXException
sendLeaveElement
in interface NGCCEventSource
org.xml.sax.SAXException
public void sendText(int threadId, java.lang.String value) throws org.xml.sax.SAXException
sendText
in interface NGCCEventSource
org.xml.sax.SAXException
public void redirectSubtree(org.xml.sax.ContentHandler child, java.lang.String uri, java.lang.String local, java.lang.String qname) throws org.xml.sax.SAXException
Currently active NGCCHandler will only receive the leaveElement event of the newly started element.
uri,local,qname
- Parameters passed to the enter element event. Used to
simulate the startElement event for the new ContentHandler.org.xml.sax.SAXException
public java.lang.String resolveNamespacePrefix(java.lang.String prefix)
protected void unexpectedX(java.lang.String token) throws org.xml.sax.SAXException
org.xml.sax.SAXException
private void printIndent()
public void trace(java.lang.String s)
public void traceln(java.lang.String s)