001 package org.codehaus.groovy.runtime; 002 003 import groovy.lang.Closure; 004 import groovy.lang.MetaClass; 005 006 007 /** 008 * Represents a method on an object using a closure which can be invoked 009 * at any time 010 * 011 * @author <a href="mailto:james@coredevelopers.net">James Strachan</a> 012 * @version $Revision: 1.6 $ 013 */ 014 public class MethodClosure extends Closure { 015 016 private String method; 017 MetaClass metaClass = InvokerHelper.getMetaClass(this); 018 019 public MethodClosure(Object delegate) { 020 super(delegate); 021 } 022 023 public MethodClosure(Object owner, String method) { 024 super(owner); 025 this.method = method; 026 } 027 028 public String getMethod() { 029 return method; 030 } 031 032 public Object call(Object arguments) { 033 return InvokerHelper.invokeMethod(getDelegate(), method, arguments); 034 } 035 036 public MetaClass getMetaClass() { 037 return metaClass; 038 } 039 040 public void setMetaClass(MetaClass metaClass) { 041 this.metaClass = metaClass; 042 } 043 044 protected Object doCall(Object arguments) { 045 return InvokerHelper.invokeMethod(getDelegate(), method, arguments); 046 } 047 }