com.waveset.util
Interface XmlObject

All Known Implementing Classes:
AbstractXmlObject, PersistentObject, PropertyList, SimpleProperties, TaskTemplate

public interface XmlObject

An interface for objects that are able to serialize and deserialize themselves using XML. Objects that either implement this interface, or extend AbstractXmlObject may be "contained" by other objects that support XML serialization.

Adapted from similar code in the PersistentObject class so we can support lighter weight object serialization, without having to make everything a PersistentObject.

Normally you will extend AbstractXmlObject to take advantage of default implementations of some of the methods. But if you're already inheriting something else, you may implement this interface and copy the default implemetnations from AbstractXmlObject.

Note that rather than requiring classes to implement a factory method that parses an Element and returning an object, we will use reflection to look for a class constructor that takes an Element argument. Unfortunately we can't define constructor signatures in an interface, so we have no way to check this at compile time.


Field Summary
static java.lang.String code_id
          This is only public so that it can be contained in an interface.
 
Method Summary
 java.lang.String getElementName()
          Objects must provide the name of the XML element that will be used in their serialized representation.
 java.lang.String toXml()
          Objects must be able to render themselves as valid XML documents including a header and DOCTYPE.
 void toXml(java.lang.StringBuffer b, int indent)
          Objects must be able to render themselves as XML into a string buffer, with an optional amount of indentation.
 

Field Detail

code_id

public static final java.lang.String code_id
This is only public so that it can be contained in an interface.

See Also:
Constant Field Values
Method Detail

getElementName

public java.lang.String getElementName()
Objects must provide the name of the XML element that will be used in their serialized representation.

Returns:
the element name

toXml

public java.lang.String toXml()
Objects must be able to render themselves as valid XML documents including a header and DOCTYPE. Normally this is implemented by AbstractXmlObject, which also provides a static implementation toXml(XmlObject) which may be called from classes that must implement this interface.

Returns:
the string representation of this object

toXml

public void toXml(java.lang.StringBuffer b,
                  int indent)
Objects must be able to render themselves as XML into a string buffer, with an optional amount of indentation. This rendering should not include an XML header or DOCTYPE. The indentation count should be handled by XmlUtil.addIndent so we can globally turn indentation on or off.

Parameters:
b - target buffer
indent - amount of indentation