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 method;
17 MetaClass metaClass = InvokerHelper.getMetaClass(this);
18
19 public MethodClosure(Object delegate) {
20 super(delegate);
21 }
22
23 public MethodClosure(Object owner, String method) {
24 super(owner);
25 this.method = method;
26 }
27
28 public String getMethod() {
29 return method;
30 }
31
32 public Object call(Object 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 doCall(Object arguments) {
45 return InvokerHelper.invokeMethod(getDelegate(), method, arguments);
46 }
47 }