dev@jaxb.java.net

Re: Plugin to extend another class

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 30 Jan 2007 17:33:05 -0800

Stern, Michael W wrote:
> I was just wondering if it is a possibility to write a plugin to make a
> generated class extend another (non-generated) class.

Sure.

> The main reason
> for wanting to do this, is to allow adding behavior to the generated
> JAXB models. The superclass will contain the business methods & logic,
> the model (sub-class) will contain the attributes. This is my first
> attempt at a plugin, and I have a test one working, and have been
> looking at the _extends() methods on JDefinedClass, but they don't seem
> to give the ability I was hoping for.

Really? For example JAXB RI supports something similar by itself. Look
at BeanGenerator line 209 where we set the base class.


> I am in pursuit of a Rich Domain Model, and am trying to avoid the
> anemic model that using JAXB classes tends to promote. I got the Simple
> regenerator plugin
> <https://jaxb2-commons.dev.java.net/simple-regenerator/> working, but
> would like to to see if there is a way to do this a little more
> elegantly.

Yes.

> Additionally it would be nice to see a little more fine grained control
> over creating interfaces, but that is a topic for another day. If you
> need more information on what I am trying to do, I have a class diagram
> as well.

It would be really nice if you can host your plugin on
http://jaxb2-commons.dev.java.net/

I think other people will find your work useful.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com