Skip to main content
Last updated March 29, 2011 23:09, by elygre
Feedicon  

fluent_api

The FluentApi plugin provides Method Chaining for bean setters, basically what Martin Fowler refers to as FluentInterface.

Using standard javabeans setters, you would use this:

   USAddress address = new USAddress();
   address.setName( name );
   address.setStreet( street );
   address.setCity( city );
   address.setState( state );
   address.setZip( new BigDecimal( zip ) );


With the FluentApi plugin, you may also use this:

   USAddress address = new USAddress()
 			.withName(name)
 			.withStreet(street)
 			.withCity(city)
 			.withState(state)
 			.withZip(new BigDecimal(zip));


Usage

Sample ant build.xml:

 <taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
    <classpath>
       <pathelement path="/path/to/jaxb-xjc.jar"/>
       <pathelement path="/path/to/jaxb-fluent-api-2.2.jar" />
    </classpath>
 </taskdef> 
 <xjc>
    <arg value="-Xfluent-api" />
     ...
 </xjc>

Getting the plugin

The plugin is available in the central Maven repository, under http://repo2.maven.org/maven2/org/jvnet/jaxb2_commons/jaxb2-fluent-api/.

 
 
Close
loading
Please Confirm
Close