commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Prohaska <Andreas.Proha...@web.de>
Subject [Betwixt] Using interfaces or abstract classes
Date Wed, 06 Aug 2003 19:20:17 GMT
Hi,

I intend to use betwixt as serialization mechanism in a small 
application I'm currently writing. The problem I have was discussed in 
another thread some months (years?) ago and I was wondering if there is 
a solution in the meantime. Imagine two classes and two interfaces:

1) Interface "Installation" and class "FSInstallation" implementing the 
interface.
2) Interface "Daemon" and class "FSDaemon" implementing the interface.

An Installation contains a Collection of Daemon objects and has the 
neccesary getters "getDaemons()" and setters "addDaemon()". When I use 
the BeanWriter to serialize an FSInstallation I get the following XML 
fragment:

    <installation>
       ... some properties here ...
       <daemons>
          <daemon id="2">
             ... daemon properties ...
          </daemon>
       </daemons>
    </installation>

As you can guess the error happens when I try to deserialize the beans 
again since betwixt is trying to instantiate an object of class Daemon 
when it encounters the "daemon" tag. However, it should instantiate the 
implementing class FSDaemon. I already tried to register the class via

    BeanReader.registerBeanClass("daemon", FSDaemon.class)

but this didn't help.

Is there any way to get around this problem? In my situation it's the 
only choice of design to split between interfaces and classes. And I 
guess other people will have this problem, too. Perhaps including the 
"classname" attribute in the generated XML, causing the digester to 
instantiate the correct class? Or registering the class somewhere else?

Any help is appreciated.

Thanks,

    Andreas




Mime
View raw message