org.bifrost.xmlio
Class XmlWriter

java.lang.Object
  extended by org.bifrost.xmlio.XmlWriter

public class XmlWriter
extends java.lang.Object

Serialize an xml representation of a graph of objects into a writer.

Created: Feb 24, 2003
Copyright: Copyright (c) 2003
Assumptions: none
Requires: nothing
Required by: nothing
Revision History:

Example:

 Config config = new Config();
 config.setNumber(123);
 config.setString("acb");
 XmlWriter writer = new XmlWriter("filename.xml");
 writer.setRootObject(config);
 
 Would produce an xml file that might look like:
 <Config>
   <number>123</number>
   <string>abc</string>
 </Config>
 

Conventions:

Version:
1.0
Author:
Donald Kittle

Field Summary
static java.lang.String EX_CLOSE
          Exception when there is a problem flushing or closing the writer.
static java.lang.String EX_FILE
          Exception when there is an error creating an output file.
static java.lang.String EX_NULL_ATTRIBUTE
          Exception when an attribute is null.
static java.lang.String EX_NULL_OBJECT
          Exception when a null object is encountered.
static java.lang.String EX_NULL_WRITER
          Exception when a writer is null.
static java.lang.String EX_OBJECT_GRAPH
          Exception when there is an error calling a getter.
static java.lang.String EX_PRIMATIVE
          Exception when a primative object is found in a List or Set.
static java.lang.String EX_WRITING
          Exception when there is an error writing to the Writer.
 
Constructor Summary
XmlWriter(java.lang.String filename)
          Constructor which creates a FileWriter from the supplied filename.
XmlWriter(java.io.Writer writer)
          Constructor which initializes the XmlWriter with the supplied writer object.
 
Method Summary
 boolean getBeautify()
          Gets the flag which controls 'beautifying' the output.
 java.lang.String getBreakString()
          Gets the string which will be used to break each element/attribute line of the resulting xml if beatifying is true.
 org.bifrost.xmlio.config.XmlIOConfig getConfig()
           
 boolean getDashedNames()
           
 boolean getIncludePackageName()
          Get the flag indicating whether the fully qualified classname should be output as an element or just the classname (without the package).
 java.lang.String getIndentString()
          Gets the string which will be used to indent each element/attribute of the resulting xml if beatifying is true.
 boolean getOutputNulls()
           
 void setBeautify(boolean beautify)
          Sets the flag to control 'beautifying' the output.
 void setBreakString(java.lang.String breakString)
          Sets the string which will be used to break each element/attribute line of the resulting xml if beatifying is true.
 void setConfig(org.bifrost.xmlio.config.XmlIOConfig config)
           
 void setDashedNames(boolean dashedNames)
           
 void setIncludePackageName(boolean includePackageName)
          Set the flag indicating whether the fully qualified classname should be output as an element or just the classname (without the package).
 void setIndentString(java.lang.String indentString)
          Sets the string which will be used to indent each element/attribute of the resulting xml if beatifying is true.
 void setOutputNulls(boolean outputNulls)
           
 void setRootObject(java.lang.Object rootObject)
          Sets the root object to be serialized out and initiates the process of writing xml out to the writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EX_NULL_OBJECT

public static final java.lang.String EX_NULL_OBJECT
Exception when a null object is encountered.

See Also:
Constant Field Values

EX_PRIMATIVE

public static final java.lang.String EX_PRIMATIVE
Exception when a primative object is found in a List or Set.

See Also:
Constant Field Values

EX_WRITING

public static final java.lang.String EX_WRITING
Exception when there is an error writing to the Writer.

See Also:
Constant Field Values

EX_OBJECT_GRAPH

public static final java.lang.String EX_OBJECT_GRAPH
Exception when there is an error calling a getter.

See Also:
Constant Field Values

EX_NULL_ATTRIBUTE

public static final java.lang.String EX_NULL_ATTRIBUTE
Exception when an attribute is null.

See Also:
Constant Field Values

EX_FILE

public static final java.lang.String EX_FILE
Exception when there is an error creating an output file.

See Also:
Constant Field Values

EX_CLOSE

public static final java.lang.String EX_CLOSE
Exception when there is a problem flushing or closing the writer.

See Also:
Constant Field Values

EX_NULL_WRITER

public static final java.lang.String EX_NULL_WRITER
Exception when a writer is null.

See Also:
Constant Field Values
Constructor Detail

XmlWriter

public XmlWriter(java.io.Writer writer)
          throws XmlException
Constructor which initializes the XmlWriter with the supplied writer object.

Parameters:
writer - the writer to output to.
Throws:
XmlException - if there was a problem

XmlWriter

public XmlWriter(java.lang.String filename)
          throws XmlException
Constructor which creates a FileWriter from the supplied filename.

Parameters:
filename - the name of the file to write to
Throws:
XmlException - if there was a problem
Method Detail

getBeautify

public boolean getBeautify()
Gets the flag which controls 'beautifying' the output.

Returns:
boolean the flag controlling whether or not output should be 'beautified'

getBreakString

public java.lang.String getBreakString()
Gets the string which will be used to break each element/attribute line of the resulting xml if beatifying is true.

Returns:
String the string which will be used to break each element/attribute line

getIndentString

public java.lang.String getIndentString()
Gets the string which will be used to indent each element/attribute of the resulting xml if beatifying is true.

Returns:
String the string which will be used to indent each element/attribute

getIncludePackageName

public boolean getIncludePackageName()
Get the flag indicating whether the fully qualified classname should be output as an element or just the classname (without the package).

Returns:
boolean whether a fully qualified classname should be output.

setBeautify

public void setBeautify(boolean beautify)
Sets the flag to control 'beautifying' the output.

Parameters:
beautify - the flag controlling whether or not output should be 'beautified'

setBreakString

public void setBreakString(java.lang.String breakString)
Sets the string which will be used to break each element/attribute line of the resulting xml if beatifying is true.

Parameters:
breakString - the string which will be used to break each element/attribute line

setIndentString

public void setIndentString(java.lang.String indentString)
Sets the string which will be used to indent each element/attribute of the resulting xml if beatifying is true.

Parameters:
indentString - the string which will be used to indent each element/attribute

setIncludePackageName

public void setIncludePackageName(boolean includePackageName)
Set the flag indicating whether the fully qualified classname should be output as an element or just the classname (without the package).

Parameters:
rootObject -
Throws:
XmlException

setRootObject

public void setRootObject(java.lang.Object rootObject)
                   throws XmlException
Sets the root object to be serialized out and initiates the process of writing xml out to the writer. Any attributes that are not a primative nor an Object that represents a primative will be serialized as an object with 'primative' attributes.

Parameters:
rootObject - the root object of the graph that will be serialized to xml
Throws:
XmlException - if there was a problem

getConfig

public org.bifrost.xmlio.config.XmlIOConfig getConfig()
Returns:
Returns the configuration.

setConfig

public void setConfig(org.bifrost.xmlio.config.XmlIOConfig config)
Parameters:
config - The new configuration.

getOutputNulls

public boolean getOutputNulls()

setOutputNulls

public void setOutputNulls(boolean outputNulls)

getDashedNames

public boolean getDashedNames()

setDashedNames

public void setDashedNames(boolean dashedNames)