users@jaxb.java.net

Réf. : Re: Generating bound javabeans using xjc

From: Patrick BRUNETON <patrick.bruneton_at_eads.com>
Date: Mon, 24 Oct 2005 09:07:35 +0200

In a plugin I have written for my company, I did something like this.
It's possible to inject/modify code but not always easy because the code
model is mostly in "write once" mode.
For example I do this :

private void augmenterGetSetObjetBD(JDefinedClass classeObjetBD)
{
      for (JMethod m : classeObjetBD.methods())
      {
         if (m.name().startsWith("set"))
         {
            m.body().directStatement("setChanged();");
         }
         ...

For some more complex modifications (e.g. changing return type, modify
annotations, modify method names, etc.) I had to use reflection on
com.sun.codemodel classes.



                                                                                                                                           
                    Kohsuke Kawaguchi
                    <kohsuke.kawaguch Pour : users_at_jaxb.dev.java.net
                    i_at_sun.com> cc :
                                            Objet : Re: Generating bound javabeans using xjc
                    21/10/2005 20:45
                    Veuillez répondre
                    à users
                                                                                                                                           
                                                                                                                                           





Sorry for a delay.

Dmitri Colebatch wrote:
> Hi,
>
> I'd like to generate beans that have PropertyChangeListener support,
> that is have addPropertyChangeListener(PropertyChangeListener
> pcl)/removePropertyChangeListener(PropertyChangeListener pcl) methods.
>
> I'm looking through the source to ImplStructureStrategy which seems to
> be what I need to be hooking into, but I don't see how I can get in to
> fire PropertyChangeEvents.
>
> Surely I'm not the first person to have this requirement? Does anyone
> have any guidance on how to hook into this area?

For plugins to do this, I think I need to open up more of the code
generation process to plugins, for example so that you can inject code
into the setter method. This is also useful for other purposes, such as
injecting code to check the int value against facets, etc.

I'll see what I can do. You are welcome to file an issue to track the
progress of this.

Regarding your PropertyChangeListener, it would be somewhat difficult to
fire an event for a change to List, as it happens outside the knowledge
of JAXB.

--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com