01: /*
02: * ConvertedClosure.java created on 12.10.2006
03: *
04: * To change this generated comment go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.codehaus.groovy.runtime;
08:
09: import java.lang.reflect.Method;
10: import java.util.Map;
11:
12: import groovy.lang.Closure;
13:
14: /**
15: * This class is a general adapter to adapt a map of closures to
16: * any Java interface.
17: * <p>
18: * @author <a href="mailto:blackdrag@gmx.org">Jochen Theodorou</a>
19: */
20: public class ConvertedMap extends ConversionHandler {
21:
22: /**
23: * to create a ConvertedMap object.
24: * @param map the map of closres
25: */
26: protected ConvertedMap(Map closures) {
27: super (closures);
28: }
29:
30: public Object invokeCustom(Object proxy, Method method,
31: Object[] args) throws Throwable {
32: Map m = (Map) getDelegate();
33: Closure cl = (Closure) m.get(method.getName());
34: return cl.call(args);
35: }
36:
37: public String toString() {
38: return DefaultGroovyMethods.toString((Map) getDelegate());
39: }
40: }
|