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
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>In <a class="confluence-link" href="/pages/viewpage.action?pageId=73861" data-linked-resource-id="73861" data-linked-resource-type="page" data-linked-resource-default-alias="MetaClass Redesign (by blackdrag)" data-base-url="http://docs.codehaus.org">MetaClass Redesign (by blackdrag)</a> I tried to show some ideas of how such a redisgn might look like and what the advantages and disadvantages might be.</p> <h2> groovy.lang.MetaClass</h2> <p>In this part I want to show a more detailed version of one idea. that is a implementation based MetaClass is in front and the user can add custom behaviors. This limits the basic MetaClass interface to mere adminisatrative methods</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> package groovy.lang; public interface MetaClass { // MOP void addMOP(MetaClassObjectProtocoll mop); MetaClassObjectProtokoll removeMOP(MetaClassObjectProtokoll mop); // add methods and properties void addMethod(MetaMethod mm); void addProperty(MetaProperty mp); void addConstructor(MetaMethod mc); // listener for MetaClass changes void addMetClassListener(MetaClassListener mcl); void removeMetaClassListener(MetaClassListener mcl); MetaClassListener[] getMetClassListeners(); } </pre></td></tr></table> <p>So the central point is addMOP, which allows to customize the method invocation for example. Besides this there are some methods for mutating the MetaClass (adding properties and such), a standard listener interface that allows to react to additions of properties for example. The implementation of this is not relevant for the user as it is thought as specification. The implementation depends on the Grovy runtime and might differ from other runtimes if there are ever such runtimes.</p> <h2>Usage of groovy.lang.MetaClass</h2> <p>If the user wants to influence themethod invocation process for example, then he has to implement the MetaClassObjectProtokoll interface, which I will show later. In this section I want to show how to create a per instance MetaClass and how to use it.</p> <h4> changing a MetaClass in the registry</h4> <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> //old coderegistry.setMetaClass(theClass,myMetaClass) // new code metaClass = registry.getMetaClass(theClass)metaClass.addBehavior(myMOP) // or in one line registry.getMetaClass(theClass).addMOP(myMOP) </pre></td></tr></table> <p>So the one-line codebecomes a more complex two-line code, unless we decide to change MetaClassRegistry to make that by itself.</p> <h4> creating and changing a per instance MetaClass</h4> <p> The old code was like this:</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> groovyObject.metaClass = myMetaClass </pre></td></tr></table> <p>The new code will look like this:</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> groovyObject.metaClass.addMOP(myMOP) </pre></td></tr></table> <p>So the change here is minimal. The code to create a per instance MetaClass is hidden by the implementation and might differ. This of course means that the class GroovyObjectSupport, which is part of groovy.lang has implementation knowledge inside. So a implementator must change this class to his version of the runtime.</p> <h2> Using the Listener to MetaClass changes</h2> <p><span style="color: rgb(255,0,0);">(add interface)</span></p> <p> ...</p> <h2> Consequences</h2>
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