Any other thoughts ?
H
---------- Forwarded message ----------
From: Hanson Char <hanson.char_at_gmail.com>
Date: Jun 9, 2006 7:21 AM
Subject: Re: JAXB2 fluent-api improvement
To: Kenny MacLeod <kennym_at_kizoom.com>
Hi Kenny,
Interesting thought. Admittedly I haven't touched jaxb for a while, so I'd
like to clarify more with you.
For the getMyList() method, does XJC currently generate a respective
MyClass withMyList(List<OtherType> list);
method already ?
I would think so, and that means you want to overload it with a vararg
parameter list. Hmmm...if that's the case I don't think the overloading is
a good idea. I prefer to follow the JavaBean pattern of:
// add to the List<OtherType>
void addOtherType(OtherType otherType);
with an affluent equivalent API of something like:
MyClass appendOtherType(OtherType otherType);
What do you think ?
H
On 6/9/06, Kenny MacLeod < kennym_at_kizoom.com> wrote:
>
> Hi Hanson,
>
> You've already made my life easier with the fluent-api plugin for JAXB2
> XJC, and I have a suggestion
> for a small improvement for it.
>
> By default, XJC represents Lists by generating a getter method, but no
> setter. This is impossible
> to chain with fluent-api. How about the plugin generates a withXYZ()
> method for List properties,
> taking as it's parameters a vararg list. For example:
>
> public class MyClass {
> private List<OtherType> myList;
>
> // This method is generated by vanilla XJC
> public List<OtherType> getMyList() {
> if (myList == null) {
> myList = new ArrayList<OtherType>();
> }
> return myList;
> }
>
> // This would be generated by fluent-api
> public MyClass withMyList(OtherType... values) {
> for(OtherType value : values) {
> getMyList().add(value);
> }
> return this;
> }
> }
>
>
> How does this strike you?
>
> cheers
> kenny
>