users@jaxb.java.net

Re: Adding functionality to JAXB-generated classes

From: Felipe Gaścho <fgaucho_at_gmail.com>
Date: Wed, 16 Jan 2008 20:12:49 +0100

well, just a guess:

include an interface reference in your generate classes, like:

class A {
   Functionality f;
   ........
}

then add a JAXB Event Handler to your unmarshaller process, and in
this handler you instantiate types that implement this interface.. .
and kind of inject them in your objects

that's it.....


On Jan 16, 2008 1:12 AM, Carlos Alegrķa <ccristoo_at_gmail.com> wrote:
> Hi all,
>
> I'm trying to add some functionality to JAXB-generated classes in order to
> integrate them with my project's classes and avoid having two classes that
> refeer to the same thing (the ones that contains the operations, and the
> ones - JAXB generated - that manage the state).
> By reading JAXB documentation and (this) user mail list I found that there
> are three approaches to accomplish this:
>
> - Customize schema compilation to tell ObjectFactory to create a subclass
> of the JAXB generated classes when unmarshalling
> - Customize schema compilation to generate JAXB classes that inherit from a
> class that contains extra functionality
> - Create the classes and add JAXB annotations manually (or use something
> like JAXB Introductions*)
>
> I read that the first one is not a good idea, as the original purpose of the
> attribute "implClass" of the class customization element is to be able to
> add portability between different JAXB implementations. For me, the third
> one is wasting a lot of the benefits of using JAXB, as you'd have to modify
> by hand your classes when the schema changes.
>
> I heard that JAXB 2.0 will provide a better mechanism to solve the problem
> of adding functionality to generated classes, but I have found no
> documentation about this (even in the JAXB specification document).
>
> Does anyone knows if there is a way to do this on JAXB 2.*?
>
> Best regards.
> Carlos Alegria
>
> * JAXB Introductions page:
> http://wiki.jboss.org/wiki/Wiki.jsp?page=JAXBIntroductions
>