1 package org.apache.commons.ognl.internal.entry;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import org.apache.commons.ognl.OgnlRuntime;
28 import org.apache.commons.ognl.internal.CacheException;
29
30 import java.lang.reflect.Method;
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36 public abstract class MethodCacheEntryFactory<T extends MethodCacheEntry>
37 implements CacheEntryFactory<T, Map<String, List<Method>>>
38 {
39 public Map<String, List<Method>> create( T key )
40 throws CacheException
41 {
42 Map<String, List<Method>> result = new HashMap<String, List<Method>>( 23 );
43
44 Class<?> c = key.targetClass;
45 while ( c != null )
46 {
47 for ( Method method : c.getDeclaredMethods() )
48 {
49
50
51 if ( !OgnlRuntime.isMethodCallable( method ) )
52 {
53 continue;
54 }
55
56 if ( shouldCache( key, method ) )
57 {
58 List<Method> ml = result.get( method.getName() );
59
60 if ( ml == null )
61 {
62 ml = new ArrayList<Method>();
63 result.put( method.getName(), ml );
64 }
65
66 ml.add( method );
67 }
68 }
69 c = c.getSuperclass();
70 }
71 return result;
72 }
73
74 protected abstract boolean shouldCache( T key, Method method );
75 }