1 6 package org.logicalcobwebs.proxool.proxy; 7 8 import org.logicalcobwebs.proxool.ProxoolException; 9 10 import java.lang.reflect.Method ; 11 import java.util.Map ; 12 import java.util.HashMap ; 13 14 26 public class MethodMapper { 27 28 private Class concreteClass; 29 30 private Map cachedConcreteMethods = new HashMap (); 31 ; 32 36 public MethodMapper(Class concreteClass) { 37 this.concreteClass = concreteClass; 38 } 39 40 49 protected Method getConcreteMethod(Method injectableMethod) throws ProxoolException { 50 Method concreteMethod = (Method ) cachedConcreteMethods.get(injectableMethod); 52 if (concreteMethod == null) { 53 Method [] candidateMethods = concreteClass.getMethods(); 55 for (int i = 0; i < candidateMethods.length; i++) { 56 Method candidateMethod = candidateMethods[i]; 57 if (candidateMethod.getName().equals(injectableMethod.getName()) && 59 candidateMethod.getParameterTypes().length == injectableMethod.getParameterTypes().length && 60 candidateMethod.getReturnType().equals(injectableMethod.getReturnType())) { 61 boolean matches = true; 63 Class [] candidateTypes = candidateMethod.getParameterTypes(); 64 Class [] injectableTypes = injectableMethod.getParameterTypes(); 65 for (int j = 0; j < candidateTypes.length; j++) { 66 if (!candidateTypes[j].equals(injectableTypes[j])) { 67 matches = false; 68 break; 69 } 70 71 } 72 if (matches) { 73 concreteMethod = candidateMethod; 74 break; 75 } 76 } 77 } 78 if (concreteMethod == null) { 80 throw new ProxoolException("Couldn't match injectable method " + injectableMethod + " with any of those " + 81 "found in " + concreteClass.getName()); 82 } 83 cachedConcreteMethods.put(injectableMethod, concreteMethod); 85 } 86 return concreteMethod; 87 } 88 89 94 public void overrideConcreteMethod(Method injectableMethod, Method overridenMethod) { 95 cachedConcreteMethods.put(injectableMethod, overridenMethod); 96 } 97 98 } 99 100 | Popular Tags |