1 package org.apache.velocity.util.introspection; 2 3 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 54 public class IntrospectorBase 55 { 56 60 protected Map classMethodMaps = new HashMap (); 61 62 66 protected Set cachedClassNames = new HashSet (); 67 68 79 public Method getMethod(Class c, String name, Object [] params) 80 throws Exception 81 { 82 if (c == null) 83 { 84 throw new Exception ( 85 "Introspector.getMethod(): Class method key was null: " + name ); 86 } 87 88 ClassMap classMap = null; 89 90 synchronized(classMethodMaps) 91 { 92 classMap = (ClassMap)classMethodMaps.get(c); 93 94 99 100 if (classMap == null) 101 { 102 if ( cachedClassNames.contains( c.getName() )) 103 { 104 109 clearCache(); 110 } 111 112 classMap = createClassMap(c); 113 } 114 } 115 116 return classMap.findMethod(name, params); 117 } 118 119 124 protected ClassMap createClassMap(Class c) 125 { 126 ClassMap classMap = new ClassMap( c ); 127 classMethodMaps.put(c, classMap); 128 cachedClassNames.add( c.getName() ); 129 130 return classMap; 131 } 132 133 137 protected void clearCache() 138 { 139 144 classMethodMaps.clear(); 145 146 150 cachedClassNames = new HashSet (); 151 } 152 } 153 | Popular Tags |