protected XmlEncoder getEncoder(boolean forRead) {...}method. If you extend the IntegratedDataViewer class you could override this method to initialize the XmlEncoder differently.
If you create new classes that will be persisted there are some conventions your class needs to follow.
See an example bundle file here: example.xidv
public void set<Parameter Name>(type param) public type get<Parameter Name>()
public interface XmlDelegate { /** * Create the xml element for the given object. * * @param encoder The XmlEncoder that is calling this method. * @param object The Object to encode. * @return The xml element that defines the given object. */ public Element createElement(XmlEncoder encoder, Object object); /** * Create the Object defined by the given xml element. * @param encoder The XmlEncoder that is calling this method. * @param element The xml that defines the object. * @return The Object defined by the xml. */ public Object createObject(XmlEncoder encoder, Element element); }Most of the uses of this interface are derived from the XmlDelegateImpl which provides a default createObject method. The delegates overwrite createElement typically by putting on a constructor tag. For example, here we have a delegate that handles the persistence of Color objects:
XmlDelegate xmlDelegate = new XmlDelegateImpl() { public Element createElement(XmlEncoder e, Object o) { Color color = (Color) o; List args = Misc.newList(new Integer(color.getRed()), new Integer(color.getGreen()), new Integer(color.getBlue())); List types = Misc.newList(Integer.TYPE, Integer.TYPE, Integer.TYPE); return e.createObjectConstructorElement(o, args, types); } });The utility method
XmlEncoder.createObjectConstructorElement(Object o, List args, List types);creates a constructor tag e.g.:
To add a delegate to an XmlEncoder call:<object class="java.awt.Color"> <constructor> <int>0</int> <int>0</int> <int>0</int> </constructor> </object>
XmlEncoder.addDelegateForClass(Class theClass, XmlDelegate xmlDelegate);The XmlEncoder that the IDV uses is initialized with its own addDefaultDelegates() and with the ucar.visad.VisADPersistence.init(XmlEncoder encoder) method.
Right now there is now way to add delegates through a plugin.
public interface XmlPersistable { /** * Create the xml representation of the object. * * @param encoder The encoder. * @return The xml representation. */ public Element createElement(XmlEncoder encoder); /** * Initialize this object from the given xml element. * @param encoder The encoder. * @param element The xml element representing this object. * @return Return true if it is ok to do the default processing for this node. */ public boolean initFromXml(XmlEncoder encoder, Element element); }In this case it still needs a parameter-less constructor but it will handle its own persistence.