com.openharbor.beck.unmarshal
Class ContractionUnmarshaller

java.lang.Object
  extended bycom.openharbor.beck.unmarshal.DefaultUnmarshaller
      extended bycom.openharbor.beck.unmarshal.JavaBeanUnmarshaller
          extended bycom.openharbor.beck.unmarshal.ContractionUnmarshaller
All Implemented Interfaces:
Configurable, MapFromXML.Aware, Setter, Unmarshaller

public class ContractionUnmarshaller
extends JavaBeanUnmarshaller
implements Configurable, Setter

Maps two levels of the XML tree to one level of the object tree. So, there is no object that corresponds to this.getSource(), but each of the XML elements or attributes contained in this getSource() maps to an object. Those objects' types and names are mapped from XML names formed by concatenating the name of this.getSource and the name of each child source. For example,

<money>
     <value>29.99</value>
     <currency>USD</currency>
 </money>
is handled like:
<moneyValue>29.99</moneyValue>
 <moneyCurrency>USD</moneyCurrency>
A ContractionUnmarshaller acts as its own Setter (by default), with a setValue method that does nothing.

ContractionUnmarshallers can be cascaded, to map three or more levels of XML containment to a single level of Java object references.


Field Summary
 
Fields inherited from class com.openharbor.beck.unmarshal.JavaBeanUnmarshaller
STRING_PARAMETER
 
Fields inherited from class com.openharbor.beck.unmarshal.DefaultUnmarshaller
data, documentState, log
 
Fields inherited from interface com.openharbor.beck.configure.Configurable
ATTRIBUTE, CLASS_IS_ARRAY, DIRECTION, ELEMENT, JAVA_TO_XML, NAMESPACE, NONE, PARENT_CLASS, PARENT_ELEMENT, PREDICATE, PREFIX, SCHEMA_LOCATION, TEXT, XML_TO_JAVA
 
Constructor Summary
ContractionUnmarshaller()
           
 
Method Summary
 void addChild(Unmarshaller child)
          Create a reference from this object to the given child object.
protected  void afterEndObject()
          Don't call this.addToParent (as the inherited method would).
protected  XMLThing contract(XMLThing source)
          Insert this.getSource().getName() in front of the given thing's name.
 java.lang.Class getChildClass(XMLThing childSource)
          Choose the class of the object to be mapped from a contained XML attribute or element.
 java.util.Map getConfiguration()
           
 java.lang.Object getObject()
           
 java.lang.Object getValue(Unmarshaller self, java.lang.Object[] getterParameters)
          Traverse an existing relationship from parent to child.
 java.lang.Class getValueClass(JavaBeanUnmarshaller parent)
          Find the expected class of a child object; for example, the declared class of a field or JavaBean property.
 java.lang.Object removeValue(Unmarshaller self, java.lang.Object[] getterParameters)
           
 java.lang.Object replaceValue(Unmarshaller self, java.lang.Object[] getterParameters)
           
 void setConfiguration(java.util.Map configuration)
           
protected  void setParentAndSource(Unmarshaller parent, XMLThing source)
          Maintain an engagement on the parent Unmarshaller.
 void setValue(Unmarshaller self, java.lang.Object[] getterParameters)
          Create a relationship from parent to child.
 
Methods inherited from class com.openharbor.beck.unmarshal.JavaBeanUnmarshaller
getSetter, setValue, startElement
 
Methods inherited from class com.openharbor.beck.unmarshal.DefaultUnmarshaller
addToParent, addValue, disengage, disengaged, endElement, endObject, engage, getMap, getMapFromXML, getObjectClass, getParent, getSource, getSourceXPath, getXMLContext, getXName, getXPath, isEngaged, newObject, processAttributes, referToThis, reset, rethrow, setMapFromXML, setObject, setObjectClass, setXMLContext, startObject, toString, trim
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContractionUnmarshaller

public ContractionUnmarshaller()
Method Detail

getConfiguration

public java.util.Map getConfiguration()
Specified by:
getConfiguration in interface Configurable

setConfiguration

public void setConfiguration(java.util.Map configuration)
Specified by:
setConfiguration in interface Configurable

setParentAndSource

protected void setParentAndSource(Unmarshaller parent,
                                  XMLThing source)
Maintain an engagement on the parent Unmarshaller. This prevents the parent from being disengaged before this is; which is necessary because this delegates some methods to the parent.

When ContractionUnmarshallers are cascaded, they build up a chain of engagements, with each engaging its parent.

Overrides:
setParentAndSource in class DefaultUnmarshaller

getObject

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

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
Overrides:
getChildClass in class JavaBeanUnmarshaller
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
Overrides:
addChild in class JavaBeanUnmarshaller
Throws:
java.lang.Exception

afterEndObject

protected void afterEndObject()
Don't call this.addToParent (as the inherited method would).

Overrides:
afterEndObject in class DefaultUnmarshaller

contract

protected XMLThing contract(XMLThing source)
Insert this.getSource().getName() in front of the given thing's name. For example, return <moneyValue id="x"/> given <value id="x"/>.


getValueClass

public java.lang.Class getValueClass(JavaBeanUnmarshaller parent)
Description copied from interface: Setter
Find the expected class of a child object; for example, the declared class of a field or JavaBean property. The actual class of the child object may be derived from this class.

Specified by:
getValueClass in interface Setter
Parameters:
parent - describes the parent object, or null if the parent is not yet known.
Returns:
the expected class of the child object, or null if no particular class is expected.

setValue

public void setValue(Unmarshaller self,
                     java.lang.Object[] getterParameters)
Description copied from interface: Setter
Create a relationship from parent to child. Ordinarily, set a member of the parent to refer to the child.

Specified by:
setValue in interface Setter
Parameters:
self - describes the child object. child.getParent() describes the parent.
getterParameters - additional parameters to the setter method, such as LocaleTag.

getValue

public java.lang.Object getValue(Unmarshaller self,
                                 java.lang.Object[] getterParameters)
Description copied from interface: Setter

Traverse an existing relationship from parent to child. Call child.setObject() and child.setObjectClass() to record the child's identity and type, and return a reference to the child.

This method is used to resolve XPaths. Given an object and an XPath, we create an Unmarshaller for every level of the XPath, use the mapper to retrieve the corresponding setters, then traverse the object model using this method.

Specified by:
getValue in interface Setter
Parameters:
self - Child unmarshaller, which represents the property we're interested in. The parent (or the object whose property is to be read) can be accessed by child.getParent().
getterParameters - the parameters the getter takes. Typically, getters take no parameters, and null can be passed in. With mutli-lingual properties however, LocaleTag must be passed in to identify the language of interest,
Returns:
a reference to the child object, or null if there is no existing child.

removeValue

public java.lang.Object removeValue(Unmarshaller self,
                                    java.lang.Object[] getterParameters)
Specified by:
removeValue in interface Setter

replaceValue

public java.lang.Object replaceValue(Unmarshaller self,
                                     java.lang.Object[] getterParameters)
Specified by:
replaceValue in interface Setter