Top Description Fields Constructors Methods
com.sun.tools.jxc.gen.config

public Class NGCCRuntime

extends Object
implements ContentHandler, NGCCEventSource
Class Inheritance
All Implemented Interfaces
com.sun.tools.jxc.gen.config.NGCCEventSource, org.xml.sax.ContentHandler
Known Direct Subclasses
com.sun.tools.jxc.NGCCRuntimeEx
Imports
java.text.MessageFormat, java.util.ArrayList, .List, .Stack, .StringTokenizer, org.xml.sax.Attributes, .ContentHandler, .Locator, .SAXException, .SAXParseException

Runtime Engine for RELAXNGCC execution. This class has the following functionalities:
  1. Managing a stack of NGCCHandler objects and switching between them appropriately.
  2. Keep track of all Attributes.
  3. manage mapping between namespace URIs and prefixes.
  4. TODO: provide support for interleaving.

Auto-generated, do not edit.

Author
Kohsuke Kawaguchi ([email protected])
Version
$Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $

Field Summary

Modifier and TypeField and Description
private final Stack<AttributesImpl>
private AttributesImpl
currentAtts

current attributes set.

private NGCCEventReceiver
currentHandler

The current NGCCHandler.

pack-priv static final String
IMPOSSIBLE

Impossible token.

private int
private Locator
private final List<String>
namespaces

in-scope namespace mapping.

private boolean
private int
nsEffectivePtr

Index on the namespaces array, which points to the top of the effective bindings.

private final Stack<Integer>
nsEffectiveStack

Stack to preserve old nsEffectivePtr values.

private 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 StringBuffer
text

accumulated text.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
characters(char[] ch, int start, int length)

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data.

public void
consumeAttribute(int index)

public void
endDocument()

Implements org.xml.sax.ContentHandler.endDocument.

Receive notification of the end of a document.

public void
endElement(String uri, String localname, String qname)

Implements org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.

public void
endPrefixMapping(String prefix)

Implements org.xml.sax.ContentHandler.endPrefixMapping.

End the scope of a prefix-URI mapping.

public int
public Attributes

Returns:

Attributes that belong to the current element
getCurrentAttributes
()

Attributes that belong to the current element.

public Locator

Returns:

the source location of the current event
getLocator
()

Gets the source location of the current event.

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

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

Receive notification of ignorable whitespace in element content.

public void
onEnterElementConsumed(String
Parameter passed to the element event.
uri
,
String
Parameter passed to the element event.
localName
,
String
Parameter passed to the element event.
qname
,
Attributes
Parameter passed to the element event.
atts
)

Called by the generated handler code when an enter element event is consumed.

public void
onLeaveElementConsumed(String
Parameter passed to the element event.
uri
,
String
Parameter passed to the element event.
localName
,
String
Parameter passed to the element event.
qname
)

private void
public void
processingInstruction(String target, String data)

Implements org.xml.sax.ContentHandler.processingInstruction.

Receive notification of a processing instruction.

public void
private void
processPendingText(boolean
True if the buffered character can be ignorable. False if it needs to be consumed.
ignorable
)

Processes buffered text.

public void
redirectSubtree(ContentHandler
the new ContentHandler
child
,
String
Parameter passed to the enter element event. Used to simulate the startElement event for the new ContentHandler.
uri
,
String
Parameter passed to the enter element event. Used to simulate the startElement event for the new ContentHandler.
local
,
String
Parameter passed to the enter element event. Used to simulate the startElement event for the new ContentHandler.
qname
)

This method can be called only from the enterElement handler.

public int
replace(NGCCEventReceiver o, NGCCEventReceiver n)

Implements com.sun.tools.jxc.gen.config.NGCCEventSource.replace.

Replaces an old handler with a new handler, and returns ID of the EventReceiver thread.

public void
reset()

Cleans up all the data structure so that the object can be reused later.

public String
public void
public void
sendEnterElement(int threadId, String uri, String local, String qname, Attributes atts)

Implements com.sun.tools.jxc.gen.config.NGCCEventSource.sendEnterElement.

Sends an enter element event to the specified EventReceiver thread.

public void
public void
public void
public void
setDocumentLocator(Locator _loc)

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Receive an object for locating the origin of SAX document events.

public void
setRootHandler(NGCCHandler
new root handler
rootHandler
)

Sets the root handler, which will be used to parse the root element.

public void
skippedEntity(String name)

Implements org.xml.sax.ContentHandler.skippedEntity.

Receive notification of a skipped entity.

public void
startDocument()

Implements org.xml.sax.ContentHandler.startDocument.

Receive notification of the beginning of a document.

public void
startElement(String uri, String localname, String qname, Attributes atts)

Implements org.xml.sax.ContentHandler.startElement.

Receive notification of the beginning of an element.

public void
startPrefixMapping(String prefix, String uri)

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Begin the scope of a prefix-URI Namespace mapping.

public void
public void
protected void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attStackback to summary
private final Stack<AttributesImpl> attStack

stack of Attributes.

currentAttsback to summary
private AttributesImpl currentAtts

current attributes set. always equal to attStack.peek()

currentHandlerback to summary
private NGCCEventReceiver currentHandler

The current NGCCHandler. Always equals to handlerStack.peek()

IMPOSSIBLEback to summary
pack-priv static final String IMPOSSIBLE

Impossible token. This value can never be a valid XML name.

indentback to summary
private int indent
locatorback to summary
private Locator locator
namespacesback to summary
private final List<String> namespaces

in-scope namespace mapping. namespaces[2n ] := prefix namespaces[2n+1] := namespace URI

needIndentback to summary
private boolean needIndent
nsEffectivePtrback to summary
private int nsEffectivePtr

Index 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 from namespaces.size().

For example, consider the following schema:

<oneOrMore>
  <element name="foo"><empty/></element>
 </oneOrMore>
 code fragment X
 <element name="bob"/>
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".
nsEffectiveStackback to summary
private final Stack<Integer> nsEffectiveStack

Stack to preserve old nsEffectivePtr values.

redirectback to summary
private ContentHandler redirect

When redirecting a sub-tree, this value will be non-null.

redirectionDepthback to summary
private int redirectionDepth

Counts the depth of the elements when we are re-directing a sub-tree to another ContentHandler.

textback to summary
private StringBuffer text

accumulated text.

Constructor Detail

NGCCRuntimeback to summary
public NGCCRuntime()

Method Detail

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

Implements org.xml.sax.ContentHandler.characters.

Doc from org.xml.sax.ContentHandler.characters.

Receive notification of character data.

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Individual characters may consist of more than one Java char value. There are two important cases where this happens, because characters can't be represented in just sixteen bits. In one case, characters are represented in a Surrogate Pair, using two special Unicode values. Such characters are in the so-called "Astral Planes", with a code point above U+FFFF. A second case involves composite characters, such as a base character combining with one or more accent characters.

Your code should not assume that algorithms using char-at-a-time idioms will be working in character units; in some cases they will split characters. This is relevant wherever XML permits arbitrary characters, such as attribute values, processing instruction data, and comments as well as in data reported from this method. It's also generally relevant whenever Java code manipulates internationalized text; the issue isn't unique to XML.

Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so).

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
consumeAttributeback to summary
public void consumeAttribute(int index) throws SAXException
endDocumentback to summary
public void endDocument() throws SAXException

Implements org.xml.sax.ContentHandler.endDocument.

Doc from org.xml.sax.ContentHandler.endDocument.

Receive notification of the end of a document.

This method is invoked by the parser to signal it has reached the end of the document after successfully completing the parsing process. After the event, the parser will return the control to the application.

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
endElementback to summary
public void endElement(String uri, String localname, String qname) throws SAXException

Implements org.xml.sax.ContentHandler.endElement.

Doc from org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.

The SAX parser will invoke this method at the end of every element in the XML document; there will be a corresponding startElement event for every endElement event (even when the element is empty).

For information on the names, see startElement.

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
endPrefixMappingback to summary
public void endPrefixMapping(String prefix) throws SAXException

Implements org.xml.sax.ContentHandler.endPrefixMapping.

Doc from org.xml.sax.ContentHandler.endPrefixMapping.

End the scope of a prefix-URI mapping.

See startPrefixMapping for details. These events will always occur immediately after the corresponding endElement event, but the order of endPrefixMapping events is not otherwise guaranteed.

Annotations
@Override
Exceptions
SAXException:
the client may throw an exception during processing
getAttributeIndexback to summary
public int getAttributeIndex(String uri, String localname)
getCurrentAttributesback to summary
public Attributes 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.

Returns:Attributes

Attributes that belong to the current element

getLocatorback to summary
public Locator 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

Returns:Locator

the source location of the current event

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

Implements org.xml.sax.ContentHandler.ignorableWhitespace.

Doc from org.xml.sax.ContentHandler.ignorableWhitespace.

Receive notification of ignorable whitespace in element content.

Validating Parsers must use this method to report each chunk of whitespace in element content (see the W3C XML 1.0 recommendation, section 2.10): non-validating parsers may also use this method if they are capable of parsing and using content models.

SAX parsers may return all contiguous whitespace in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.

The application must not attempt to read from the array outside of the specified range.

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
onEnterElementConsumedback to summary
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 truly consumes the enterElement event.

Parameters
uri:String

Parameter passed to the element event.

localName:String

Parameter passed to the element event.

qname:String

Parameter passed to the element event.

atts:Attributes

Parameter passed to the element event.

Exceptions
SAXException:
for errors
onLeaveElementConsumedback to summary
public void onLeaveElementConsumed(String uri, String localName, String qname) throws SAXException
Parameters
uri:String

Parameter passed to the element event.

localName:String

Parameter passed to the element event.

qname:String

Parameter passed to the element event.

Exceptions
SAXException:
for errors
printIndentback to summary
private void printIndent()
processingInstructionback to summary
public void processingInstruction(String target, String data) throws SAXException

Implements org.xml.sax.ContentHandler.processingInstruction.

Doc from org.xml.sax.ContentHandler.processingInstruction.

Receive notification of a processing instruction.

The Parser will invoke this method once for each processing instruction found: note that processing instructions may occur before or after the main document element.

A SAX parser must never report an XML declaration (XML 1.0, section 2.8) or a text declaration (XML 1.0, section 4.3.1) using this method.

Like characters(), processing instruction data may have characters that need more than one char value.

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
processListback to summary
public void processList(String str) throws SAXException
processPendingTextback to summary
private void processPendingText(boolean ignorable) throws SAXException

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:

<element name="foo">
  <choice>
    <element name="bar"><empty/></element>
    <text/>
  </choice>
</element>
Assume we hit the following instance:
<foo> <bar/></foo>
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:
<foo/>
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
ignorable:boolean

True if the buffered character can be ignorable. False if it needs to be consumed.

redirectSubtreeback to summary
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
child:ContentHandler

the new ContentHandler

uri:String

Parameter passed to the enter element event. Used to simulate the startElement event for the new ContentHandler.

local:String

Parameter passed to the enter element event. Used to simulate the startElement event for the new ContentHandler.

qname:String

Parameter passed to the enter element event. Used to simulate the startElement event for the new ContentHandler.

Exceptions
SAXException:
for errors
replaceback to summary
public int replace(NGCCEventReceiver o, NGCCEventReceiver n)

Implements com.sun.tools.jxc.gen.config.NGCCEventSource.replace.

Doc from com.sun.tools.jxc.gen.config.NGCCEventSource.replace.

Replaces an old handler with a new handler, and returns ID of the EventReceiver thread.

Annotations
@Override
resetback to summary
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.

resolveNamespacePrefixback to summary
public String resolveNamespacePrefix(String prefix)
sendEnterAttributeback to summary
public void sendEnterAttribute(int threadId, String uri, String local, String qname) throws SAXException

Implements com.sun.tools.jxc.gen.config.NGCCEventSource.sendEnterAttribute.

Annotations
@Override
sendEnterElementback to summary
public void sendEnterElement(int threadId, String uri, String local, String qname, Attributes atts) throws SAXException

Implements com.sun.tools.jxc.gen.config.NGCCEventSource.sendEnterElement.

Doc from com.sun.tools.jxc.gen.config.NGCCEventSource.sendEnterElement.

Sends an enter element event to the specified EventReceiver thread.

Annotations
@Override
Exceptions
SAXException:
for errors
sendLeaveAttributeback to summary
public void sendLeaveAttribute(int threadId, String uri, String local, String qname) throws SAXException

Implements com.sun.tools.jxc.gen.config.NGCCEventSource.sendLeaveAttribute.

Annotations
@Override
sendLeaveElementback to summary
public void sendLeaveElement(int threadId, String uri, String local, String qname) throws SAXException

Implements com.sun.tools.jxc.gen.config.NGCCEventSource.sendLeaveElement.

Annotations
@Override
sendTextback to summary
public void sendText(int threadId, String value) throws SAXException

Implements com.sun.tools.jxc.gen.config.NGCCEventSource.sendText.

Annotations
@Override
setDocumentLocatorback to summary
public void setDocumentLocator(Locator _loc)

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Doc from org.xml.sax.ContentHandler.setDocumentLocator.

Receive an object for locating the origin of SAX document events.

SAX parsers are strongly encouraged (though not absolutely required) to supply a locator: if it does so, it must supply the locator to the application by invoking this method before invoking any of the other methods in the ContentHandler interface.

The locator allows the application to determine the end position of any document-related event, even if the parser is not reporting an error. Typically, the application will use this information for reporting its own errors (such as character content that does not match an application's business rules). The information returned by the locator is probably not sufficient for use with a search engine.

Note that the locator will return correct information only during the invocation SAX event callbacks after startDocument returns and before endDocument is called. The application should not attempt to use it at any other time.

Annotations
@Override
setRootHandlerback to summary
public void setRootHandler(NGCCHandler rootHandler)

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.

Parameters
rootHandler:NGCCHandler

new root handler

Exceptions
IllegalStateException:
If this method is called but it doesn't satisfy the pre-condition stated above.
skippedEntityback to summary
public void skippedEntity(String name) throws SAXException

Implements org.xml.sax.ContentHandler.skippedEntity.

Doc from org.xml.sax.ContentHandler.skippedEntity.

Receive notification of a skipped entity. This is not called for entity references within markup constructs such as element start tags or markup declarations. (The XML recommendation requires reporting skipped external entities. SAX also reports internal entity expansion/non-expansion, except within markup constructs.)

The Parser will invoke this method each time the entity is skipped. Non-validating processors may skip entities if they have not seen the declarations (because, for example, the entity was declared in an external DTD subset). All processors may skip external entities, depending on the values of the http://xml.org/sax/features/external-general-entities and the http://xml.org/sax/features/external-parameter-entities properties.

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
startDocumentback to summary
public void startDocument()

Implements org.xml.sax.ContentHandler.startDocument.

Doc from org.xml.sax.ContentHandler.startDocument.

Receive notification of the beginning of a document.

The SAX parser will invoke this method only once, before any other event callbacks (except for setDocumentLocator).

Annotations
@Override
startElementback to summary
public void startElement(String uri, String localname, String qname, Attributes atts) throws SAXException

Implements org.xml.sax.ContentHandler.startElement.

Doc from org.xml.sax.ContentHandler.startElement.

Receive notification of the beginning of an element.

The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

This event allows up to three name components for each element:

  1. the Namespace URI;
  2. the local name; and
  3. the qualified (prefixed) name.

Any or all of these may be provided, depending on the values of the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes properties:

  • the Namespace URI and local name are required when the namespaces property is true (the default), and are optional when the namespaces property is false (if one is specified, both must be);
  • the qualified name is required when the namespace-prefixes property is true, and is optional when the namespace-prefixes property is false (the default).

Note that the attribute list provided will contain only attributes with explicit values (specified or defaulted): #IMPLIED attributes will be omitted. The attribute list will contain attributes used for Namespace declarations (xmlns* attributes) only if the http://xml.org/sax/features/namespace-prefixes property is true (it is false by default, and support for a true value is optional).

Like characters(), attribute values may have characters that need more than one char value.

Annotations
@Override
Exceptions
SAXException:
any SAX exception, possibly wrapping another exception
startPrefixMappingback to summary
public void startPrefixMapping(String prefix, String uri) throws SAXException

Implements org.xml.sax.ContentHandler.startPrefixMapping.

Doc from org.xml.sax.ContentHandler.startPrefixMapping.

Begin the scope of a prefix-URI Namespace mapping.

The information from this event is not necessary for normal Namespace processing: the SAX XML reader will automatically replace prefixes for element and attribute names when the http://xml.org/sax/features/namespaces feature is true (the default).

There are cases, however, when applications need to use prefixes in character data or in attribute values, where they cannot safely be expanded automatically; the start/endPrefixMapping event supplies the information to the application to expand prefixes in those contexts itself, if necessary.

Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each other: all startPrefixMapping events will occur immediately before the corresponding startElement event, and all endPrefixMapping events will occur immediately after the corresponding endElement event, but their order is not otherwise guaranteed.

There should never be start/endPrefixMapping events for the "xml" prefix, since it is predeclared and immutable.

Annotations
@Override
Exceptions
SAXException:
the client may throw an exception during processing
traceback to summary
public void trace(String s)
tracelnback to summary
public void traceln(String s)
unexpectedXback to summary
protected void unexpectedX(String token) throws SAXException