Class NGCCRuntime
- All Implemented Interfaces:
NGCCEventSource,ContentHandler
- Direct Known Subclasses:
NGCCRuntimeEx
- Managing a stack of NGCCHandler objects and switching between them appropriately.
- Keep track of all Attributes.
- manage mapping between namespace URIs and prefixes.
- TODO: provide support for interleaving.
- Version:
- $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Stackstack ofAttributes.private AttributesImplcurrent attributes set.private NGCCEventReceiverThe current NGCCHandler.(package private) static final StringImpossible token.private intprivate Locatorprivate final ArrayListin-scope namespace mapping.private booleanprivate intIndex on the namespaces array, which points to the top of the effective bindings.private final StackStack to preserve old nsEffectivePtr values.private ContentHandlerWhen redirecting a sub-tree, this value will be non-null.private intCounts the depth of the elements when we are re-directing a sub-tree to another ContentHandler.private StringBufferaccumulated text. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(char[] ch, int start, int length) voidconsumeAttribute(int index) voidvoidendElement(String uri, String localname, String qname) voidendPrefixMapping(String prefix) intgetAttributeIndex(String uri, String localname) Attributes that belong to the current element.Gets the source location of the current event.voidignorableWhitespace(char[] ch, int start, int length) voidonEnterElementConsumed(String uri, String localName, String qname, Attributes atts) Called by the generated handler code when an enter element event is consumed.voidonLeaveElementConsumed(String uri, String localName, String qname) private voidvoidprocessingInstruction(String target, String data) voidprocessList(String str) private voidprocessPendingText(boolean ignorable) Processes buffered text.voidredirectSubtree(ContentHandler child, String uri, String local, String qname) This method can be called only from the enterElement handler.intReplaces an old handler with a new handler, and returns ID of the EventReceiver thread.voidreset()Cleans up all the data structure so that the object can be reused later.resolveNamespacePrefix(String prefix) voidsendEnterAttribute(int threadId, String uri, String local, String qname) voidsendEnterElement(int threadId, String uri, String local, String qname, Attributes atts) Sends an enter element event to the specified EventReceiver thread.voidsendLeaveAttribute(int threadId, String uri, String local, String qname) voidsendLeaveElement(int threadId, String uri, String local, String qname) voidvoidsetDocumentLocator(Locator _loc) voidsetRootHandler(NGCCHandler rootHandler) Sets the root handler, which will be used to parse the root element.voidskippedEntity(String name) voidvoidstartElement(String uri, String localname, String qname, Attributes atts) voidstartPrefixMapping(String prefix, String uri) voidvoidprotected voidunexpectedX(String token)
-
Field Details
-
locator
-
attStack
stack ofAttributes. -
currentAtts
current attributes set. always equal to attStack.peek() -
text
accumulated text. -
currentHandler
The current NGCCHandler. Always equals to handlerStack.peek() -
IMPOSSIBLE
Impossible token. This value can never be a valid XML name.- See Also:
-
redirect
When redirecting a sub-tree, this value will be non-null. -
redirectionDepth
private int redirectionDepthCounts the depth of the elements when we are re-directing a sub-tree to another ContentHandler. -
namespaces
in-scope namespace mapping. namespaces[2n ] := prefix namespaces[2n+1] := namespace URI -
nsEffectivePtr
private int nsEffectivePtrIndex on the namespaces array, which points to the top of the effective bindings. Because of the timing difference between the startPrefixMapping method and the execution of the corresponding actions, this value can be different fromnamespaces.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 -
nsEffectiveStack
Stack to preserve old nsEffectivePtr values. -
indent
private int indent -
needIndent
private boolean needIndent
-
-
Constructor Details
-
NGCCRuntime
public NGCCRuntime()
-
-
Method Details
-
setRootHandler
Sets the root handler, which will be used to parse the root element.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.
- Throws:
IllegalStateException- If this method is called but it doesn't satisfy the pre-condition stated above.
-
reset
public void reset()Cleans up all the data structure so that the object can be reused later. Normally, applications do not need to call this method directly, as the runtime resets itself after the endDocument method. -
setDocumentLocator
- Specified by:
setDocumentLocatorin interfaceContentHandler
-
getLocator
Gets the source location of the current event.One can call this method from RelaxNGCC handlers to access the line number information. Note that to
-
getCurrentAttributes
Attributes that belong to the current element.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.
-
replace
Description copied from interface:NGCCEventSourceReplaces an old handler with a new handler, and returns ID of the EventReceiver thread.- Specified by:
replacein interfaceNGCCEventSource
-
processPendingText
Processes buffered text. This method will be called by the start/endElement event to process buffered text as a text event.Whitespace handling is a tricky business. Consider the following schema fragment:
Assume we hit the following instance: Then this first space needs to be ignored (for otherwise, we will end up treating this space as the match to <text/> and won't be able to process <bar>.) Now assume the following instance: This time, we need to treat this empty string as a text, for otherwise we won't be able to accept this instance.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/>.
- Parameters:
possiblyWhitespace- True if the buffered character can be ignorabale. False if it needs to be consumed.- Throws:
SAXException
-
processList
- Throws:
SAXException
-
startElement
public void startElement(String uri, String localname, String qname, Attributes atts) throws SAXException - Specified by:
startElementin interfaceContentHandler- Throws:
SAXException
-
onEnterElementConsumed
public void onEnterElementConsumed(String uri, String localName, String qname, Attributes atts) throws SAXException Called by the generated handler code when an enter element event is consumed.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.
- Throws:
SAXException
-
onLeaveElementConsumed
- Throws:
SAXException
-
endElement
- Specified by:
endElementin interfaceContentHandler- Throws:
SAXException
-
characters
- Specified by:
charactersin interfaceContentHandler- Throws:
SAXException
-
ignorableWhitespace
- Specified by:
ignorableWhitespacein interfaceContentHandler- Throws:
SAXException
-
getAttributeIndex
-
consumeAttribute
- Throws:
SAXException
-
startPrefixMapping
- Specified by:
startPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
endPrefixMapping
- Specified by:
endPrefixMappingin interfaceContentHandler- Throws:
SAXException
-
skippedEntity
- Specified by:
skippedEntityin interfaceContentHandler- Throws:
SAXException
-
processingInstruction
- Specified by:
processingInstructionin interfaceContentHandler- Throws:
SAXException
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Throws:
SAXException
-
startDocument
public void startDocument()- Specified by:
startDocumentin interfaceContentHandler
-
sendEnterAttribute
public void sendEnterAttribute(int threadId, String uri, String local, String qname) throws SAXException - Specified by:
sendEnterAttributein interfaceNGCCEventSource- Throws:
SAXException
-
sendEnterElement
public void sendEnterElement(int threadId, String uri, String local, String qname, Attributes atts) throws SAXException Description copied from interface:NGCCEventSourceSends an enter element event to the specified EventReceiver thread.- Specified by:
sendEnterElementin interfaceNGCCEventSource- Throws:
SAXException
-
sendLeaveAttribute
public void sendLeaveAttribute(int threadId, String uri, String local, String qname) throws SAXException - Specified by:
sendLeaveAttributein interfaceNGCCEventSource- Throws:
SAXException
-
sendLeaveElement
public void sendLeaveElement(int threadId, String uri, String local, String qname) throws SAXException - Specified by:
sendLeaveElementin interfaceNGCCEventSource- Throws:
SAXException
-
sendText
- Specified by:
sendTextin interfaceNGCCEventSource- Throws:
SAXException
-
redirectSubtree
public void redirectSubtree(ContentHandler child, String uri, String local, String qname) throws SAXException This method can be called only from the enterElement handler. The sub-tree rooted at the new element will be redirected to the specified ContentHandler.Currently active NGCCHandler will only receive the leaveElement event of the newly started element.
- Parameters:
uri- ,local,qname Parameters passed to the enter element event. Used to simulate the startElement event for the new ContentHandler.- Throws:
SAXException
-
resolveNamespacePrefix
-
unexpectedX
- Throws:
SAXException
-
printIndent
private void printIndent() -
trace
-
traceln
-