users@jaxb.java.net

Adding functionality to JAXB-generated classes

From: Carlos Alegría <ccristoo_at_gmail.com>
Date: Tue, 15 Jan 2008 18:12:13 -0600

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