| Method from com.sun.tools.internal.jxc.gen.config.NGCCRuntime Detail: |
public void characters(char[] ch,
int start,
int length) throws SAXException {
if(redirect!=null)
redirect.characters(ch,start,length);
else
text.append(ch,start,length);
}
|
public void consumeAttribute(int index) throws SAXException {
final String uri = currentAtts.getURI(index).intern();
final String local = currentAtts.getLocalName(index).intern();
final String qname = currentAtts.getQName(index).intern();
final String value = currentAtts.getValue(index);
currentAtts.removeAttribute(index);
currentHandler.enterAttribute(uri,local,qname);
currentHandler.text(value);
currentHandler.leaveAttribute(uri,local,qname);
}
|
public void endDocument() throws SAXException {
// consume the special "end document" token so that all the handlers
// currently at the stack will revert to their respective parents.
//
// this is necessary to handle a grammar like
// < start >< ref name="X"/ >< /start >
// < define name="X" >
// < element name="root" >< empty/ >< /element >
// < /define >
//
// With this grammar, when the endElement event is consumed, two handlers
// are on the stack (because a child object won't revert to its parent
// unless it sees a next event.)
// pass around an "impossible" token.
currentHandler.leaveElement(IMPOSSIBLE,IMPOSSIBLE,IMPOSSIBLE);
reset();
}
|
public void endElement(String uri,
String localname,
String qname) throws SAXException {
uri = uri.intern();
localname = localname.intern();
qname = qname.intern();
if(redirect!=null) {
redirect.endElement(uri,localname,qname);
redirectionDepth--;
if(redirectionDepth!=0)
return;
// finished redirection.
for( int i=0; i< namespaces.size(); i+=2 )
redirect.endPrefixMapping((String)namespaces.get(i));
redirect.endDocument();
redirect = null;
// then process this element normally
}
processPendingText(false);
currentHandler.leaveElement(uri, localname, qname);
// System.out.println("endElement:"+localname);
}
|
public void endPrefixMapping(String prefix) throws SAXException {
if(redirect!=null)
redirect.endPrefixMapping(prefix);
else {
namespaces.remove(namespaces.size()-1);
namespaces.remove(namespaces.size()-1);
}
}
|
public int getAttributeIndex(String uri,
String localname) {
return currentAtts.getIndex(uri, localname);
}
|
public Attributes getCurrentAttributes() {
return currentAtts;
}
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. |
public Locator getLocator() {
return locator;
}
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 |
public void ignorableWhitespace(char[] ch,
int start,
int length) throws SAXException {
if(redirect!=null)
redirect.ignorableWhitespace(ch,start,length);
else
text.append(ch,start,length);
}
|
public void onEnterElementConsumed(String uri,
String localName,
String qname,
Attributes atts) throws SAXException {
attStack.push(currentAtts=new AttributesImpl(atts));
nsEffectiveStack.push( new Integer(nsEffectivePtr) );
nsEffectivePtr = namespaces.size();
}
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. |
public void onLeaveElementConsumed(String uri,
String localName,
String qname) throws SAXException {
attStack.pop();
if(attStack.isEmpty())
currentAtts = null;
else
currentAtts = (AttributesImpl)attStack.peek();
nsEffectivePtr = ((Integer)nsEffectiveStack.pop()).intValue();
}
|
public void processList(String str) throws SAXException {
StringTokenizer t = new StringTokenizer(str, " \t\r\n");
while(t.hasMoreTokens())
currentHandler.text(t.nextToken());
}
|
public void processingInstruction(String target,
String data) throws SAXException {
if(redirect!=null)
redirect.processingInstruction(target,data);
}
|
public void redirectSubtree(ContentHandler child,
String uri,
String local,
String qname) throws SAXException {
redirect = child;
redirect.setDocumentLocator(locator);
redirect.startDocument();
// TODO: when a prefix is re-bound to something else,
// the following code is potentially dangerous. It should be
// modified to report active bindings only.
for( int i=0; i< namespaces.size(); i+=2 )
redirect.startPrefixMapping(
(String)namespaces.get(i),
(String)namespaces.get(i+1)
);
redirect.startElement(uri,local,qname,currentAtts);
redirectionDepth=1;
}
|
public int replace(NGCCEventReceiver o,
NGCCEventReceiver n) {
if(o!=currentHandler)
throw new IllegalStateException(); // bug of RelaxNGCC
currentHandler = n;
return 0; // we only have one thread.
}
|
public void reset() {
attStack.clear();
currentAtts = null;
currentHandler = null;
indent=0;
locator = null;
namespaces.clear();
needIndent = true;
redirect = null;
redirectionDepth = 0;
text = new StringBuffer();
// add a dummy attributes at the bottom as a "centinel."
attStack.push(new AttributesImpl());
}
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. |
public String resolveNamespacePrefix(String prefix) {
for( int i = nsEffectivePtr-2; i >=0; i-=2 )
if( namespaces.get(i).equals(prefix) )
return (String)namespaces.get(i+1);
// no binding was found.
if(prefix.equals("")) return ""; // return the default no-namespace
if(prefix.equals("xml")) // pre-defined xml prefix
return "http://www.w3.org/XML/1998/namespace";
else return null; // prefix undefined
}
|
public void sendEnterAttribute(int threadId,
String uri,
String local,
String qname) throws SAXException {
currentHandler.enterAttribute(uri,local,qname);
}
|
public void sendEnterElement(int threadId,
String uri,
String local,
String qname,
Attributes atts) throws SAXException {
currentHandler.enterElement(uri,local,qname,atts);
}
|
public void sendLeaveAttribute(int threadId,
String uri,
String local,
String qname) throws SAXException {
currentHandler.leaveAttribute(uri,local,qname);
}
|
public void sendLeaveElement(int threadId,
String uri,
String local,
String qname) throws SAXException {
currentHandler.leaveElement(uri,local,qname);
}
|
public void sendText(int threadId,
String value) throws SAXException {
currentHandler.text(value);
}
|
public void setDocumentLocator(Locator _loc) {
this.locator=_loc;
}
|
public void setRootHandler(NGCCHandler rootHandler) {
if(currentHandler!=null)
throw new IllegalStateException();
currentHandler = 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. |
public void skippedEntity(String name) throws SAXException {
if(redirect!=null)
redirect.skippedEntity(name);
}
|
public void startDocument() throws SAXException {
}
|
public void startElement(String uri,
String localname,
String qname,
Attributes atts) throws SAXException {
uri = uri.intern();
localname = localname.intern();
qname = qname.intern();
if(redirect!=null) {
redirect.startElement(uri,localname,qname,atts);
redirectionDepth++;
} else {
processPendingText(true);
// System.out.println("startElement:"+localname+"- >"+_attrStack.size());
currentHandler.enterElement(uri, localname, qname, atts);
}
}
|
public void startPrefixMapping(String prefix,
String uri) throws SAXException {
if(redirect!=null)
redirect.startPrefixMapping(prefix,uri);
else {
namespaces.add(prefix);
namespaces.add(uri);
}
}
|
public void trace(String s) {
if(needIndent) {
needIndent=false;
printIndent();
}
System.out.print(s);
}
|
public void traceln(String s) {
trace(s);
trace("\n");
needIndent=true;
}
|
protected void unexpectedX(String token) throws SAXException {
throw new SAXParseException(MessageFormat.format(
"Unexpected {0} appears at line {1} column {2}",
new Object[]{
token,
new Integer(getLocator().getLineNumber()),
new Integer(getLocator().getColumnNumber()) }),
getLocator());
}
|