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><table class="wysiwyg-macro" data-macro-name="excerpt" data-macro-parameters="atlassian-macro-output-type=BLOCK" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2V4Y2VycHQ6YXRsYXNzaWFuLW1hY3JvLW91dHB1dC10eXBlPUJMT0NLfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="RICH_TEXT"><tr><td class="wysiwyg-macro-body"><p>Proxy-o-Matic lets you create dynamic proxies fast and in an homogeneous way</p></td></tr></table></p> <h2>Contribution Overview</h2> <p>Proxy-o-Matic lets you create dynamic proxies fast and in an homogeneous way. Groovy has the option to create proxy implementations of interfaces, abstract classes and even concrete classes based on closures and maps. You can see them as a poor man's version of anonymous inner classes, but they are <strong>not an exact replacement</strong> as you can't qualify method calls with <strong>this</strong> nor <strong>super</strong>.</p> <p>Proxies created with Proxy-o-Matic also suffer from the this/super problem but they add a couple of features that the standard proxy creation mechanism doesn't offer:</p> <ul> <li>ability to define overloaded methods</li> <li>ability to call its own methods from within</li> <li>ability to proxy more than 1 interface at a time</li> <li>ability to proxy from Expandos as well</li> </ul> <p>Here are a couple of examples that show how to use Proxy-o-Matic</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> import static org.kordamp.groovy.util.ProxyOMatic.proxy interface Foo { String foo() } interface Bar { String bar() } interface FooBar extends Foo, Bar { String foobar() } def f = proxy( Foo ) { foo { -> "Foo" } } assert f instanceof Foo assert f.foo() == "Foo" def fb = proxy( FooBar ) { foo { -> "Foo" } bar { -> "Bar" } foobar { -> foo() + bar() } } assert fb instanceof FooBar assert fb.foo() == "Foo" assert fb.bar() == "Bar" assert fb.foobar() == "FooBar" interface Fooz extends Foo { String foo( String n ) } def fz = proxy( Fooz ) { foo { -> "Foo" } foo { String n -> "Foo$n".toString() } } assert fz instanceof Fooz assert fz.foo() == "Foo" assert fz.foo("Groovy") == "FooGroovy" def bf = proxy( Bar, [Foo] ) { foo { -> "Foo" } bar { -> "Bar" } } assert bf instanceof Bar assert bf instanceof Foo assert bf.foo() == "Foo" assert bf.bar() == "Bar" </pre></td></tr></table> <p>Credit must be given when credit is due, in this case Proxy-o-Matic emerged from an idea Alex Tkachman pitched at the Groovy-dev mailing list, thanks Alex for the marvelous idea of a Proxy builder DSL.</p> <h3>Team Members</h3> <p>Andres Almiray [aalmiray at users dot sourceforge dot net]</p> <h2>Download</h2> <p><a href="http://docs.codehaus.org/download/attachments/89063427/proxyomatic-0.5.jar">proxyomatic-0.5.jar</a><br /> <a href="http://svn.codehaus.org/groovy-contrib/proxyomatic">source</a></p> <h3>Installing</h3> <p>Just drop proxyomatic-<version>.jar into $GROOVY_HOME/lib or ~/.groovy/lib and your done.</p> <h3>Pre-requisites</h3> <p>Have the latest stable version of Groovy installed, that's all baby!</p> <h2>Documentation</h2> <p>Using Proxy-o-Matic is pretty straight forward: call any of ProxyOMatic's proxy() methods. To achieve a DSL like usage remember to import statically <code>ProxyOMatic.proxy</code>. Proxy-o-Matic can only create proxies from interfaces for the time being, abstract/concrete classes will be supported in a following version. These are the method signatures you would need to work with</p> <ul> <li>proxy( Class type, source )</li> <li>proxy( Class type, List<Class>, source )</li> <li>proxy( Class type, Class[], source )</li> </ul> <p>where source can be any of [Closure, Map, Expando]</p> <p>Another thing to consider is that given the nature of closures in Groovy the following would be treated as equivalent definitions:</p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> interface Baz { String baz( Object b ) } def b = proxy( Baz ) { baz { "BAZ" } baz { String n -> n } } assert b.baz("gotcha") == "gotcha" </pre></td></tr></table> <p>So please avoid using the default parameter and always qualify the number of parameters a closure must have.</p> <h3>Contributing</h3> <p>Please contact the team members by e-mail.</p> <h2>Community</h2> <h3>Mailing List(s)</h3> <p><a href="http://groovy.codehaus.org/Mailing+Lists">http://groovy.codehaus.org/Mailing+Lists</a></p> <h3>Issue tracker</h3> <p><a href="http://jira.codehaus.org/secure/BrowseProject.jspa?id=10242">http://jira.codehaus.org/secure/BrowseProject.jspa?id=10242</a></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