XMLEncoder & DefaultPersistenceDelegate  
Author Message
lasandell





PostPosted: 2005-11-6 1:37:00 Top

java-programmer, XMLEncoder & DefaultPersistenceDelegate I am trying to encode EventObject's as XML using XMLEncoder. As
subclasses of EventObject/AWTEvent are generally NOT java beans (they
do not provide a nullary constructor), I have to provide an instance of
DefaultPersistenceDelegate which specifies which properties are set by
the constructor. I tried to this with ActionEvent as follows:

encoder.setPersistenceDelegate( ActionEvent.class, new
DefaultPersistenceDelegate(
new String[] {"source", "ID", "actionCommand", "modifiers",
"when"} )
);

Unfortunately, when I call encoder.writeObject with an argument of type
ActionEvent, I get the following exception:

java.lang.NoSuchMethodException: <unbound>=Class.new(null, Integer,
"1", Integer, Long);
Continuing ...
java.lang.Exception: XMLEncoder: discarding statement
XMLEncoder.writeObject(ActionEvent);
Continuing ...

It is apparently unable to find the constructor due to the first
argument being null. However, "source" in my ActionEvent happens to not
be null. "source" is a property from EventObject rather than
ActionEvent, and I think this may be part of the problem. I have read
another post that says XMLEncoder has problems with superclass
properties.

Anybody have any ideas?

 
lasandell





PostPosted: 2005-11-6 1:49:00 Top

java-programmer >> XMLEncoder & DefaultPersistenceDelegate Oh one thing I forgot to mention... "source" is a transient property. I
don't know if XMLEncoder pays attention to the "transient" keyword,
however.

 
lasandell





PostPosted: 2005-11-6 1:55:00 Top

java-programmer >> XMLEncoder & DefaultPersistenceDelegate OK this is was horrible case of overconfidence.... it turns out that
getSource() is indeed returning null. I'm not sure why though, the
ActionEvent was generated by a Swing button; it should have that as its
source!