users@jaxb.java.net

Re: (JAXB Plugin) Customize the body of a setter method to fire bound properties

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Fri, 12 Jan 2007 10:35:54 -0800

Chris Campbell wrote:
> Thanks, Kohsuke and Jerome. I asked the following on Kohsuke's blog,
> but probably would be better to move the discussion here.
>
> 1) I just tried it with the xjc that comes with JDK 6, and the option
> wasn't recognized (says "unrecognized parameter -Xinject-listener-
> code"):
> % xjc -classpath property-listener-injector-1.0.jar -Xinject-listener-
> code catalog.xsd
>
> However, the plugin works fine if I run it using the xjc that comes
> with JAXB 2.1 RI. So is this plugin dependent on JAXB 2.1? Is there
> a reason why it wouldn't work with the JAXB 2.0 that comes with JDK 6?

JavaSE has a much much higher bar in terms of maintaining the
compatibility. So we chose not to support plugins with JAXB
implementation in JavaSE. If you'd like to use plugins, please download
the JAXB RI from http://jaxb.dev.java.net/.

I probably don't need to rely on JAXB 2.1. I'll check if I can pick a
lesser version.

> 2) (From Mikael Grev...) The property name fired has the first
> character upper case (should be lowercase).

Looks like a bug.

> 3) Why does it only generate "constrained" properties?
> http://java.sun.com/docs/books/tutorial/javabeans/properties/
> constrained.html
>
> These are arguably more complex than the usual "bound" properties:
> http://java.sun.com/docs/books/tutorial/javabeans/properties/bound.html
>
> Even the way the plugin generates "constrained" properties is not
> quite right, as Mikael pointed out already on Kohsuke's blog. For
> true "constrained" support, it would need to follow the steps listed
> on that tutorial page.
>
> Personally, I would prefer that the plugin generate only "bound"
> properties by default. For example:
>
> @XmlTransient
> private final PropertyChangeSupport pcs = new
> PropertyChangeSupport(this);
>
> public String getTitle() {
> return this.title;
> }
>
> public void setTitle(String title) {
> String old = this.title;
> this.title = title;
> this.pcs.firePropertyChange("title", old, title);
> }
>
> Then if the user really wants "constrained" support (usually in
> addition to, but I suppose could be in place of) "bound" support,
> they could specify another argument to get that behavior. For example:
> % xjc -Xinject-bound-properties ...
> % xjc -Xinject-bound-properties -Xinject-constrained-properties ...
> % xjc -Xinject-constrained-properties ...
>
> Jerome or Marcos, any opinions? Would either of you be willing to
> take this on?

I'll wait for Jerome to chime in.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com