com.waveset.util
Class AbstractXmlObject

java.lang.Object
  extended by com.waveset.util.AbstractXmlObject
All Implemented Interfaces:
XmlObject, javax.naming.Referenceable
Direct Known Subclasses:
AttributeCondition, GenericObject, ResourceInfo, ResultError, ResultItem, Subject, Util.TimePeriod, WavesetResult, WSAttribute

public abstract class AbstractXmlObject
extends java.lang.Object
implements XmlObject, javax.naming.Referenceable

An abstract class that implements the XmlObject interface and provides a set of default implementations for some methods. You normally want to extend this rather than implement XmlObject, though you may be forced to implement XmlObject if you're already extending some other class.

This got a lot simpler as it evolved, we may be able to get rid of this and move some of the stuff to XmlUtil.

Implements Referenceable so that any AbstractXmlObject can be bound into a JNDI service provider.


Field Summary
static java.lang.String code_id
           
 
Constructor Summary
AbstractXmlObject()
           
 
Method Summary
static void addXmlHeader(java.lang.StringBuffer b, java.lang.String doctypeName)
          Adds a standard XML header, DOCTYPE statement and element start tag.
 java.lang.Object cloneObject()
          Make a deep copy of an object by serializing it and parsing the serialization into a new object.
 void dump()
          Dump an XML for an object to the console.
 void dumpFile(java.lang.String file)
          Dump the XML for an object to a file.
abstract  java.lang.String getElementName()
          Return the element name.
 javax.naming.Reference getReference()
           
 void setTrace(boolean b)
           
 java.lang.String toIdentityString()
           
 java.lang.String toVerboseString()
           
 java.lang.String toVerboseString(java.lang.String indent)
           
 java.lang.String toXml()
          A default implementation for rendering as a valid XML document.
 void toXml(java.lang.StringBuffer b)
          This isn't defined in the XmlObject interface, but its used a lot in older code, so provide an implementation to ease the transition.
abstract  void toXml(java.lang.StringBuffer b, int indent)
          Serialize into a buffer with optional indentation.
static java.lang.String toXml(XmlObject obj)
          Renders the full XML for an object, including header and DOCTYPE statement.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values
Constructor Detail

AbstractXmlObject

public AbstractXmlObject()
Method Detail

addXmlHeader

public static void addXmlHeader(java.lang.StringBuffer b,
                                java.lang.String doctypeName)
Adds a standard XML header, DOCTYPE statement and element start tag. This is typically called by the toXml method below prior to calling the toXml method of a subclass. Subclasses may also call it if they want to overload the generation of the header or DOCTYPE for some reason, though there should be no reason to do so.

Direct implementations of XmlObject that can't subclass AbstractXmlObject may also call this in their required implementations of toXml.

Parameters:
b - StringBuffer for generated xml.
doctypeName - document type

cloneObject

public java.lang.Object cloneObject()
                             throws com.waveset.util.WavesetException
Make a deep copy of an object by serializing it and parsing the serialization into a new object. We don't use clone so we can throw exceptions.

Returns:
clone of this XmlObject
Throws:
com.waveset.util.WavesetException - if there's a problem generating or parsing the xml.

dump

public void dump()
Dump an XML for an object to the console. This is a debugging aid, you can call this from the JBuilder Evaluate/Modify dialog to get an object rendered into the output panel, its easier than navigating through the object browser.


dumpFile

public void dumpFile(java.lang.String file)
Dump the XML for an object to a file. This is a debugging aid you can call from within JBuilder.

Parameters:
file - path for dump

getElementName

public abstract java.lang.String getElementName()
Return the element name.

Specified by:
getElementName in interface XmlObject
Returns:
the element name

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Specified by:
getReference in interface javax.naming.Referenceable
Throws:
javax.naming.NamingException

setTrace

public void setTrace(boolean b)

toIdentityString

public java.lang.String toIdentityString()

toVerboseString

public java.lang.String toVerboseString()

toVerboseString

public java.lang.String toVerboseString(java.lang.String indent)

toXml

public java.lang.String toXml()
A default implementation for rendering as a valid XML document.

Specified by:
toXml in interface XmlObject
Returns:
the string representation of this object

toXml

public void toXml(java.lang.StringBuffer b)
This isn't defined in the XmlObject interface, but its used a lot in older code, so provide an implementation to ease the transition.

Parameters:
b - StringBuffer for generated xml.

toXml

public abstract void toXml(java.lang.StringBuffer b,
                           int indent)
Serialize into a buffer with optional indentation. This must be implemented by the subclass.

Specified by:
toXml in interface XmlObject
Parameters:
b - StringBuffer in which to write the generated xml
indent - Number of spaces to indent the generated xml block

toXml

public static java.lang.String toXml(XmlObject obj)
Renders the full XML for an object, including header and DOCTYPE statement.

This is provided as a static method so that it may be called from the required toXml method of classes that implement XmlObject rather than extend AbstractXmlObject.

We'll ask the object for its element name which we then use in the DOCTYPE. If it doesn't give us one, we'll wrap it in our generic container element.

Parameters:
obj - XmlObject to serialize as xml.
Returns:
xml for obj.