users@jaxb.java.net

Re: Adding functionality to JAXB-generated classes

From: James Bloomfield <jbloomfield_at_mncsoftware.com>
Date: Tue, 19 May 2009 10:21:56 -0700 (PDT)

Hi Benoit,

Did you ever finish your plugin in for the visitor pattern? I have a problem
where I need to convert xml into a binary file and would love to use the
visitor pattern directly on the JAXB generated classes.

Any code or help you be great.

Thanks,
James


benoit.callebaut wrote:
>
> Yes,
> you can use JAXB plugins to inject code in the generated classes.
> a plugin can manipulate the code model of the generated classes and add
> functionalities to them.
> The inject sample plugin does something like that but very limited way.
> It is up to you to expand it.
> I am currently writing a plugin to add the visitor pattern to the
> generated classes.
> Take a look on the jaxb-commons project? You will find sourcecode of
> some plugins
>
> Carlos Alegría a écrit :
>
>> 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
>> <http://wiki.jboss.org/wiki/Wiki.jsp?page=JAXBIntroductions>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>

-- 
View this message in context: http://www.nabble.com/Adding-functionality-to-JAXB-generated-classes-tp14857369p23620757.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.