buoy.xml
Class WidgetEncoder

java.lang.Object
  extended by buoy.xml.WidgetEncoder

public class WidgetEncoder
extends java.lang.Object

This class is used for serializing Widgets as XML. This allows user interfaces to be saved in a persistent form, then reconstructed using the WidgetDecoder class.

To use this class, simply call WidgetEncoder.writeObject(), passing it the root Widget to save and an OutputStream to write the XML to. It will save that Widget, along with all other objects referenced by it: child Widgets, event listeners, models, etc.

The serialization is done through the java.beans.XMLEncoder class. It therefore can encode any object which is a bean. An object which is not a bean can also be saved if a PersistenceDelegate has been defined for it. The buoy.xml.delegate package includes PersistenceDelegates for all of the Widgets in the buoy.widget package. If you wish to define delegates for other classes, you can do so by calling WidgetEncoder.setPersistenceDelegate(). If the class in question is an EventSource, the delegate should generally subclass EventSourceDelegate and invoke initializeEventLinks() from its initialize() method so that its event listeners will be properly saved.

It is possible for XML files to contain localized text, where the actual value to use is supplied from a ResourceBundle at decoding time. See WidgetLocalization for details.

Author:
Peter Eastman

Method Summary
static void setPersistenceDelegate(java.lang.Class cls, java.beans.PersistenceDelegate delegate)
          Register a persistence delegate for a class.
static void writeObject(java.lang.Object obj, java.io.OutputStream out)
          Serialize an object hierarchy as XML.
static void writeObject(java.lang.Object obj, java.io.OutputStream out, java.beans.ExceptionListener listener)
          Serialize an object hierarchy as XML.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeObject

public static void writeObject(java.lang.Object obj,
                               java.io.OutputStream out)
Serialize an object hierarchy as XML. The OutputStream will be closed once the XML is written.

Parameters:
obj - the object which forms the root of the hierarchy to save
out - the OutputStream to write the XML to

writeObject

public static void writeObject(java.lang.Object obj,
                               java.io.OutputStream out,
                               java.beans.ExceptionListener listener)
Serialize an object hierarchy as XML. If recoverable errors occur during serialization, the listener will be notified of them. The OutputStream will be closed once the XML is written.

Parameters:
obj - the object which forms the root of the hierarchy to save
out - the OutputStream to write the XML to
listener - the listener to notify of recoverable errors

setPersistenceDelegate

public static void setPersistenceDelegate(java.lang.Class cls,
                                          java.beans.PersistenceDelegate delegate)
Register a persistence delegate for a class.

Parameters:
cls - the class for which to define a PersistenceDelegate
delegate - the delegate to use for saving that class


Written by Peter Eastman.