dsto.dfc.databeans.io
Class XmlMemberwiseCodec

java.lang.Object
  extended by dsto.dfc.databeans.io.XmlMemberwiseCodec
All Implemented Interfaces:
XmlDecoder, XmlEncoder

public class XmlMemberwiseCodec
extends Object
implements XmlEncoder, XmlDecoder

An XML codec that encodes/decodes objects by reading their data fields.

Example usage:

 SerializeXmlCodec.register ("person", "org.app.Person");
 

Author:
phillipm

Constructor Summary
XmlMemberwiseCodec(String name, Class type)
           
 
Method Summary
 boolean canEncode(XmlEncodeContext context, Object value)
          Test if this codec can encode a given object.
 Object decode(XmlDecodeContext context, org.jdom.Element element)
          Decode an XML representation into a value.
static void decodeFields(XmlDecodeContext context, org.jdom.Element element, Object object)
          Decode the fields of an object from an XML element.
 org.jdom.Element encode(XmlEncodeContext context, Object value)
          Generate an XML representation of an object.
static void encodeFields(XmlEncodeContext context, org.jdom.Element element, Object object)
          Encode the fields of an object into an XML element.
static void register(String name, Class type)
          Register this codec for a given object type.
 boolean shouldPreserveIdentity(XmlEncodeContext context, Object value)
          Return true if the identity of the given value should be preserved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlMemberwiseCodec

public XmlMemberwiseCodec(String name,
                          Class type)
Method Detail

register

public static void register(String name,
                            Class type)
Register this codec for a given object type.

Parameters:
name - The XML tag name to use (eg "person").
type - The type of object (eg Person.class).

shouldPreserveIdentity

public boolean shouldPreserveIdentity(XmlEncodeContext context,
                                      Object value)
Description copied from interface: XmlEncoder
Return true if the identity of the given value should be preserved. If true, any instances of the object after the first will be written out as references to the original rather than a copy.

Specified by:
shouldPreserveIdentity in interface XmlEncoder

canEncode

public boolean canEncode(XmlEncodeContext context,
                         Object value)
Description copied from interface: XmlEncoder
Test if this codec can encode a given object.

Specified by:
canEncode in interface XmlEncoder
Parameters:
context - The current encode context.
value - The value. May be null.
Returns:
True if this encoder should be used for value.

encode

public org.jdom.Element encode(XmlEncodeContext context,
                               Object value)
Description copied from interface: XmlEncoder
Generate an XML representation of an object.

Specified by:
encode in interface XmlEncoder
Parameters:
context - The encoding context.
value - The value to be encoded.
Returns:
The JDOM element created for the value.

decode

public Object decode(XmlDecodeContext context,
                     org.jdom.Element element)
              throws IllegalArgumentException,
                     ClassNotFoundException
Description copied from interface: XmlDecoder
Decode an XML representation into a value.

Specified by:
decode in interface XmlDecoder
Parameters:
context - The decode context.
element - The element to decode.
Returns:
The new object.
Throws:
IllegalArgumentException - if an error is found in the structure of the document.
ClassNotFoundException - if a referenced class cannot be found.

encodeFields

public static void encodeFields(XmlEncodeContext context,
                                org.jdom.Element element,
                                Object object)
                         throws IllegalArgumentException
Encode the fields of an object into an XML element.

Throws:
IllegalArgumentException

decodeFields

public static void decodeFields(XmlDecodeContext context,
                                org.jdom.Element element,
                                Object object)
                         throws IllegalArgumentException,
                                ClassNotFoundException
Decode the fields of an object from an XML element.

Throws:
IllegalArgumentException
ClassNotFoundException


Copyright © 2008 Commonwealth of Australia