dsto.dfc.databeans.io
Class XmlOutput

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

public class XmlOutput
extends Object

Manages encoding of data bean objects to XML. Usage:

   Writer writer = new FileWriter ("file.dbxml");

   XmlOutput xmlOutput = new XmlOutput ();
 
   xmlOutput.write (writer, object);
 
   writer.close ();
 

Version:
$Revision$
Author:
mpp

Constructor Summary
XmlOutput()
          Constructor for XmlOutput.
XmlOutput(org.jdom.output.Format format)
          Constructor for XmlOutput.
XmlOutput(String indent, boolean addNewlines)
          Constructor for XmlOutput.
 
Method Summary
 org.jdom.Element createHeader()
          Method createHeaderElement.
 void finished()
          Signal encoding is finished.
 int getMajorVersion()
           
 int getMinorVersion()
           
 Object getProperty(Object name)
          Get a custom property defined by setProperty(Object, Object).
 boolean isMultiObject()
          See setMultiObject(boolean).
static void registerGlobalTextEncoder(TextEncoder encoder)
          Register a global TextEncoder.
static void registerGlobalXmlEncoder(XmlEncoder encoder)
          Register a global XmlEncoder.
 void registerTextEncoder(TextEncoder encoder)
          Register a TextEncoder for this output object.
 void registerXmlEncoder(XmlEncoder encoder)
          Register an XmlEncoder for this output object.
 void setMajorVersion(int majorVersion)
           
 void setMinorVersion(int minorVersion)
           
 void setMultiObject(boolean newValue)
          If set to true (default = false), then multiple elements may be decoded by calling the decode () methods multiple times while sharing the same context.
 void setProperty(Object name, Object value)
          Define a custom property that will be accessible during this session via getProperty(Object) and XmlEncodeContext.getProperty(Object).
 void setVersion(int majorVersion, int minorVersion)
           
 org.jdom.Element write(Object object)
          Encode an object to a JDOM element.
 org.jdom.Element write(OutputStream stream, Object object)
          Serialize an object to a stream with dbxml header.
 org.jdom.Element write(Writer stream, Object object)
          Serialize an object to a stream with dbxml header.
 org.jdom.Element write(Writer stream, Object object, boolean includeHeader)
          Serialize an object to a stream.
 String writeToString(Object object)
          Shortcut to encode an object into an XML string,
 String writeXml(org.jdom.Element root)
          Write a JDOM element tree to string,
 void writeXml(Writer writer, org.jdom.Element root)
          Write a JDOM element tree to a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlOutput

public XmlOutput()
Constructor for XmlOutput. Use write(Writer, Object) to serialize objects.


XmlOutput

public XmlOutput(String indent,
                 boolean addNewlines)
Constructor for XmlOutput. Use write(Writer, Object) to serialize objects.

Parameters:
indent - The characters to use for indenting.
addNewlines - If true, align tags using newlines.
See Also:
XmlOutput(Format)

XmlOutput

public XmlOutput(org.jdom.output.Format format)
Constructor for XmlOutput. Use write(Writer, Object) to serialize objects.

Parameters:
format - The JDOM formatting options.
Method Detail

setProperty

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


getProperty

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


isMultiObject

public boolean isMultiObject()
See setMultiObject(boolean).


setMultiObject

public void setMultiObject(boolean newValue)
If set to true (default = false), then multiple elements may be decoded by calling the decode () methods multiple times while sharing the same context. Reusing the context means that if an object read by one read () call references objects defined in another call, the links will resolve. This intended for the case where you might wish to represent an object tree in more than one XML document.

IMPORTANT: If this option is enabled, it is up to the client to call finished() when the decode session is complete, otherwise outstanding links may not be resolved.


finished

public void finished()
Signal encoding is finished. Only needed if you enable multi object encoding (@link #setMultiObjectEncode(boolean)}, otherwise this is done automatically after each encode () call.


write

public org.jdom.Element write(OutputStream stream,
                              Object object)
                       throws IOException
Serialize an object to a stream with dbxml header.

Parameters:
stream - The stream to write to.
object - The object to serialize.
Returns:
Element The JDOM element that was written to the stream.
Throws:
IOException - if an error occurs writing to the stream.
See Also:
write(Writer,Object)

write

public org.jdom.Element write(Writer stream,
                              Object object)
                       throws IOException
Serialize an object to a stream with dbxml header.

Parameters:
stream - The stream to write to.
object - The object to serialize.
Returns:
Element The JDOM element that was written to the stream.
Throws:
IOException - if an error occurs writing to the stream.
See Also:
write(Writer,Object,boolean)

write

public org.jdom.Element write(Writer stream,
                              Object object,
                              boolean includeHeader)
                       throws IOException
Serialize an object to a stream. This is a wrapper around write(Object) to encode the object to a JDOM document and writeXml(Writer, Element) to write the document to the stream. The header (if requested) is created with createHeader().

Parameters:
stream - The stream to write to.
object - The object to serialize.
includeHeader - True if the DBXML header should be included.
Returns:
Element The JDOM element that was written to the stream (the XML encoded version of object).
Throws:
IOException - if an error occurs writing to the stream.
See Also:
write(Object)

writeXml

public String writeXml(org.jdom.Element root)
                throws IOException
Write a JDOM element tree to string,

Parameters:
root - The document root.
Throws:
IOException - if an error occurs writing element.
See Also:
writeXml(Writer, Element)

writeXml

public void writeXml(Writer writer,
                     org.jdom.Element root)
              throws IOException
Write a JDOM element tree to a stream.

Parameters:
writer - The stream.
root - The document root.
Throws:
IOException - if an error occurs writing to the stream.
See Also:
write(Writer, Object)

write

public org.jdom.Element write(Object object)
Encode an object to a JDOM element.

Parameters:
object - The object.
Returns:
Element the encoded document.

writeToString

public String writeToString(Object object)
                     throws IOException
Shortcut to encode an object into an XML string,

Throws:
IOException

createHeader

public org.jdom.Element createHeader()
Method createHeaderElement.

Returns:
Element

registerXmlEncoder

public void registerXmlEncoder(XmlEncoder encoder)
Register an XmlEncoder for this output object.

Parameters:
encoder - The encoder.
See Also:
registerGlobalXmlEncoder(XmlEncoder)

registerTextEncoder

public void registerTextEncoder(TextEncoder encoder)
Register a TextEncoder for this output object.

Parameters:
encoder - The encoder.
See Also:
registerGlobalTextEncoder(TextEncoder)

registerGlobalXmlEncoder

public static void registerGlobalXmlEncoder(XmlEncoder encoder)
Register a global XmlEncoder. All XmlOutput instances created after this call will use the registered encoder by default.

Parameters:
encoder - The encoder.
See Also:
registerGlobalXmlEncoder(XmlEncoder)

registerGlobalTextEncoder

public static void registerGlobalTextEncoder(TextEncoder encoder)
Register a global TextEncoder. All XmlOutput instances created after this call will use the registered encoder by default.

Parameters:
encoder - The encoder.
See Also:
registerTextEncoder(TextEncoder)

getMajorVersion

public int getMajorVersion()

getMinorVersion

public int getMinorVersion()

setMajorVersion

public void setMajorVersion(int majorVersion)

setMinorVersion

public void setMinorVersion(int minorVersion)

setVersion

public void setVersion(int majorVersion,
                       int minorVersion)


Copyright © 2008 Commonwealth of Australia