buoy.xml
Class 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.
static void | setPersistenceDelegate(Class cls, PersistenceDelegate delegate) - Register a persistence delegate for a class.
|
static void | writeObject(Object obj, OutputStream out) - Serialize an object hierarchy as XML.
|
static void | writeObject(Object obj, OutputStream out, ExceptionListener listener) - Serialize an object hierarchy as XML.
|
setPersistenceDelegate
public static void setPersistenceDelegate(Class cls,
PersistenceDelegate delegate)
Register a persistence delegate for a class.
cls
- the class for which to define a PersistenceDelegatedelegate
- the delegate to use for saving that class
writeObject
public static void writeObject(Object obj,
OutputStream out)
Serialize an object hierarchy as XML. The OutputStream will be closed once the XML is written.
obj
- the object which forms the root of the hierarchy to saveout
- the OutputStream to write the XML to
writeObject
public static void writeObject(Object obj,
OutputStream out,
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.
obj
- the object which forms the root of the hierarchy to saveout
- the OutputStream to write the XML tolistener
- the listener to notify of recoverable errors
Written by Peter Eastman.