Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h3>FactoryBuilderSupport</h3> <p><a href="http://groovy.codehaus.org/Swing+Builder">SwingBuilder</a> is one of the most used Groovy builders. It follows the standard structure of BuilderSupport but uses the concept of factories to build each node. Seeing that the concept was useful enough for other builders the basic implementation was taken out of SwingBuilder and FactoryBuilderSupport was born (and SwingBuilder was retrofitted of course). <a href="http://docs.codehaus.org/display/GROOVY/How+Builders+Work" title="A beginer's perspective">How Builders Work</a></p> <p>The <strong>Factory</strong> interface is the basic building block, the builder will call the factory's methods at specific points during node building, let's see them in their invocation order:</p> <ul> <li><strong>Object newInstance( FactoryBuilderSupport builder, Object name, Object value, Map attributes ) throws InstantiationException, IllegalAccessException</strong><br /> Responsible for creating the object that responds to the node 'name' and its called during builder.createNode</li> <li><strong>boolean onHandleNodeAttributes( FactoryBuilderSupport builder, Object node, Map attributes )</strong><br /> Gives the factory the ability to process the attributes as it may see fit with the option of stopping the builder to process them itself (by returning true).</li> <li><strong>void setParent( FactoryBuilderSupport builder, Object parent, Object child )</strong><br /> <strong>void setChild( FactoryBuilderSupport builder, Object parent, Object child )</strong><br /> allows the factory to setup parent/child relationships.</li> <li><strong>boolean isLeaf()</strong><br /> Lets the builder know if the node allows for further nodes to be nested on the current node.</li> <li><strong>void onNodeCompleted( FactoryBuilderSupport builder, Object parent, Object node )</strong><br /> Is the last method called from the factories perspective, it will let you handle any cleanup the node may require.</li> </ul> <p>But that's not everything FactoryBuilderSupport has to offer. The factories may require contextual information on the current node being built to do its work, onNodeCompleted may require information that it is only available when newInstance is invoked, or newInstance may need to inspect the parent to decide what is the best way to create the node, just to mention a few scenarios, that's why FactoryBuilderSupport enables the following helping methods:</p> <table class="confluenceTable"><tbody> <tr> <th class="confluenceTh"><p> Method </p></th> <th class="confluenceTh"><p> Description </p></th> </tr> <tr> <td class="confluenceTd"><p> Map getContext() </p></td> <td class="confluenceTd"><p> returns the context of the current node* </p></td> </tr> <tr> <td class="confluenceTd"><p> Map getParentContext() </p></td> <td class="confluenceTd"><p> returns the context of the parent of the current node** </p></td> </tr> <tr> <td class="confluenceTd"><p> Factory getCurrentFactory() </p></td> <td class="confluenceTd"><p> returns the factory that built the current node </p></td> </tr> <tr> <td class="confluenceTd"><p> Factory getParentFactory() </p></td> <td class="confluenceTd"><p> returns the factory of the parent of the current node (if any) </p></td> </tr> <tr> <td class="confluenceTd"><p> Object getParentNode() </p></td> <td class="confluenceTd"><p> returns the parent of the current node (if any)** </p></td> </tr> <tr> <td class="confluenceTd"><p> Object getCurrent() </p></td> <td class="confluenceTd"><p> returns the current node* </p></td> </tr> </tbody></table> <p><strong>* Note:</strong> In the newInstance(...) method, since the "current" node has not yet been created, getCurrent() and getContext() will return the parent node or parent context of the node that is currently being constructed.</p> <p><strong>** Note:</strong> In the newInstance(...) method, since the "current" node has not yet been created, getParentNode() and getParentContext() will return the grandparent node or grandparent context of the node that is currently being constructed.</p> <p>The builder is marked as abstract so you are required to create a subclass for your own builders, despite that it doesn't enforce the implementation of any method at all. There are a couple of protected methods though, that when overwritten will give you more control over the builder's internal workings:</p> <ul> <li><strong>Factory resolveFactory( Object name, Map attributes, Object value )</strong><br /> Usually what you would like in a subclass of FactoryBuilderSupport is a <strong>1 to 1</strong> relation on node names to factories, but for those cases where you would like <strong>n to 1</strong> you can override this method and plug in your custom selection mechanism.</li> <li><strong>void preInstantiate( Object name, Map attributes, Object value )</strong><br /> <strong>void postInstantiate( Object name, Map attributes, Object node )</strong><br /> <strong>void handleNodeAttributes( Object node, Map attributes )</strong><br /> <strong>Object postNodeCompletion( Object parent, Object node )</strong><br /> These methods are called during the lifecycle of a node, you can override them at any time but there is also a way to extend the behavior associated with those calls without overwriting the methods: you may register a closure, in fact as many as you like, to hook your own logic. The closures will be called from last to first as they were registered.</li> </ul> <p><strong>TODO</strong> document build() methods</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced