1 package dynaop.util; 2 3 import java.io.IOException ; 4 import java.io.Serializable ; 5 import java.lang.reflect.Method ; 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 import java.util.Map ; 9 10 15 public class MethodHandle implements Serializable { 16 17 static long serialVersionUID = 0; 18 19 Class declaringClass; 20 String name; 21 Class [] parameterTypes; 22 23 public MethodHandle(Method method) { 24 this.declaringClass = method.getDeclaringClass(); 25 this.name = method.getName(); 26 this.parameterTypes = method.getParameterTypes(); 27 } 28 29 public Method getMethod() throws NoSuchMethodException { 30 return declaringClass.getDeclaredMethod(this.name, 31 this.parameterTypes); 32 } 33 34 public static Map handleMethodKeys(Map map) { 35 Map handled = new HashMap (); 36 for (Iterator i = map.entrySet().iterator(); i.hasNext();) { 37 Map.Entry entry = (Map.Entry ) i.next(); 38 handled.put( 39 new MethodHandle((Method ) entry.getKey()), 40 entry.getValue() 41 ); 42 } 43 return handled; 44 } 45 46 public static Map unhandleMethodKeys(Map map) throws IOException { 47 try { 48 Map unhandled = new HashMap (); 49 for (Iterator i = map.entrySet().iterator(); i.hasNext();) { 50 Map.Entry entry = (Map.Entry ) i.next(); 51 unhandled.put( 52 ((MethodHandle) entry.getKey()).getMethod(), 53 entry.getValue() 54 ); 55 } 56 return unhandled; 57 } 58 catch (NoSuchMethodException e) { 59 throw NestedException.wrap(e); 60 } 61 } 62 } 63 | Popular Tags |