Home > Archive > Java Beans > November 2005 > XMLEncoder & DefaultPersistenceDelegate
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
XMLEncoder & DefaultPersistenceDelegate
|
|
| lasandell@gmail.com 2005-11-07, 9:59 pm |
| 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@gmail.com 2005-11-07, 9:59 pm |
| 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@gmail.com 2005-11-07, 9:59 pm |
| 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!
|
|
|
|
|