001    /*
002     * ConvertedClosure.java created on 12.10.2006
003     *
004     * To change this generated comment go to 
005     * Window>Preferences>Java>Code Generation>Code and Comments
006     */
007    package org.codehaus.groovy.runtime;
008    
009    import java.lang.reflect.Method;
010    import java.util.Map;
011    
012    import groovy.lang.Closure;
013    
014    /**
015     * This class is a general adapter to adapt a map of closures to
016     * any Java interface.
017     * <p>
018     * @author <a href="mailto:blackdrag@gmx.org">Jochen Theodorou</a>
019     */
020    public class ConvertedMap extends ConversionHandler {
021            
022        /**
023         * to create a ConvertedMap object.
024         * @param map the map of closres
025         */
026        protected ConvertedMap(Map closures) {
027            super(closures);
028        }
029        
030        public Object invokeCustom(Object proxy, Method method, Object[] args)
031        throws Throwable {
032            Map m = (Map) getDelegate();
033            Closure cl = (Closure) m.get(method.getName());
034            return cl.call(args);
035        }
036        
037        public String toString() {
038            return DefaultGroovyMethods.toString((Map) getDelegate());
039        }
040    }
041