Java, Beans, XML and serialization.

Hello, i'd like to have some answers to thoses questions:

Im coding a programme with "graphs" inside JInternalFrames and i would like to save them and what is inside (panels, with panels inside and dnd listeners and my lord, a lot of things indeed).

Can i just use XMLEncoder/XMLDecoder to read/save those Graphs?

It seems that i can save basic components:

encoder.writeObject(new JButton("segsg"));

works, but

encoder.writeObject(t);

where t (Try) is something that extends a JButton doesnt work and i get:

java.lang.InstantiationException: ariane.ui.Workspace$Try

Continuing ...

java.lang.Exception: discarding statement XMLEncoder0.writeObject(Workspace$Try0);

Cant XMLEncoder save nothing but basic JButtons or JFrames?

[812 byte] By [Xuelynom] at [2007-9-26 2:37:18]
# 1

Is ariane.ui.Workspace$Try your class?

Under new long-term persistence model using XML, the definition of "bean" is widened (I think..)

XMLEncoder/Decoder treat all classes, which need to be saved in XML, like a JavaBeans component. They do the followings:

1) try to construct an object using a null-constructor.

2) try to find get/set methods for non-transient fields (properties).

These are usual requirements for JavaBeans but not for a general class.

If you want to save (serialize) your class, which might contain lots of classes/objects, you have to make sure that all object/classes, which need to be saved, provide "null-constructor" and get/set methods for all fields, which need to be saved.

I hope this helps.

Masa

TakatsukaM at 2007-6-29 10:06:23 > top of Java-index,Desktop,Developing for the Desktop...
# 2

If I recall, the ...$Try means it is an inner class. Its not a public class and therefore not a java bean. The encoder cannot save inner classes. This is particulary true of the common way that Borlands JBuilder adds actionListeners for events to components. It makes lots of inner classes. The new static EventHandler.create( ... ) method was added to JDK1.4 to make it easier to use long term persistence with event handlers. See the java.beans.EventHandler documentation.

chavener at 2007-6-29 10:06:23 > top of Java-index,Desktop,Developing for the Desktop...
# 3
Yes that would be an inner class.Encoder/XMLEncoder can save inner classes, they may have to be public static however.
NicholasTDaley at 2007-6-29 10:06:23 > top of Java-index,Desktop,Developing for the Desktop...