dsto.dfc.databeans.io
Class XmlDataObjectCodec

java.lang.Object
  extended by dsto.dfc.databeans.io.XmlDataObjectCodec
All Implemented Interfaces:
XmlDecoder, XmlEncoder
Direct Known Subclasses:
XmlEntityCodec

public class XmlDataObjectCodec
extends Object
implements XmlEncoder, XmlDecoder

XML encoder/decoder for IDataObject's, IDataBean's and vanilla JavaBean's. This handles any object that:

Author:
Matthew Phillips

Constructor Summary
XmlDataObjectCodec()
           
 
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.
protected  Object decodeDataBean(XmlDecodeContext context, org.jdom.Element element, Class valueType)
          Decode an IDataBean.
protected  IDataObject decodeDataObject(XmlDecodeContext context, org.jdom.Element element, Class valueType)
           
protected  Object decodeDataObjectProperty(XmlDecodeContext context, org.jdom.Element child, IDataObject object)
          Decode the property of a data object
protected  Object decodeJavaBean(XmlDecodeContext context, org.jdom.Element element, Class valueType)
           
 org.jdom.Element encode(XmlEncodeContext context, Object value)
          Generate an XML representation of an object.
protected  org.jdom.Element encodeDataBean(XmlEncodeContext context, IDataBean bean)
          Encode an IDataBean.
protected  void encodeDataBeanProperties(XmlEncodeContext context, IDataBean bean, org.jdom.Element element)
           
protected  org.jdom.Element encodeDataObject(XmlEncodeContext context, IDataObject object)
          Encode an IDataObject.
protected  void encodeDataObjectProperty(XmlEncodeContext context, org.jdom.Element element, IDataObject object, Object property)
           
protected  org.jdom.Element encodeJavaBean(XmlEncodeContext context, Object bean)
          Encode a JavaBean
protected  void setObjectValue(IDataObject object, Object property, Object value)
          Called by data object decoders to set property values.
 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

XmlDataObjectCodec

public XmlDataObjectCodec()
Method Detail

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.

encodeDataObject

protected org.jdom.Element encodeDataObject(XmlEncodeContext context,
                                            IDataObject object)
Encode an IDataObject.


encodeDataObjectProperty

protected void encodeDataObjectProperty(XmlEncodeContext context,
                                        org.jdom.Element element,
                                        IDataObject object,
                                        Object property)
                                 throws IllegalArgumentException
Throws:
IllegalArgumentException

encodeJavaBean

protected org.jdom.Element encodeJavaBean(XmlEncodeContext context,
                                          Object bean)
Encode a JavaBean


encodeDataBean

protected org.jdom.Element encodeDataBean(XmlEncodeContext context,
                                          IDataBean bean)
Encode an IDataBean.


encodeDataBeanProperties

protected void encodeDataBeanProperties(XmlEncodeContext context,
                                        IDataBean bean,
                                        org.jdom.Element element)

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.

decodeDataObject

protected IDataObject decodeDataObject(XmlDecodeContext context,
                                       org.jdom.Element element,
                                       Class valueType)
                                throws ClassNotFoundException,
                                       IllegalArgumentException
Throws:
ClassNotFoundException
IllegalArgumentException

decodeDataObjectProperty

protected Object decodeDataObjectProperty(XmlDecodeContext context,
                                          org.jdom.Element child,
                                          IDataObject object)
                                   throws IllegalArgumentException,
                                          ClassNotFoundException
Decode the property of a data object

Parameters:
context -
child -
object -
Returns:
The property decoded.
Throws:
IllegalArgumentException
ClassNotFoundException

decodeDataBean

protected Object decodeDataBean(XmlDecodeContext context,
                                org.jdom.Element element,
                                Class valueType)
                         throws ClassNotFoundException,
                                IllegalArgumentException
Decode an IDataBean.

Throws:
ClassNotFoundException
IllegalArgumentException

setObjectValue

protected void setObjectValue(IDataObject object,
                              Object property,
                              Object value)
Called by data object decoders to set property values. Subclasses may override to hook changes.


decodeJavaBean

protected Object decodeJavaBean(XmlDecodeContext context,
                                org.jdom.Element element,
                                Class valueType)
                         throws ClassNotFoundException,
                                IllegalArgumentException
Throws:
ClassNotFoundException
IllegalArgumentException


Copyright © 2008 Commonwealth of Australia