dsto.dfc.databeans.io
Class XmlEncodeContext

java.lang.Object
  extended by dsto.dfc.databeans.io.XmlEncodeContext

public class XmlEncodeContext
extends Object

Contains context state during an XML encoding operation. XmlEncoder clients receive an instance via XmlEncoder.encode(XmlEncodeContext, Object).

Version:
$Revision$
Author:
mpp

Nested Class Summary
static interface XmlEncodeContext.IdCallback
          Callback interface for clients that wish to use forward references.
 
Constructor Summary
protected XmlEncodeContext(List xmlEncoders, List textEncoders, Map typeAliases)
           
 
Method Summary
 void callbackWithIdForObject(XmlEncodeContext.IdCallback callback, org.jdom.Element element, Object value, Object extraData)
          Register a callback to be invoked when an ID becomes defined for another encoded value.
protected  void doPostEncode()
           
 org.jdom.Element encode(Object value)
          Mediates the encoding of a value.
 String encodeType(Class valueClass)
          Get the encoded type name for a class, taking type aliases and array encoding into account.
 Object getProperty(Object name)
          Get a custom property defined by setProperty(Object, Object).
 TextEncoder getTextEncoder(Object value)
          Get the registered text encoder for a given value.
 String getTypeAlias(Class valueClass)
          Get the alias for a given type.
 XmlEncoder getXmlEncoder(Object value)
          Get the registered XML encoder for a given value.
 TextEncoder peekTextEncoder(Object value)
          Lookup the registered text encoder for a given value.
 void registerElement(org.jdom.Element element, Object value)
          Register a document element as representing a given value.
protected  void setProperties(Map properties)
          Set all custom properties.
 void setProperty(Object name, Object value)
          Define a custom property that will be accessible during this session via getProperty(Object).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlEncodeContext

protected XmlEncodeContext(List xmlEncoders,
                           List textEncoders,
                           Map typeAliases)
Method Detail

doPostEncode

protected void doPostEncode()

setProperties

protected void setProperties(Map properties)
Set all custom properties. Used by XmlOutput.

See Also:
setProperty(Object, Object)

setProperty

public void setProperty(Object name,
                        Object value)
Define a custom property that will be accessible during this session via getProperty(Object).

See Also:
XmlOutput.setProperty(Object, Object)

getProperty

public Object getProperty(Object name)
Get a custom property defined by setProperty(Object, Object).


encode

public org.jdom.Element encode(Object value)
Mediates the encoding of a value. This method should be used in preference to a direct call to the registered XmlEncoder for a value, since it manages generation of id/refid for values that need their identity preserved.

Parameters:
value - The value to encode.
Returns:
The element representing the encoded value.
Throws:
IllegalArgumentException - if the value could not be encoded.

getXmlEncoder

public XmlEncoder getXmlEncoder(Object value)
Get the registered XML encoder for a given value.


getTextEncoder

public TextEncoder getTextEncoder(Object value)
                           throws IllegalStateException
Get the registered text encoder for a given value.

Throws:
IllegalStateException - if no encoder found.
See Also:
peekTextEncoder(Object)

peekTextEncoder

public TextEncoder peekTextEncoder(Object value)
Lookup the registered text encoder for a given value.

Returns:
The encoder, or null.
See Also:
getTextEncoder(Object)

getTypeAlias

public String getTypeAlias(Class valueClass)
Get the alias for a given type.

Returns:
The alias, or null if no registered alias.

encodeType

public String encodeType(Class valueClass)
Get the encoded type name for a class, taking type aliases and array encoding into account.

See Also:
XmlDecodeContext.decodeType(String)

registerElement

public void registerElement(org.jdom.Element element,
                            Object value)
Register a document element as representing a given value. This registration may be used later if an ID is needed for the element.

Clients do not need to call this, since encode(Object) does this automatically, but may choose to do so early if they contain child values that may reference the value.


callbackWithIdForObject

public void callbackWithIdForObject(XmlEncodeContext.IdCallback callback,
                                    org.jdom.Element element,
                                    Object value,
                                    Object extraData)
Register a callback to be invoked when an ID becomes defined for another encoded value. This can be used if a client wants to refer to a value that may not have been encoded yet. When an ID is defined the client will be notified via XmlEncodeContext.IdCallback.idForObjectCallback(dsto.dfc.databeans.io.XmlEncodeContext, org.jdom.Element, java.lang.String, java.lang.Object). The callback will be invoked immediately if an ID is already available.

Parameters:
callback - The callback target.
element - The element param to be passed to the callback.
value - The value for which an ID is needed.
extraData - Any extra data to be passed to the callback (may be null).
See Also:
XmlEncodeContext.IdCallback.idForObjectCallback(dsto.dfc.databeans.io.XmlEncodeContext, org.jdom.Element, java.lang.String, java.lang.Object), XmlDecodeContext.callbackWithObjectForId(dsto.dfc.databeans.io.XmlDecodeContext.IdCallback, org.jdom.Element, java.lang.String, java.lang.Object)


Copyright © 2008 Commonwealth of Australia