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 | 362 | 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 | 359 | Map<String, List<Method>> result = new HashMap<String, List<Method>>( 23 ); |
43 | |
|
44 | 359 | Class<?> c = key.targetClass; |
45 | 1144 | while ( c != null ) |
46 | |
{ |
47 | 9152 | for ( Method method : c.getDeclaredMethods() ) |
48 | |
{ |
49 | |
|
50 | |
|
51 | 8367 | if ( !OgnlRuntime.isMethodCallable( method ) ) |
52 | |
{ |
53 | 99 | continue; |
54 | |
} |
55 | |
|
56 | 8268 | if ( shouldCache( key, method ) ) |
57 | |
{ |
58 | 6425 | List<Method> ml = result.get( method.getName() ); |
59 | |
|
60 | 6425 | if ( ml == null ) |
61 | |
{ |
62 | 5167 | ml = new ArrayList<Method>(); |
63 | 5167 | result.put( method.getName(), ml ); |
64 | |
} |
65 | |
|
66 | 6425 | ml.add( method ); |
67 | |
} |
68 | |
} |
69 | 785 | c = c.getSuperclass(); |
70 | |
} |
71 | 359 | return result; |
72 | |
} |
73 | |
|
74 | |
protected abstract boolean shouldCache( T key, Method method ); |
75 | |
} |