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: Wed, 10 Jan 2007 09:36:09 -0800

Marcos wrote:
> Hi all,
>
> I'm trying to write a plugin based on the one developed by Mr.
> Jerome Dochez, found at.:
> http://fisheye5.cenqua.com/browse/glassfish/admin-core/xjc-plugin/src/com/sun/tools/xjc/addon/property_listener_injector/PluginImpl.java?r1=1.1&r2=1.1.2.1

We are just talking about moving this to jaxb2-commons.

> JAXB's binding compiler generate setter methods for all elements found
> in the .xsd file
> but I would like to replace some parts to suit my needs .... as follows.:
>
> Before.: (Without the plugin)
>
> /**
> * Sets the value of the returnCode property.
> *
> * @param value
> * allowed object is
> * {_at_link String }
> *
> */
> public void setReturnCode(String value) {
> this.returnCode = value;
> }
>
> After.: (Using the plugin)
>
> /* PropertyChangeSupport inserted by my own plugin.*/
> private PropertyChangeSupport changes = new PropertyChangeSupport(this);
>
> /**
> * Sets the value of the returnCode property.
> *
> * @param value
> * allowed object is
> * {_at_link String }
> *
> */
> public void setReturnCode(String value) {
> String oldReturnCode = this.returnCode; // This must be
> inserted by my plugin
> this.returnCode = value; // I'm not
> sure if I can invoke the default implementation of JAXB to retrieve this
> line of code ...
> changes.firePropertyChange ("returnCode", oldReturnCode,
> returnCode); // This must be inserted by my plugin
> }
>
> I know that each plugin has 02 interesting hook methods.:
> onActivated (Options opt)
> run (Outline model, Options opt, ErrorHandler)
>
> How can I use these methods and JAXB RI API to inject the piece of code
> that I need ?

It really depends on what kind of code you want to inject. Why don't you
start by looking at Jerome's code and modify it to fit your needs?

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com