1 16 package net.sf.cglib.beans; 17 18 import java.lang.reflect.InvocationHandler ; 19 import java.lang.reflect.Method ; 20 import java.lang.reflect.Proxy ; 21 import java.util.Map ; 22 23 27 public class BeanMapProxy implements InvocationHandler { 28 private Map map; 29 30 public static Object newInstance(Map map, Class [] interfaces) { 31 return Proxy.newProxyInstance(map.getClass().getClassLoader(), 32 interfaces, 33 new BeanMapProxy(map)); 34 } 35 36 public BeanMapProxy(Map map) { 37 this.map = map; 38 } 39 40 public Object invoke(Object proxy, Method m, Object [] args) throws Throwable { 41 String name = m.getName(); 42 if (name.startsWith("get")) { 43 return map.get(name.substring(3)); 44 } else if (name.startsWith("set")) { 45 map.put(name.substring(3), args[0]); 46 return null; 47 } 48 return null; 49 } 50 } 51 52 | Popular Tags |