dev@jaxb.java.net

RE: Plugin to extend another class

From: Stern, Michael W <MSTERN_at_amfam.com>
Date: Wed, 31 Jan 2007 12:58:57 -0600

Ok, I have figured out how to use the _extends(). I am able to produce
the results I desired. However, I am still facing a challenge in
externalizing the configuration. Currently my PluginImpl just hardcoded
some 'if' logic to set the _extends() to a hardcoded class definition.
I believe the plug-in should allow for a more dynamic usage.
 
Ideally I would like to use my existing xpath notation in an external
binding (.xjb) file, to set the option for a given complex type. If
that is not feasible, I would at least like to use the external binding
file to configure my plug-in manually. Can you please provide some
examples of how to do the external configuration, and specifically how
the pattern matching is used to trigger a plug-in customization?
 
I would be more than willing to contribute my plug-in to the commons
project.
 
Additionally, the collection-setter-injector.jar is missing from the
commons page
(https://jaxb2-commons.dev.java.net/collection-setter-injector/). I
would find this plug-in very useful, and was hoping it could get hosted
along with the existing usage guide.
 
Regards,
~Mike
 

  _____

ate: Tue, 30 Jan 2007 17:33:05 -0800
From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Content-Type: multipart/signed;
protocol="application/x-pkcs7-signature"; micalg=sha1;
boundary="------------ms020700030306050306060907"
Subject: Plugin to extend another class
 

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/
<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/ <http://jaxb2-commons.dev.java.net/>
 
I think other people will find your work useful.
 

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com
<mailto:kohsuke.kawaguchi_at_sun.com>