users@jaxb.java.net

Re: [Issue 115] Supports Method Chaining/ FluentAPI

From: Kohsuke Kawaguchi <kohsuke.kawaguchi_at_sun.com>
Date: Thu, 26 Jan 2006 16:06:53 -0800

Hanson Char wrote:
> Hi,
>
> I am trying to write a xjc plugin to support a fluent api in addition to the
> default (JavaBean) setter methods.

Yes!!! Welcome on board!

> The initial idea is simply to add a "with*" method to the generated class (via
> JDefinedClass.method) for every "set*" method encountered, with the only
> difference of returning the class instance, instead of void.

Ah, I see. Yeah, that's easy to implement.

What I had in my mind was for you to replace "FieldRendererFactory" to
completely take over the field generation process. We can refactor the
current field generators so that you can extend them and tweak them so
that they return the right type.

> In creating a "with*" method, I am trying to clone across the modifiers of the
> corresponding setter method. These modifiers can be accessed via
> JMethod.getMods() which is of type JMods. However, although JMods has an
> internal "mods" int field, there seems no API to gain access to it. (I don't
> want to resort to reflection to break the API.) Meanwhile, the required "mods"
> parameter of JDefinedClass.method is an int.
>
> Any chance this can be changed ?
> ie.
>
> 1. Either JDefinedClass.method should allow passing in a JMods instead of int
> for the modifiers; or
> 2. JMods should provide a getter method to its internal "mods".
>
> Does this make sense ?

Sure. Just committed int JMods.getValue()

>
> Hanson


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com