KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > runtime > MethodClosure


1 package org.codehaus.groovy.runtime;
2
3 import groovy.lang.Closure;
4 import groovy.lang.MetaClass;
5
6
7 /**
8  * Represents a method on an object using a closure which can be invoked
9  * at any time
10  *
11  * @author <a HREF="mailto:james@coredevelopers.net">James Strachan</a>
12  * @version $Revision: 1.6 $
13  */

14 public class MethodClosure extends Closure {
15
16     private String JavaDoc method;
17     MetaClass metaClass = InvokerHelper.getMetaClass(this);
18     
19     public MethodClosure(Object JavaDoc delegate) {
20         super(delegate);
21     }
22     
23     public MethodClosure(Object JavaDoc owner, String JavaDoc method) {
24         super(owner);
25         this.method = method;
26     }
27     
28     public String JavaDoc getMethod() {
29         return method;
30     }
31
32     public Object JavaDoc call(Object JavaDoc arguments) {
33         return InvokerHelper.invokeMethod(getDelegate(), method, arguments);
34     }
35     
36     public MetaClass getMetaClass() {
37         return metaClass;
38     }
39     
40     public void setMetaClass(MetaClass metaClass) {
41         this.metaClass = metaClass;
42     }
43
44     protected Object JavaDoc doCall(Object JavaDoc arguments) {
45         return InvokerHelper.invokeMethod(getDelegate(), method, arguments);
46     }
47 }
48
Popular Tags