Global PersistenceDelegate default

Hi guys,

I have a question concerning the Java XML long time persistence API (Java SE 5). I have some classes for which I need to implement aPersistenceDelegate.

Now I'm wondering if there is some mechanism that makes my persistence delegate kind of default persistence delegate which will be used by allXMLEncoders (per default). I think this would be more convenient than setting the persistence delegate for all my classes explicitly for each XMLEncoder I use by means of java.beans.Encoder.setPersistenceDelegate.

Does anybody have an idea?

[586 byte] By [ProggerFromKupfera] at [2007-11-26 18:41:03]
# 1
Curiously enough that's the way it works. When you set a PersistenceDelegate on one XMLEncoder it is installed into a static table so it will work for all of them. Poor piece of work by Sun but it's working in your favour ...
ejpa at 2007-7-9 6:15:05 > top of Java-index,Core,Core APIs...
# 2
This doesn't seem to be intuitive... but that's really the way it works. I couldn't find a description of the exact behaviour in the API spec, but a glance to their source code finally revealed it.Thank you!
ProggerFromKupfera at 2007-7-9 6:15:05 > top of Java-index,Core,Core APIs...
# 3

Another thing that you can do (which doesn't seem to be documented) is to set a 'persistenceDelegate' attribute in your BeanDescriptor for your class, like this:

DefaultPersistenceDelegate delegate = new DefaultPersistenceDelegate( new String[] {"name", "hostAddress", "serverPath", "modulePath", "sourceBaseDir", "classPool"} );

try {

Introspector.getBeanInfo( YourClass.class ).getBeanDescriptor().setValue( "persistenceDelegate", delegate );

} catch( IntrospectionException e ) {

throw new RuntimeException( e );

}

This will be picked up by XMLEncoder automatically.

jesse_barnuma at 2007-7-9 6:15:05 > top of Java-index,Core,Core APIs...