users@jaxb.java.net

RE: Re: restricting access to constructors of generated classes

From: <HeruMartinus.Salim_at_infineon.com>
Date: Thu, 23 Nov 2006 10:42:51 +0100

Hi,

How can I create a plugin to change the behavior of the generation of
ObjectFactory?
I haven't found how, because this generation is not done in Plugin
level, but in BeanGenerator level. (as I know)

Thanks.
Regards,
Heru

> -----Original Message-----
> From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
> Sent: Friday, October 06, 2006 6:05 AM
> To: users_at_jaxb.dev.java.net
> Subject: Re: restricting access to constructors of generated classes
>
> Lowell Kirsh wrote:
> > Both of these seem to do the exact same thing. I'm curious,
> if there's
> > a factory, why are the constructors public?
>
> Because it's more convenient and terse if you can just create
> a new instance via "new".
>
> In 1.0, there was only a factory and no public constructor.
> People didn't like that at all.
>
> > My problem is that I want
> > to only call the factory creation methods, and to not call the
> > constructors directly. That way I can sometimes return a
> subclass. But
> > sometimes I forget, and call the constructors directly, which in my
> > case is a bug. So I'd like to prevent myself from shooting
> myself in
> > the foot by making the constructors private. Is there a way
> to set all
> > generated classes to have private constructors?
>
> You should consider writing a plugin. You can either put
> @deprecated on all constructors, and that way you can
> relatively quickly tell when someone in your team makes that mistake.
>
> I believe you can also change constructor access modifiers
> (if you can't, let me know.)
>
> Also, take a look at
> https://jaxb2-commons.dev.java.net/contribute.html
> and consider hosting such a plugin on jaxb2-commons.
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>