com.openharbor.beck.marshal
Class DefaultMarshaller

java.lang.Object
  extended bycom.openharbor.beck.marshal.DefaultMarshaller
All Implemented Interfaces:
Marshaller
Direct Known Subclasses:
ArrayMarshaller, CollectionMarshaller, DateMarshaller, EnumerationMarshaller, JavaBeanMarshaller, MapMarshaller, PrimitiveMarshaller, QNameMarshaller, StringMarshaller, XPathMarshaller

public class DefaultMarshaller
extends java.lang.Object
implements Marshaller


Field Summary
protected  org.apache.commons.logging.Log log
           
 
Constructor Summary
DefaultMarshaller()
           
 
Method Summary
 java.lang.String getText(java.lang.Object parent, Getter source, java.lang.Object child, XMLWriter out)
          Copy data as a String, for use as XML element text or an XML attribute value.
 XMLThing getXML(MapToXML mapper, java.lang.Object parent, Getter getter, XMLWriter writer)
          Choose the XML element or attribute name for a Java object.
 java.lang.Object getXMLSource(MapToXML mapper, java.lang.Object parent, Getter getter)
          This implementation returns getter.getValue(parent), but extended classes override this.
 void marshal(MapToXML mapper, java.lang.Object parent, Getter getter, XMLThing tag, XMLWriter writer)
          Generate XML from an object and its contained objects (if any).
protected  void marshalMember(XMLThing tag, MapToXML mapper, java.lang.Object parent, Getter getter, Marshaller marshaller, XMLWriter writer)
           
protected  void writeAsElement(MapToXML mapper, java.lang.Object parent, Getter getter, java.lang.Object source, XMLThing tag, XMLWriter writer)
           
protected  void writeNull(MapToXML mapper, java.lang.Object parent, Getter getter, XMLWriter out)
          Generate the XML representation of a null reference (the absence of an object).
protected  boolean writeSimply(XMLThing tag, XMLWriter out)
          Output XML if it's simple.
 
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
Constructor Detail

DefaultMarshaller

public DefaultMarshaller()
Method Detail

getXML

public XMLThing getXML(MapToXML mapper,
                       java.lang.Object parent,
                       Getter getter,
                       XMLWriter writer)
                throws java.lang.Exception
Description copied from interface: Marshaller
Choose the XML element or attribute name for a Java object. If the returned thing is an element with a null value, the caller should output the element and also additional attributes and/or content mapped from the source object. If the returned thing is an attribute or an element with a non-null value, the caller should output the returned thing without additions.

Specified by:
getXML in interface Marshaller
Parameters:
getter - to be mapped to XML
parent - contains source
Returns:
an attribute name and value or an element name with a set of conditions, or null to indicate that this source should not be marshalled.
Throws:
java.lang.Exception

marshal

public void marshal(MapToXML mapper,
                    java.lang.Object parent,
                    Getter getter,
                    XMLThing tag,
                    XMLWriter writer)
             throws java.lang.Exception
Description copied from interface: Marshaller
Generate XML from an object and its contained objects (if any).

Specified by:
marshal in interface Marshaller
Parameters:
parent - the object that contains this one, or null if the containing object is unknown.
getter - a reference to the object to be mapped and its name (if any) in the parent.
tag - the desired element name and conditions, or null if unspecified.
writer - the stream wherein to marshal the generated XML.
Throws:
java.lang.Exception

getXMLSource

public java.lang.Object getXMLSource(MapToXML mapper,
                                     java.lang.Object parent,
                                     Getter getter)
This implementation returns getter.getValue(parent), but extended classes override this. For example, this method returns null if the XML is a cross-reference (such as an XPath or idref), or simply has no Java counterpart.

Specified by:
getXMLSource in interface Marshaller

getText

public java.lang.String getText(java.lang.Object parent,
                                Getter source,
                                java.lang.Object child,
                                XMLWriter out)
                         throws java.lang.Exception
Description copied from interface: Marshaller
Copy data as a String, for use as XML element text or an XML attribute value.

Specified by:
getText in interface Marshaller
Returns:
the text representation of the given child, or null to indicate that it's not representable as text.
Throws:
java.lang.Exception

writeNull

protected void writeNull(MapToXML mapper,
                         java.lang.Object parent,
                         Getter getter,
                         XMLWriter out)
                  throws java.lang.Exception
Generate the XML representation of a null reference (the absence of an object). This implementation does nothing: by default, a null reference is absent from the XML. This behavior is overridable, as usual.

Throws:
java.lang.Exception

writeSimply

protected boolean writeSimply(XMLThing tag,
                              XMLWriter out)
                       throws java.lang.Exception
Output XML if it's simple. That is, return false if the given tag is an element that might have sub-elements. Otherwise, write the tag into the given stream and return true.

Parameters:
tag -
out -
Returns:
Throws:
java.lang.Exception

writeAsElement

protected void writeAsElement(MapToXML mapper,
                              java.lang.Object parent,
                              Getter getter,
                              java.lang.Object source,
                              XMLThing tag,
                              XMLWriter writer)
                       throws java.lang.Exception
Throws:
java.lang.Exception

marshalMember

protected void marshalMember(XMLThing tag,
                             MapToXML mapper,
                             java.lang.Object parent,
                             Getter getter,
                             Marshaller marshaller,
                             XMLWriter writer)
                      throws java.lang.Exception
Throws:
java.lang.Exception