1
2
3
4
5
6
7 package org.codehaus.groovy.runtime;
8
9 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, Object[] args)
31 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 }
41