users@jaxb.java.net

Re: Injecting Code with Plugins

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 20 Mar 2006 07:31:01 -0800

dustin hunter wrote:
> Basically what I want to do is extract an interface for each and every java
> element created by JAXB, and have the implementation implement the
> interface.

Have you tried <jaxb:globalBindings generateValueClass="false" /> ? It
sounds like that's close to what you want to do.

Otherwise, your code would go basically like this:

   for(each ClassOutline co in model) {
     JDefinedClass intf = codeModel._class(...);
     for(each JMethod m in co.ref.methods()) {
       if(you want m to show up in intf) {
         intf.method(...);
       }
     }
   }

As long as you do "JCodeModel._class()" or "JPackage._class()" or some
such in JCodeModel, those classes will be scheduled for the generation.
You need not "hook things up" with outline to get them generated ---
outline is a read-only object model that represents association between
schema and the generated code.

BTW, sounds like this is an interesting plugin. Would you be interested
in hosting this on http://jxab2-commons.dev.java.net/, so that other
people can use it?

> The problem I am having is that we have many different versions of a 3rd
> party schema that we need to work with. They are almost the same, but
> slightly different. I want to be able to write our code such that it does
> not care about the discrepencies between the schemas, and so that it only
> ever works with interfaces and factories.

I see.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com