Make a builder Add comment to Wiki View in Wiki Edit Wiki page Printable Version

To create a new builder like a the MarkupBuilder or AntBuilder, you have to implement in java (in groovy later too) a subclass of the groovy.util.BuilderSupport class.

The main methods to be implemented are the following :

  • protected abstract void setParent(Object parent, Object child);
  • protected abstract Object createNode(Object name); // a node without parameter and closure
  • protected abstract Object createNode(Object name, Object value); //a node without parameters, but with closure
  • protected abstract Object createNode(Object name, Map attributes); // a Node without closure but with parameters
  • protected abstract Object createNode(Object name, Map attributes, Object value); //a node with closure and parameters
  • protected Object getName(String methodName)

The BuilderSupport.java class







The NodeBuilder example

To be able to write such a code :





we need :





The MarkupBuilder.java class as second example







 

Search

Results of your search request can come from various sources: the Groovy website itself, the JIRA issues, the API documentation, as well as a few other interesting Groovy-related blogs.

  By  -  pages  -  views  - last modified