com.openharbor.beck.unmarshal
Class DefaultUnmarshaller

java.lang.Object
  extended bycom.openharbor.beck.unmarshal.DefaultUnmarshaller
All Implemented Interfaces:
MapFromXML.Aware, Unmarshaller
Direct Known Subclasses:
ChooseUnmarshaller, DanglingUnmarshaller, DateUnmarshaller, EnumerationUnmarshaller, GroupUnmarshaller, JavaBeanUnmarshaller, NonUnmarshaller, PrimitiveUnmarshaller, StringUnmarshaller, XPathUnmarshaller

public abstract class DefaultUnmarshaller
extends java.lang.Object
implements Unmarshaller, MapFromXML.Aware

Shared code, inherited by most kinds of Unmarshaller. Recycles itself (to improve performance) when disengaged.


Field Summary
protected  java.lang.StringBuffer data
           
protected  java.util.Map documentState
           
protected  org.apache.commons.logging.Log log
           
 
Constructor Summary
DefaultUnmarshaller()
           
 
Method Summary
 void addChild(Unmarshaller child)
          Create a reference from this object to the given child object.
protected  void addToParent()
          Create references to this.getObject() from its parent and other Java objects.
 void addValue(char[] from, int start, int length)
          Add characters from XML content (text) to the value of the mapped object.
protected  void afterEndObject()
           
 void disengage()
          Un-do a previous engagement.
protected  void disengaged()
          The last engagement on this will soon be disengaged.
protected  void endElement()
          The source element's closing tag has just been processed (but disengage() has not yet been called).
 java.lang.Object endObject()
          Conclude the mapping of this object, and return it.
 void engage()
          Prevent re-using this Unmarshaller until a matching call to disengage() is made.
 java.lang.Class getChildClass(XMLThing childSource)
          Choose the class of the object to be mapped from a contained XML attribute or element.
protected  java.util.Map getMap(java.util.Map map, java.lang.Object key)
           
 MapFromXML getMapFromXML()
           
 java.lang.Object getObject()
           
 java.lang.Class getObjectClass()
           
 Unmarshaller getParent()
          The set allocated to the XML element that contains this Unmarshaller's XML source.
 XMLThing getSource()
          The XML element or attribute from which this Unmarshaller is currently mapping data.
 java.lang.String getSourceXPath()
           
 XMLContext getXMLContext()
           
protected  java.lang.String getXName(XMLThing from, Prefixer prefixer)
           
protected  java.lang.String getXPath(Unmarshaller parent, XMLThing source)
           
protected  boolean isEngaged()
          Whether this object is currently engaged.
protected  java.lang.Object newObject()
           
protected  void processAttributes(java.util.Map attributes)
           
protected  void referToThis()
          Create Java references to this.getObject() if this.getSource() is the referent of an XML cross-reference.
protected  void reset()
          Release all resources, and subsequently behave as though newly constructed.
static void rethrow(java.lang.Throwable t)
          Throw an exception that contains the most diagnostic information available from the given Throwable.
 void setMapFromXML(MapFromXML mapper)
           
 void setObject(java.lang.Object object)
           
 void setObjectClass(java.lang.Class objectClass)
          Set the expected class of the object to be mapped from XML.
protected  void setParentAndSource(Unmarshaller parent, XMLThing source)
           
protected  void setValue(java.lang.StringBuffer data)
          Convert the text and store the resulting data into the object.
 void setXMLContext(XMLContext context)
          Set the functor for resolving an XML namespace prefix to the namespace URI.
protected  void startElement(Unmarshaller parent, XMLThing source)
           
 void startObject(java.util.Map documentState, Unmarshaller parent, XMLThing source)
          Begin mapping an object from an XML element or attribute.
protected  java.lang.String toString(XMLThing from)
           
protected  void trim(java.lang.StringBuffer data)
          Trim whitespace from XML data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log

documentState

protected java.util.Map documentState

data

protected java.lang.StringBuffer data
Constructor Detail

DefaultUnmarshaller

public DefaultUnmarshaller()
Method Detail

setMapFromXML

public void setMapFromXML(MapFromXML mapper)
Specified by:
setMapFromXML in interface MapFromXML.Aware

getMapFromXML

public MapFromXML getMapFromXML()
Specified by:
getMapFromXML in interface MapFromXML.Aware

setXMLContext

public void setXMLContext(XMLContext context)
Description copied from interface: Unmarshaller
Set the functor for resolving an XML namespace prefix to the namespace URI.

Specified by:
setXMLContext in interface Unmarshaller

getXMLContext

public XMLContext getXMLContext()
Specified by:
getXMLContext in interface Unmarshaller

getParent

public Unmarshaller getParent()
Description copied from interface: Unmarshaller
The set allocated to the XML element that contains this Unmarshaller's XML source.

Specified by:
getParent in interface Unmarshaller

getSource

public XMLThing getSource()
Description copied from interface: Unmarshaller
The XML element or attribute from which this Unmarshaller is currently mapping data.

Specified by:
getSource in interface Unmarshaller

getSourceXPath

public java.lang.String getSourceXPath()
Specified by:
getSourceXPath in interface Unmarshaller
Returns:
The XPath of getSource().

getObject

public java.lang.Object getObject()
Specified by:
getObject in interface Unmarshaller

setObject

public void setObject(java.lang.Object object)
Specified by:
setObject in interface Unmarshaller

setObjectClass

public void setObjectClass(java.lang.Class objectClass)
Description copied from interface: Unmarshaller
Set the expected class of the object to be mapped from XML. A null Class indicates that the object class is unknown.

Specified by:
setObjectClass in interface Unmarshaller

getObjectClass

public java.lang.Class getObjectClass()
Specified by:
getObjectClass in interface Unmarshaller
Returns:
the expected class of the object to be mapped from XML. A null Class indicates that the object class is unknown.

setParentAndSource

protected void setParentAndSource(Unmarshaller parent,
                                  XMLThing source)

engage

public void engage()
Description copied from interface: Unmarshaller
Prevent re-using this Unmarshaller until a matching call to disengage() is made. This method may be called repeatedly; the Unmarshaller should maintain an engagement counter or similar state to correlate calls to engage and disengage.

Specified by:
engage in interface Unmarshaller

disengage

public void disengage()
               throws java.lang.Exception
Description copied from interface: Unmarshaller
Un-do a previous engagement. For best performance, when the last engagement is disengaged, we recommend making this available for re-use; e.g. by calling getMapFromXML().recycle(this). But this optimization is not required.

Specified by:
disengage in interface Unmarshaller
Throws:
java.lang.Exception

isEngaged

protected boolean isEngaged()
Whether this object is currently engaged.


disengaged

protected void disengaged()
                   throws java.lang.Exception
The last engagement on this will soon be disengaged. That is, isEngaged() returns true now, but will cease to do so soon. The default implementation calls reset() and getMapFromXML.recycle(this).

Throws:
java.lang.Exception

addToParent

protected void addToParent()
                    throws java.lang.Exception
Create references to this.getObject() from its parent and other Java objects.

Throws:
java.lang.Exception

referToThis

protected void referToThis()
                    throws java.lang.Exception
Create Java references to this.getObject() if this.getSource() is the referent of an XML cross-reference.

Throws:
java.lang.Exception

startObject

public void startObject(java.util.Map documentState,
                        Unmarshaller parent,
                        XMLThing source)
                 throws java.lang.Exception
Description copied from interface: Unmarshaller
Begin mapping an object from an XML element or attribute.

Specified by:
startObject in interface Unmarshaller
Throws:
java.lang.Exception

startElement

protected void startElement(Unmarshaller parent,
                            XMLThing source)
                     throws java.lang.Exception
Throws:
java.lang.Exception

endElement

protected void endElement()
                   throws java.lang.Exception
The source element's closing tag has just been processed (but disengage() has not yet been called).

Throws:
java.lang.Exception

processAttributes

protected void processAttributes(java.util.Map attributes)
                          throws java.lang.Exception
Throws:
java.lang.Exception

newObject

protected java.lang.Object newObject()
                              throws java.lang.Exception
Throws:
java.lang.Exception

getXPath

protected java.lang.String getXPath(Unmarshaller parent,
                                    XMLThing source)

getXName

protected java.lang.String getXName(XMLThing from,
                                    Prefixer prefixer)

toString

protected java.lang.String toString(XMLThing from)

getChildClass

public java.lang.Class getChildClass(XMLThing childSource)
                              throws java.lang.Exception
Description copied from interface: Unmarshaller
Choose the class of the object to be mapped from a contained XML attribute or element.

Specified by:
getChildClass in interface Unmarshaller
Returns:
the chosen class, or null to indicate that the child's class is not determined by this Unmarshaller.
Throws:
java.lang.Exception

addChild

public void addChild(Unmarshaller child)
              throws java.lang.Exception
Description copied from interface: Unmarshaller
Create a reference from this object to the given child object. For example, set a reference-valued JavaBean property, or add a member to a Collection.

Specified by:
addChild in interface Unmarshaller
Throws:
java.lang.Exception

addValue

public void addValue(char[] from,
                     int start,
                     int length)
Description copied from interface: Unmarshaller
Add characters from XML content (text) to the value of the mapped object. This method may be called repeatedly, as the XML parser encounters content fragments. The implementation of this method should accumulate the characters from consecutive calls, and map all of them (concatenated) to the object value.

Specified by:
addValue in interface Unmarshaller

trim

protected void trim(java.lang.StringBuffer data)
Trim whitespace from XML data.


setValue

protected void setValue(java.lang.StringBuffer data)
                 throws java.lang.Exception
Convert the text and store the resulting data into the object.

Throws:
java.lang.Exception

endObject

public java.lang.Object endObject()
                           throws java.lang.Exception
Description copied from interface: Unmarshaller
Conclude the mapping of this object, and return it.

Specified by:
endObject in interface Unmarshaller
Returns:
the object that this Unmarshaller mapped from XML.
Throws:
java.lang.Exception

afterEndObject

protected void afterEndObject()
                       throws java.lang.Exception
Throws:
java.lang.Exception

reset

protected void reset()
Release all resources, and subsequently behave as though newly constructed.


getMap

protected java.util.Map getMap(java.util.Map map,
                               java.lang.Object key)

rethrow

public static void rethrow(java.lang.Throwable t)
                    throws java.lang.Exception
Throw an exception that contains the most diagnostic information available from the given Throwable.

Throws:
java.lang.Exception