public class FluentApiPlugin
extends com.sun.tools.xjc.Plugin
The initial idea is simply to add a "with*" method to the generated class for every "set*" method encountered, with the only functional difference of returning the class instance, instead of void.
Enhancement on 11 June 2006:
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:
Provide fluent setter api for Lists, with support of variable arguments.
This enhancement was suggested by Kenny MacLeod
Enhancement on 11 Oct 2008:
// 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) {
if (values!= null) {
for(OtherType value : values) {
getMyList().add(value);
}
}
return this;
}
Provide fluent setter api for Lists, with support of Collection argument in addition to varargs arguments.
This enhancement was suggested by Alex Wei
| Constructor and Description |
|---|
FluentApiPlugin() |
| Modifier and Type | Method and Description |
|---|---|
String |
getOptionName() |
String |
getUsage() |
boolean |
run(com.sun.tools.xjc.outline.Outline outline,
com.sun.tools.xjc.Options opt,
ErrorHandler errorHandler) |
public String getOptionName()
getOptionName in class com.sun.tools.xjc.Pluginpublic String getUsage()
getUsage in class com.sun.tools.xjc.Pluginpublic boolean run(com.sun.tools.xjc.outline.Outline outline,
com.sun.tools.xjc.Options opt,
ErrorHandler errorHandler)
run in class com.sun.tools.xjc.PluginCopyright © 2017. All rights reserved.