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
<p /><blockquote><p>Work in Progress</p></blockquote>This section I will discuss how builders work and how you can create your own builder. Builders are based on the <a href="http://en.wikipedia.org/wiki/Builder_pattern">builder pattern</a> from the <a href="http://en.wikipedia.org/wiki/Design_Patterns" title="Gamma, Helm, Johnson and Vlissides">GOF design pattern book</a>. It provides a way to build your own <a href="http://en.wikipedia.org/wiki/Domain-specific_programming_language" title="Domain-Specific programming Language">DSL</a> and represents a powerful concept in Groovy. Let me start by saying I am not an expert on the subject of Groovy and this is a good thing for the following reasons. I will take you through a step by step example from a novice point of view. Much of the Groovy documentation is very useful but you have to know a lot to get the most out of the pages. I am starting smae pages to learn more about the power of Groovy and share that undestanding to other novices like me. It is also my hope that this will encourage other novices to take up the challange and write their own pages.<p /> <h2> Things you need to know</h2> <ul> <li>Hierarchic structures - XML data in groovy</li> <li>Closures</li> <li>Method Handlers </li> <li>Properties</li> <li>Meta Programming</li> </ul> <p>Let me also add that here are many examples of creating builders in Groovy, so I will use those examples to keep this presentation short.</p> <p>I find it easier to understand concrete examples so I will start by using a standard builder MarkupBuilder; so let us see it in use:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-parameters="borderStyle=solid|title=MarkupBuilder Example" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6Ym9yZGVyU3R5bGU9c29saWR8dGl0bGU9TWFya3VwQnVpbGRlciBFeGFtcGxlfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>// create a builder, (note: this is not in one of the packages that are automatically imported def builder = new groovy.xml.MarkupBuilder() // construct a builder step(1) // create a simple xml markup builder.stocks { // step (2) stock(symbol: 'JAVA') // step (3-1) stock(symbol: 'MSFT') // step (3-2) stock(symbol: 'IBM' ) } ==== result output =====> <stocks> <stock symbol='JAVA' /> <stock symbol='MSFT' /> <stock symbol='IBM' /> </stocks> </pre></td></tr></table> <p>So what is going on here:</p> <p>step(1) - we just create a <strong>MarkupBuilder</strong> and save in in the variable <em>builder</em>, pretty much standard Groovy</p> <p>step(2) - we invoke the method <strong><em>stocks</em></strong> on <em>builder</em></p> <p>The first thing to note is that <em>builder</em> does not know the method <strong><em>stocks</em></strong> so in java for example the compiler will give an error. In a dynamic language, where these decisions are made at runtime, the builder will <em>missing method exception</em>.</p> <p> WORK IN PROGRESS <br class="atl-forced-newline" /></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