I had the same problem. I haven't followed the newer version of JAXB, but
in previous version I concluded that JAXB is good only for hidding the
parsing involved using SAX or DOM.
If you want to add business logic to the JAXB generated classes, you will
have a hard time.
In my opinion, the best is to use JAXB just as an intermediary step to
copy the data from the XML to objects doing the business logic.
Unless something have change with the lastest implementation you have two
options:
a) Wrap the JAXB object with your own classes.
b) Use JAXB objects only to read /write to XML. Transfer the data from
your objects to/from JAXB objects. (In other words, never keep the JAXB
objects)
I prefer option (b).
XML ---> JAXB objects ---> Business logic objects (beans)
There seems to be other binding tools, like Castor that are supposed to
generate beans...but I never tried it.
<stuart.d.davies_at_bt.com> wrote on 03/23/2005 10:41:12 AM:
> I am very impressed with JAXB and after a small amount of effort
> have been able to implement a complex application. As with all these
> things, there comes a point where that small detail causes big
> problems. I am at that point!
> I have created a Sub Class that requires certain values to be
> derived by the implementation. This derived value is read millions
> of times so I would like to derive it only when the dependencies change.
>
> For example in MySubClass of MyClassImpl, A is derived from X
and Y:
> My first solution was to override setX() and setY() methods
> in MySubClass and derive A within the setters.
> The problem is that during unmarshalling the setters are not
> used. The properties are set directly.
> My second solution was to (in addition to my first solution)
> derive A from X and Y when all values of MySubClass have been set.
> Conceptually at the endElement event.
> The problem is that there do not appear to be any life cycle
> events exposed that I can trap. There is no startedUnMarshal,
> endedUnmarshal etc.
> My third solution would be to add listeners to the bean
> managed bindings for bound and constrained properties but these do
> not appear to be implemented.
> My fourth solution is to use a series of flags but I dislike
> this for it's complexity and poor design.
> Could you please recommend a solution.
> Regards
> Stuart D Davies
> BT Exact
> Phone +44 117 3024552