edu.ksi.virtualclassroom.mappers.jaxb.xmlwrapper.impl.runtime
Class SAXUnmarshallerHandlerImpl

java.lang.Object
  extended byedu.ksi.virtualclassroom.mappers.jaxb.xmlwrapper.impl.runtime.SAXUnmarshallerHandlerImpl
All Implemented Interfaces:
org.xml.sax.ContentHandler, javax.xml.namespace.NamespaceContext, SAXUnmarshallerHandler, javax.xml.bind.UnmarshallerHandler, UnmarshallingContext

public class SAXUnmarshallerHandlerImpl
extends java.lang.Object
implements SAXUnmarshallerHandler, UnmarshallingContext

Implementation of UnmarshallerHandler. * * This object converts SAX events into unmarshaller events and * cooridnates the entire unmarshalling process. * * @author * Kohsuke KAWAGUCHI * @version $Revision$


Field Summary
private  boolean aborted
          Field aborted
private  com.sun.xml.bind.util.AttributesImpl[] attStack
          Attributes stack.
private  java.lang.StringBuffer buffer
          Field buffer
private  boolean[] collectText
          Stack of collectText flag.
private  int elementDepth
          Element nesting level.
private  GrammarInfo grammarInfo
          Field grammarInfo
private  int handlerLen
          Field handlerLen
private  UnmarshallingEventHandler[] handlers
          Field handlers
private  java.util.Hashtable idmap
          Records ID->Object map.
private  int[] idxStack
          Field idxStack
private  boolean isUnmarshalInProgress
          This flag is set to true at the startDocument event and false at the endDocument event.
private  org.xml.sax.Locator locator
          Field locator
private  int[] mementos
          Field mementos
private  java.lang.String[] nsBind
          Field nsBind
private  int nsLen
          Field nsLen
private  UnmarshallerImpl parent
          Field parent
private  java.lang.Runnable[] patchers
          Submitted patchers in the order they've submitted.
private  int patchersLen
          Field patchersLen
private  java.lang.Object result
          Root object that is being unmarshalled.
private  int stackTop
          Always elementDepth-1.
private  com.sun.xml.bind.unmarshaller.Tracer tracer
          Field tracer
 
Constructor Summary
SAXUnmarshallerHandlerImpl(UnmarshallerImpl _parent, GrammarInfo _gi)
          Constructor for SAXUnmarshallerHandlerImpl
 
Method Summary
 void addPatcher(java.lang.Runnable job)
          Method addPatcher
 java.lang.String addToIdTable(java.lang.String id)
          Method addToIdTable
 void characters(char[] buf, int start, int len)
          Method characters
private  java.lang.String computeExpectedRootElements()
          Computes the names of possible root elements for a better error diagnosis.
 void consumeAttribute(int idx)
          Method consumeAttribute
protected  void consumeText(java.lang.String str, boolean ignorable)
          Method consumeText
 java.lang.String eatAttribute(int idx)
          Method eatAttribute
 void endDocument()
          Method endDocument
 void endElement(java.lang.String uri, java.lang.String local, java.lang.String qname)
          Method endElement
 void endPrefixMapping(java.lang.String prefix)
          Method endPrefixMapping
 java.lang.String[] getAllDeclaredPrefixes()
          Method getAllDeclaredPrefixes
private  java.util.List getAllPrefixesInList(java.lang.String uri)
          Method getAllPrefixesInList
 int getAttribute(java.lang.String uri, java.lang.String local)
          Gets the index of the attribute with the specified name.
 java.lang.String getBaseUri()
          Method getBaseUri
 UnmarshallingEventHandler getCurrentHandler()
          Method getCurrentHandler
 GrammarInfo getGrammarInfo()
          Method getGrammarInfo
 org.xml.sax.Locator getLocator()
          Method getLocator
 java.lang.String getNamespaceURI(java.lang.String prefix)
          Method getNamespaceURI
 java.lang.String[] getNewlyDeclaredPrefixes()
          Method getNewlyDeclaredPrefixes
 java.lang.Object getObjectFromId(java.lang.String id)
          Method getObjectFromId
 java.lang.String getPrefix(java.lang.String uri)
          Method getPrefix
 java.util.Iterator getPrefixes(java.lang.String uri)
          Method getPrefixes
private  java.lang.String[] getPrefixList(int startIndex)
          Method getPrefixList
 java.lang.Object getResult()
          Method getResult
 com.sun.xml.bind.unmarshaller.Tracer getTracer()
          Method getTracer
 org.xml.sax.Attributes getUnconsumedAttributes()
          Method getUnconsumedAttributes
 void handleEvent(javax.xml.bind.ValidationEvent event, boolean canRecover)
          Method handleEvent
 void ignorableWhitespace(char[] buf, int start, int len)
          Method ignorableWhitespace
 boolean isNotation(java.lang.String s)
          Method isNotation
 boolean isUnparsedEntity(java.lang.String s)
          Method isUnparsedEntity
 void popAttributes()
          Method popAttributes
 void popContentHandler()
          Method popContentHandler
 void processingInstruction(java.lang.String target, java.lang.String data)
          Method processingInstruction
private  void processText(boolean ignorable)
          Method processText
 void pushAttributes(org.xml.sax.Attributes atts, boolean collectTextFlag)
          Method pushAttributes
 void pushContentHandler(UnmarshallingEventHandler handler, int memento)
          Method pushContentHandler
 java.lang.String resolveNamespacePrefix(java.lang.String prefix)
          Method resolveNamespacePrefix
private  void runPatchers()
          Executes all the patchers.
 void setDocumentLocator(org.xml.sax.Locator loc)
          Method setDocumentLocator
 void setTracer(com.sun.xml.bind.unmarshaller.Tracer t)
          Method setTracer
private  boolean shouldCollectText()
          Returns true if we should be collecting characters in the current element.
 void skippedEntity(java.lang.String name)
          Method skippedEntity
 void startDocument()
          Method startDocument
 void startElement(java.lang.String uri, java.lang.String local, java.lang.String qname, org.xml.sax.Attributes atts)
          Method startElement
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Method startPrefixMapping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isUnmarshalInProgress

private boolean isUnmarshalInProgress
This flag is set to true at the startDocument event and false at the endDocument event. Until the first document is unmarshalled, we don't want to return an object. So this variable is initialized to true.


grammarInfo

private final GrammarInfo grammarInfo
Field grammarInfo


result

private java.lang.Object result
Root object that is being unmarshalled.


handlers

private UnmarshallingEventHandler[] handlers
Field handlers


mementos

private int[] mementos
Field mementos


handlerLen

private int handlerLen
Field handlerLen


buffer

private java.lang.StringBuffer buffer
Field buffer


nsBind

private java.lang.String[] nsBind
Field nsBind


nsLen

private int nsLen
Field nsLen


idxStack

private int[] idxStack
Field idxStack


attStack

private com.sun.xml.bind.util.AttributesImpl[] attStack
Attributes stack.


elementDepth

private int elementDepth
Element nesting level.


stackTop

private int stackTop
Always elementDepth-1.


collectText

private boolean[] collectText
Stack of collectText flag. False means text can be ignored for this element. Use elementDepth and stackTop to access the array.


patchers

private java.lang.Runnable[] patchers
Submitted patchers in the order they've submitted. Many XML vocabulary doesn't use ID/IDREF at all, so we initialize it with null.


patchersLen

private int patchersLen
Field patchersLen


idmap

private java.util.Hashtable idmap
Records ID->Object map.


locator

private org.xml.sax.Locator locator
Field locator


parent

private final UnmarshallerImpl parent
Field parent


aborted

private boolean aborted
Field aborted


tracer

private com.sun.xml.bind.unmarshaller.Tracer tracer
Field tracer

Constructor Detail

SAXUnmarshallerHandlerImpl

public SAXUnmarshallerHandlerImpl(UnmarshallerImpl _parent,
                                  GrammarInfo _gi)
Constructor for SAXUnmarshallerHandlerImpl

Parameters:
_parent - UnmarshallerImpl
_gi - GrammarInfo
Method Detail

getGrammarInfo

public GrammarInfo getGrammarInfo()
Method getGrammarInfo

Specified by:
getGrammarInfo in interface UnmarshallingContext
Returns:
GrammarInfo
See Also:
UnmarshallingContext.getGrammarInfo()

shouldCollectText

private final boolean shouldCollectText()
Returns true if we should be collecting characters in the current element.

Returns:
boolean

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Method startDocument

Specified by:
startDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.startDocument()

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Method endDocument

Specified by:
endDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.endDocument()

startElement

public void startElement(java.lang.String uri,
                         java.lang.String local,
                         java.lang.String qname,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Method startElement

Specified by:
startElement in interface org.xml.sax.ContentHandler
Parameters:
uri - String
local - String
qname - String
atts - Attributes
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.startElement(String, String, String, Attributes)

endElement

public final void endElement(java.lang.String uri,
                             java.lang.String local,
                             java.lang.String qname)
                      throws org.xml.sax.SAXException
Method endElement

Specified by:
endElement in interface org.xml.sax.ContentHandler
Parameters:
uri - String
local - String
qname - String
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.endElement(String, String, String)

getResult

public java.lang.Object getResult()
                           throws javax.xml.bind.UnmarshalException
Method getResult

Specified by:
getResult in interface javax.xml.bind.UnmarshallerHandler
Returns:
Object
Throws:
javax.xml.bind.UnmarshalException
See Also:
UnmarshallerHandler.getResult()

pushContentHandler

public void pushContentHandler(UnmarshallingEventHandler handler,
                               int memento)
Method pushContentHandler

Specified by:
pushContentHandler in interface UnmarshallingContext
Parameters:
handler - UnmarshallingEventHandler
memento - int
See Also:
UnmarshallingContext.pushContentHandler(UnmarshallingEventHandler, int)

popContentHandler

public void popContentHandler()
                       throws org.xml.sax.SAXException
Method popContentHandler

Specified by:
popContentHandler in interface UnmarshallingContext
Throws:
org.xml.sax.SAXException
See Also:
UnmarshallingContext.popContentHandler()

getCurrentHandler

public UnmarshallingEventHandler getCurrentHandler()
Method getCurrentHandler

Specified by:
getCurrentHandler in interface UnmarshallingContext
Returns:
UnmarshallingEventHandler
See Also:
UnmarshallingContext.getCurrentHandler()

consumeText

protected void consumeText(java.lang.String str,
                           boolean ignorable)
                    throws org.xml.sax.SAXException
Method consumeText

Parameters:
str - String
ignorable - boolean
Throws:
org.xml.sax.SAXException

processText

private void processText(boolean ignorable)
                  throws org.xml.sax.SAXException
Method processText

Parameters:
ignorable - boolean
Throws:
org.xml.sax.SAXException

characters

public final void characters(char[] buf,
                             int start,
                             int len)
Method characters

Specified by:
characters in interface org.xml.sax.ContentHandler
Parameters:
buf - char[]
start - int
len - int
See Also:
ContentHandler.characters(char[], int, int)

ignorableWhitespace

public final void ignorableWhitespace(char[] buf,
                                      int start,
                                      int len)
Method ignorableWhitespace

Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Parameters:
buf - char[]
start - int
len - int
See Also:
ContentHandler.ignorableWhitespace(char[], int, int)

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
Method startPrefixMapping

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Parameters:
prefix - String
uri - String
See Also:
ContentHandler.startPrefixMapping(String, String)

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
Method endPrefixMapping

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Parameters:
prefix - String
See Also:
ContentHandler.endPrefixMapping(String)

resolveNamespacePrefix

public java.lang.String resolveNamespacePrefix(java.lang.String prefix)
Method resolveNamespacePrefix

Specified by:
resolveNamespacePrefix in interface UnmarshallingContext
Parameters:
prefix - String
Returns:
String
See Also:
UnmarshallingContext.resolveNamespacePrefix(String)

getNewlyDeclaredPrefixes

public java.lang.String[] getNewlyDeclaredPrefixes()
Method getNewlyDeclaredPrefixes

Specified by:
getNewlyDeclaredPrefixes in interface UnmarshallingContext
Returns:
String[]
See Also:
UnmarshallingContext.getNewlyDeclaredPrefixes()

getAllDeclaredPrefixes

public java.lang.String[] getAllDeclaredPrefixes()
Method getAllDeclaredPrefixes

Specified by:
getAllDeclaredPrefixes in interface UnmarshallingContext
Returns:
String[]
See Also:
UnmarshallingContext.getAllDeclaredPrefixes()

getPrefixList

private java.lang.String[] getPrefixList(int startIndex)
Method getPrefixList

Parameters:
startIndex - int
Returns:
String[]

getPrefixes

public java.util.Iterator getPrefixes(java.lang.String uri)
Method getPrefixes

Specified by:
getPrefixes in interface javax.xml.namespace.NamespaceContext
Parameters:
uri - String
Returns:
Iterator
See Also:
NamespaceContext.getPrefixes(String)

getAllPrefixesInList

private java.util.List getAllPrefixesInList(java.lang.String uri)
Method getAllPrefixesInList

Parameters:
uri - String
Returns:
List

getPrefix

public java.lang.String getPrefix(java.lang.String uri)
Method getPrefix

Specified by:
getPrefix in interface javax.xml.namespace.NamespaceContext
Parameters:
uri - String
Returns:
String
See Also:
NamespaceContext.getPrefix(String)

getNamespaceURI

public java.lang.String getNamespaceURI(java.lang.String prefix)
Method getNamespaceURI

Specified by:
getNamespaceURI in interface javax.xml.namespace.NamespaceContext
Parameters:
prefix - String
Returns:
String
See Also:
NamespaceContext.getNamespaceURI(String)

pushAttributes

public void pushAttributes(org.xml.sax.Attributes atts,
                           boolean collectTextFlag)
Method pushAttributes

Specified by:
pushAttributes in interface UnmarshallingContext
Parameters:
atts - Attributes
collectTextFlag - boolean
See Also:
UnmarshallingContext.pushAttributes(Attributes, boolean)

popAttributes

public void popAttributes()
Method popAttributes

Specified by:
popAttributes in interface UnmarshallingContext
See Also:
UnmarshallingContext.popAttributes()

getUnconsumedAttributes

public org.xml.sax.Attributes getUnconsumedAttributes()
Method getUnconsumedAttributes

Specified by:
getUnconsumedAttributes in interface UnmarshallingContext
Returns:
Attributes
See Also:
UnmarshallingContext.getUnconsumedAttributes()

getAttribute

public int getAttribute(java.lang.String uri,
                        java.lang.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 - * has to be interned.
local - String
Returns:
int
See Also:
UnmarshallingContext.getAttribute(String, String)

consumeAttribute

public void consumeAttribute(int idx)
                      throws org.xml.sax.SAXException
Method consumeAttribute

Specified by:
consumeAttribute in interface UnmarshallingContext
Parameters:
idx - int
Throws:
org.xml.sax.SAXException
See Also:
UnmarshallingContext.consumeAttribute(int)

eatAttribute

public java.lang.String eatAttribute(int idx)
                              throws org.xml.sax.SAXException
Method eatAttribute

Specified by:
eatAttribute in interface UnmarshallingContext
Parameters:
idx - int
Returns:
String
Throws:
org.xml.sax.SAXException
See Also:
UnmarshallingContext.eatAttribute(int)

addPatcher

public void addPatcher(java.lang.Runnable job)
Method addPatcher

Specified by:
addPatcher in interface UnmarshallingContext
Parameters:
job - Runnable
See Also:
UnmarshallingContext.addPatcher(Runnable)

runPatchers

private void runPatchers()
Executes all the patchers.


addToIdTable

public java.lang.String addToIdTable(java.lang.String id)
Method addToIdTable

Specified by:
addToIdTable in interface UnmarshallingContext
Parameters:
id - String
Returns:
String
See Also:
UnmarshallingContext.addToIdTable(String)

getObjectFromId

public java.lang.Object getObjectFromId(java.lang.String id)
Method getObjectFromId

Specified by:
getObjectFromId in interface UnmarshallingContext
Parameters:
id - String
Returns:
Object
See Also:
UnmarshallingContext.getObjectFromId(String)

skippedEntity

public void skippedEntity(java.lang.String name)
Method skippedEntity

Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Parameters:
name - String
See Also:
ContentHandler.skippedEntity(String)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
Method processingInstruction

Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Parameters:
target - String
data - String
See Also:
ContentHandler.processingInstruction(String, String)

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator loc)
Method setDocumentLocator

Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler
Parameters:
loc - Locator
See Also:
ContentHandler.setDocumentLocator(Locator)

getLocator

public org.xml.sax.Locator getLocator()
Method getLocator

Specified by:
getLocator in interface UnmarshallingContext
Returns:
Locator
See Also:
UnmarshallingContext.getLocator()

handleEvent

public void handleEvent(javax.xml.bind.ValidationEvent event,
                        boolean canRecover)
                 throws org.xml.sax.SAXException
Method handleEvent

Specified by:
handleEvent in interface SAXUnmarshallerHandler
Parameters:
event - ValidationEvent
canRecover - boolean
Throws:
org.xml.sax.SAXException
See Also:
SAXUnmarshallerHandler.handleEvent(ValidationEvent, boolean)

getBaseUri

public java.lang.String getBaseUri()
Method getBaseUri

Specified by:
getBaseUri in interface UnmarshallingContext
Returns:
String
See Also:
UnmarshallingContext.getBaseUri()

isUnparsedEntity

public boolean isUnparsedEntity(java.lang.String s)
Method isUnparsedEntity

Specified by:
isUnparsedEntity in interface UnmarshallingContext
Parameters:
s - String
Returns:
boolean
See Also:
UnmarshallingContext.isUnparsedEntity(String)

isNotation

public boolean isNotation(java.lang.String s)
Method isNotation

Specified by:
isNotation in interface UnmarshallingContext
Parameters:
s - String
Returns:
boolean
See Also:
UnmarshallingContext.isNotation(String)

setTracer

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

Parameters:
t - Tracer

getTracer

public com.sun.xml.bind.unmarshaller.Tracer getTracer()
Method getTracer

Specified by:
getTracer in interface UnmarshallingContext
Returns:
Tracer
See Also:
UnmarshallingContext.getTracer()

computeExpectedRootElements

private java.lang.String computeExpectedRootElements()
Computes the names of possible root elements for a better error diagnosis.

Returns:
String