users@jaxb.java.net

Re: Implementing the Visitor Pattern

From: Roger Parkinson <roger_at_senanque.co.nz>
Date: Fri, 02 Aug 2013 10:19:37 +1200

  

The general approach is to write a plugin for XJC (XJC is
org.jvnet.jaxb2_commons.xjc.XJC2Task, which generates your java code
from your schema file, but you probably know that)

In the plugin you
use com.sun.codemodel to modify the generated code however you wish,
such as adding methods that implement a visitor pattern if you want.


For a non-maven example you are welcome to look at
http://code.google.com/p/madura-objects/
That is an Eclipse project, and
it also uses ant+ivy. You'll need to run the ant build first to get
everything setup and dependencies downloaded, thereafter pure Eclipse
will work as normal. See the readme for details. You can pull it using
svn, of course.

There are two plugins defined there in package
com.sun.tools.xjc.addon, the second one (ValidatorJAXBInterceptor) is
simpler than the first. You'll find XJC is invoked from the ant script
build-generated.xml.

Regards
Roger
---
 Roger Parkinson
 G+ [1]
Twitter [2] Blog [3] Home Page [4] Fiction [5]
On 02/08/2013 03:10,
pbrown1_at_nycap.rr.com wrote: 
> I want to extend the jaxb generated code
to include support for the
> Visitor pattern. I found a google
implementation, but it appears to be
> a maven project with many
dependencies. I am working in a pure Eclipse
> environment using svn and
dont' want to climb the maven learning curve
> (at least at this time).
> 
> Anybody done this before? I'm not particularly interested in
>
reinventing wheels!
 
Links:
------
[1]
http://gplus.to/RogerParkinson
[2] http://twitter.com/RogerParkinson
[3]
http://mrkimi01.blogspot.com/
[4]
http://sites.google.com/site/rogerparkinson35/
[5]
http://www.smashwords.com/profile/view/RogerParkinson