org.apache.muse.core.serializer.xstream
Class XStreamSerializer

java.lang.Object
  extended byorg.apache.muse.core.serializer.xstream.XStreamSerializer
All Implemented Interfaces:
Serializer

public abstract class XStreamSerializer
extends java.lang.Object
implements Serializer

XStreamSerializer is a generic Serializer that relies on the XStream library to serialize and deserialize objects to/from XML without any configuration files or schemas. To use this class within Muse applications, simply sub-class it an override the getSerializableType() method to return the class or interface that is being serialized. That's it!

This serializer has some additional code that helps XStream create "pure" XML by adding better support for XML namespaces and prefixes, as well as being more flexible in the Java field name conventions that can be read and converted into proper XML element names.

For more information about how XStream serializes your objects, and to get the JAR file needed to execute this code, please visit XStream's web site:

http://xstream.codehaus.org

Author:
Dan Jemiolo (danj)
See Also:
Serializer

Constructor Summary
XStreamSerializer()
           
 
Method Summary
protected  org.w3c.dom.Element copySubTree(org.w3c.dom.Element[] children, org.w3c.dom.Element root, java.lang.String namespace, java.lang.String prefix)
          This method takes the non-namespace-aware DOM (DOM Level 1) that is generated by XStream and converts it into an equivalent DOM tree with the proper namespaces and prefixes.
 java.lang.Object fromXML(org.w3c.dom.Element xml)
          Deserializes the DOM Element into a POJO whose type this Serializer is responsible for.
 XStream getXStream()
           
 org.w3c.dom.Element toXML(java.lang.Object result, QName qname)
          Serializes the given object into a DOM Element, the value wrapped inside a root element with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.muse.core.serializer.Serializer
getSerializableType
 

Constructor Detail

XStreamSerializer

public XStreamSerializer()
Method Detail

copySubTree

protected org.w3c.dom.Element copySubTree(org.w3c.dom.Element[] children,
                                          org.w3c.dom.Element root,
                                          java.lang.String namespace,
                                          java.lang.String prefix)
This method takes the non-namespace-aware DOM (DOM Level 1) that is generated by XStream and converts it into an equivalent DOM tree with the proper namespaces and prefixes. The namespace and prefix values should be taken from the QName that is provided to the Serializer.toXML() method.


fromXML

public java.lang.Object fromXML(org.w3c.dom.Element xml)
Description copied from interface: Serializer
Deserializes the DOM Element into a POJO whose type this Serializer is responsible for.

Specified by:
fromXML in interface Serializer
Parameters:
xml - The XML representation of a Java object. If the type is primitive or simple (not a primitive, but serialized to a string), the value should be a DOM Text node inside the given Element.
Returns:
A POJO representation of the given XML fragment.

getXStream

public final XStream getXStream()
Returns:
The XStream API, initialized with the DOM parser/driver.

toXML

public org.w3c.dom.Element toXML(java.lang.Object result,
                                 QName qname)
Description copied from interface: Serializer
Serializes the given object into a DOM Element, the value wrapped inside a root element with the given name.

Specified by:
toXML in interface Serializer
Parameters:
result - The object to serialize into XML, or null.
qname - The name of the element which the XML representation will be wrapped in.
Returns:
The XML representation of the object, with the root element having the given QName.