astronomy.data.spectra.impl.runtime
Class SAXUnmarshallerHandlerImpl

java.lang.Object
  extended by astronomy.data.spectra.impl.runtime.SAXUnmarshallerHandlerImpl
All Implemented Interfaces:
SAXUnmarshallerHandler, UnmarshallingContext, javax.xml.bind.UnmarshallerHandler, NamespaceContext, org.relaxng.datatype.ValidationContext, ContentHandler

public class SAXUnmarshallerHandlerImpl
extends Object
implements SAXUnmarshallerHandler, UnmarshallingContext

Implementation of UnmarshallerHandler. This object converts SAX events into unmarshaller events and cooridnates the entire unmarshalling process.

Author:
Constructor Summary
SAXUnmarshallerHandlerImpl(UnmarshallerImpl _parent, GrammarInfo _gi)
           
 
Method Summary
 void addPatcher(Runnable job)
          Adds a job that will be executed at the last of the unmarshalling.
 String addToIdTable(String id)
          Adds the object which is currently being unmarshalled to the ID table.
 void characters(char[] buf, int start, int len)
           
 void consumeAttribute(int idx)
          Fires an attribute event for the specified attribute, and marks the attribute as "used".
protected  void consumeText(String str, boolean ignorable)
           
 String eatAttribute(int idx)
          Marks the attribute as "used" and return the value of the attribute.
 void endDocument()
           
 void endElement(String uri, String local, String qname)
           
 void endPrefixMapping(String prefix)
          Removes a namespace declaration.
 int getAttribute(String uri, String local)
          Gets the index of the attribute with the specified name.
 String getBaseUri()
           
 UnmarshallingEventHandler getCurrentHandler()
          Gets the current handler.
 GrammarInfo getGrammarInfo()
          Obtains a reference to the current grammar info.
 Locator getLocator()
          Gets the current source location information.
 String getNamespaceURI(String prefix)
           
 Object getObjectFromId(String id)
          Looks up the ID table and gets associated object.
 String getPrefix(String uri)
           
 Iterator getPrefixes(String uri)
           
 Object getResult()
           
 com.sun.xml.bind.unmarshaller.Tracer getTracer()
          Gets a tracer object.
 Attributes getUnconsumedAttributes()
          Gets all the unconsumed attributes.
 void handleEvent(javax.xml.bind.ValidationEvent event, boolean canRecover)
          Reports an error to the user, and asks if s/he wants to recover.
 void ignorableWhitespace(char[] buf, int start, int len)
           
 boolean isNotation(String s)
           
 boolean isUnparsedEntity(String s)
           
 void popAttributes()
          Discards the previously stored attribute set.
 void popContentHandler()
          Pops a content handler from the stack and registers it as the current content handler.
 void processingInstruction(String target, String data)
           
 void pushAttributes(Attributes atts, boolean collectTextFlag)
          Stores a new attribute set.
 void pushContentHandler(UnmarshallingEventHandler handler, int memento)
          Pushes the current content handler into the stack and registers the newly specified content handler so that it can receive SAX events.
 String resolveNamespacePrefix(String prefix)
           
 void setDocumentLocator(Locator loc)
           
 void setTracer(com.sun.xml.bind.unmarshaller.Tracer t)
           
 void skippedEntity(String name)
           
 void startDocument()
           
 void startElement(String uri, String local, String qname, Attributes atts)
           
 void startPrefixMapping(String prefix, String uri)
          Adds a new namespace declaration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SAXUnmarshallerHandlerImpl

public SAXUnmarshallerHandlerImpl(UnmarshallerImpl _parent,
                                  GrammarInfo _gi)
Method Detail

getGrammarInfo

public GrammarInfo getGrammarInfo()
Description copied from interface: UnmarshallingContext
Obtains a reference to the current grammar info.

Specified by:
getGrammarInfo in interface UnmarshallingContext

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Throws:
SAXException

startElement

public void startElement(String uri,
                         String local,
                         String qname,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Throws:
SAXException

endElement

public final void endElement(String uri,
                             String local,
                             String qname)
                      throws SAXException
Specified by:
endElement in interface ContentHandler
Throws:
SAXException

getResult

public Object getResult()
                 throws javax.xml.bind.UnmarshalException
Specified by:
getResult in interface javax.xml.bind.UnmarshallerHandler
Throws:
javax.xml.bind.UnmarshalException

pushContentHandler

public void pushContentHandler(UnmarshallingEventHandler handler,
                               int memento)
Description copied from interface: UnmarshallingContext
Pushes the current content handler into the stack and registers the newly specified content handler so that it can receive SAX events.

Specified by:
pushContentHandler in interface UnmarshallingContext
memento - When this newly specified handler will be removed from the stack, the leaveChild event will be fired to the parent handler with this memento.

popContentHandler

public void popContentHandler()
                       throws SAXException
Description copied from interface: UnmarshallingContext
Pops a content handler from the stack and registers it as the current content handler.

This method will also fire the leaveChild event with the associated memento.

Specified by:
popContentHandler in interface UnmarshallingContext
Throws:
SAXException

getCurrentHandler

public UnmarshallingEventHandler getCurrentHandler()
Description copied from interface: UnmarshallingContext
Gets the current handler.

Specified by:
getCurrentHandler in interface UnmarshallingContext

consumeText

protected void consumeText(String str,
                           boolean ignorable)
                    throws SAXException
Throws:
SAXException

characters

public final void characters(char[] buf,
                             int start,
                             int len)
Specified by:
characters in interface ContentHandler

ignorableWhitespace

public final void ignorableWhitespace(char[] buf,
                                      int start,
                                      int len)
Specified by:
ignorableWhitespace in interface ContentHandler

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
Description copied from interface: UnmarshallingContext
Adds a new namespace declaration. This method should be called by the generated code.

Specified by:
startPrefixMapping in interface UnmarshallingContext
Specified by:
startPrefixMapping in interface ContentHandler

endPrefixMapping

public void endPrefixMapping(String prefix)
Description copied from interface: UnmarshallingContext
Removes a namespace declaration. This method should be called by the generated code.

Specified by:
endPrefixMapping in interface UnmarshallingContext
Specified by:
endPrefixMapping in interface ContentHandler

resolveNamespacePrefix

public String resolveNamespacePrefix(String prefix)
Specified by:
resolveNamespacePrefix in interface org.relaxng.datatype.ValidationContext

getPrefixes

public Iterator getPrefixes(String uri)
Specified by:
getPrefixes in interface NamespaceContext

getPrefix

public String getPrefix(String uri)
Specified by:
getPrefix in interface NamespaceContext

getNamespaceURI

public String getNamespaceURI(String prefix)
Specified by:
getNamespaceURI in interface NamespaceContext

pushAttributes

public void pushAttributes(Attributes atts,
                           boolean collectTextFlag)
Description copied from interface: UnmarshallingContext
Stores a new attribute set. This method should be called by the generated code when it "eats" an enterElement event.

Specified by:
pushAttributes in interface UnmarshallingContext
collectTextFlag - false if the context doesn't need to fire text events for texts inside this element. True otherwise.

popAttributes

public void popAttributes()
Description copied from interface: UnmarshallingContext
Discards the previously stored attribute set. This method should be called by the generated code when it "eats" a leaveElement event.

Specified by:
popAttributes in interface UnmarshallingContext

getUnconsumedAttributes

public Attributes getUnconsumedAttributes()
Description copied from interface: UnmarshallingContext
Gets all the unconsumed attributes. If you need to find attributes based on more complex filter, you need to use this method.

Specified by:
getUnconsumedAttributes in interface UnmarshallingContext

getAttribute

public int getAttribute(String uri,
                        String local)
Description copied from interface: UnmarshallingContext
Gets the index of the attribute with the specified name. This is usually faster when you only need to test with a simple name.

Specified by:
getAttribute in interface UnmarshallingContext
Parameters:
uri,local - has to be interned.
Returns:
-1 if not found.

consumeAttribute

public void consumeAttribute(int idx)
                      throws SAXException
Description copied from interface: UnmarshallingContext
Fires an attribute event for the specified attribute, and marks the attribute as "used".

Specified by:
consumeAttribute in interface UnmarshallingContext
Throws:
SAXException

eatAttribute

public String eatAttribute(int idx)
                    throws SAXException
Description copied from interface: UnmarshallingContext
Marks the attribute as "used" and return the value of the attribute.

Specified by:
eatAttribute in interface UnmarshallingContext
Throws:
SAXException

addPatcher

public void addPatcher(Runnable job)
Description copied from interface: UnmarshallingContext
Adds a job that will be executed at the last of the unmarshalling. This method is used to support ID/IDREF feature, but it can be used for other purposes as well.

Specified by:
addPatcher in interface UnmarshallingContext
Parameters:
job - The run method of this object is called.

addToIdTable

public String addToIdTable(String id)
Description copied from interface: UnmarshallingContext
Adds the object which is currently being unmarshalled to the ID table.

Specified by:
addToIdTable in interface UnmarshallingContext
Returns:
Returns the value passed as the parameter. This is a hack, but this makes it easier for ID transducer to do its job.

getObjectFromId

public Object getObjectFromId(String id)
Description copied from interface: UnmarshallingContext
Looks up the ID table and gets associated object.

Specified by:
getObjectFromId in interface UnmarshallingContext
Returns:
If there is no object associated with the given id, this method returns null.

skippedEntity

public void skippedEntity(String name)
Specified by:
skippedEntity in interface ContentHandler

processingInstruction

public void processingInstruction(String target,
                                  String data)
Specified by:
processingInstruction in interface ContentHandler

setDocumentLocator

public void setDocumentLocator(Locator loc)
Specified by:
setDocumentLocator in interface ContentHandler

getLocator

public Locator getLocator()
Description copied from interface: UnmarshallingContext
Gets the current source location information.

Specified by:
getLocator in interface UnmarshallingContext

handleEvent

public void handleEvent(javax.xml.bind.ValidationEvent event,
                        boolean canRecover)
                 throws SAXException
Description copied from interface: SAXUnmarshallerHandler
Reports an error to the user, and asks if s/he wants to recover. If the canRecover flag is false, regardless of the client instruction, an exception will be thrown. Only if the flag is true and the user wants to recover from an error, the method returns normally. The thrown exception will be catched by the unmarshaller.

Specified by:
handleEvent in interface SAXUnmarshallerHandler
Specified by:
handleEvent in interface UnmarshallingContext
Throws:
SAXException

getBaseUri

public String getBaseUri()
Specified by:
getBaseUri in interface org.relaxng.datatype.ValidationContext

isUnparsedEntity

public boolean isUnparsedEntity(String s)
Specified by:
isUnparsedEntity in interface org.relaxng.datatype.ValidationContext

isNotation

public boolean isNotation(String s)
Specified by:
isNotation in interface org.relaxng.datatype.ValidationContext

setTracer

public void setTracer(com.sun.xml.bind.unmarshaller.Tracer t)

getTracer

public com.sun.xml.bind.unmarshaller.Tracer getTracer()
Description copied from interface: UnmarshallingContext
Gets a tracer object. Tracer can be used to trace the unmarshalling behavior. Note that to debug the unmarshalling process, you have to configure XJC so that it will emit trace codes in the unmarshaller.

Specified by:
getTracer in interface UnmarshallingContext