dsto.dfc.databeans.io
Class XmlLinkCodec

java.lang.Object
  extended by dsto.dfc.databeans.io.XmlLinkCodec
All Implemented Interfaces:
XmlDecodeContext.IdCallback, XmlDecoder, XmlEncodeContext.IdCallback, XmlEncoder

public class XmlLinkCodec
extends Object
implements XmlEncoder, XmlDecoder, XmlEncodeContext.IdCallback, XmlDecodeContext.IdCallback

XML codec for the standard IDataObjectLink implementations: DataObjectLink and DataBeanLink. todo merge support for weak links in here.

Version:
$Revision$
Author:
mpp

Constructor Summary
XmlLinkCodec()
           
 
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.
 org.jdom.Element encode(XmlEncodeContext context, Object value)
          Generate an XML representation of an object.
 void idForObjectCallback(XmlEncodeContext context, org.jdom.Element element, String id, Object extraData)
          Called by encode context when an ID becomes available for a given object.
 void objectForIdCallback(XmlDecodeContext context, org.jdom.Element element, Object object, Object extraData)
          Called by decode context when an value becomes available for a given ID .
 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

XmlLinkCodec

public XmlLinkCodec()
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.

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.

idForObjectCallback

public void idForObjectCallback(XmlEncodeContext context,
                                org.jdom.Element element,
                                String id,
                                Object extraData)
Description copied from interface: XmlEncodeContext.IdCallback
Called by encode context when an ID becomes available for a given object. See XmlEncodeContext.callbackWithIdForObject(IdCallback, Element, Object, Object).

Specified by:
idForObjectCallback in interface XmlEncodeContext.IdCallback
Parameters:
context - The current encoding context.
element - The element passed to callbackWithIdForObject ().
id - The ID for the requested value.
extraData - The extraData passed to callbackWithIdForObject ().

objectForIdCallback

public void objectForIdCallback(XmlDecodeContext context,
                                org.jdom.Element element,
                                Object object,
                                Object extraData)
Description copied from interface: XmlDecodeContext.IdCallback
Called by decode context when an value becomes available for a given ID . See XmlDecodeContext.callbackWithObjectForId(IdCallback, Element, String, Object).

Specified by:
objectForIdCallback in interface XmlDecodeContext.IdCallback
Parameters:
context - The current decode context.
element - The element param passed to callbackWithObjectForId ().
object - The object that is registered with the requested ID.
extraData - The extra data param passed to callbackWithObjectForId ().


Copyright © 2008 Commonwealth of Australia