1 16 17 package org.apache.commons.jexl.util.introspection; 18 19 import java.util.Map ; 20 import java.util.Set ; 21 import java.util.HashMap ; 22 import java.util.HashSet ; 23 24 import java.lang.reflect.Method ; 25 26 53 public class IntrospectorBase { 54 58 protected Map classMethodMaps = new HashMap (); 59 60 64 protected Set cachedClassNames = new HashSet (); 65 66 78 public Method getMethod(Class c, String name, Object [] params) throws Exception { 79 if (c == null) { 80 throw new Exception ("Introspector.getMethod(): Class method key was null: " + name); 81 } 82 83 ClassMap classMap = null; 84 85 synchronized (classMethodMaps) { 86 classMap = (ClassMap) classMethodMaps.get(c); 87 88 92 93 if (classMap == null) { 94 if (cachedClassNames.contains(c.getName())) { 95 100 clearCache(); 101 } 102 103 classMap = createClassMap(c); 104 } 105 } 106 107 return classMap.findMethod(name, params); 108 } 109 110 117 protected ClassMap createClassMap(Class c) { 118 ClassMap classMap = new ClassMap(c); 119 classMethodMaps.put(c, classMap); 120 cachedClassNames.add(c.getName()); 121 122 return classMap; 123 } 124 125 128 protected void clearCache() { 129 133 classMethodMaps.clear(); 134 135 138 cachedClassNames = new HashSet (); 139 } 140 } 141 | Popular Tags |