1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.util; |
18 | |
|
19 | |
import java.lang.reflect.Field; |
20 | |
import java.lang.reflect.Modifier; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class JSTLConstants extends HashMap { |
30 | |
|
31 | |
private static final long serialVersionUID = 6701136401021219281L; |
32 | 0 | private boolean initialised = false; |
33 | |
|
34 | 0 | public JSTLConstants() { |
35 | 0 | publishFields(this, this.getClass()); |
36 | 0 | initialised = true; |
37 | 0 | } |
38 | |
|
39 | 0 | public JSTLConstants(Class constantsClass) { |
40 | 0 | publishFields(this, constantsClass); |
41 | 0 | initialised = true; |
42 | 0 | } |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
protected void publishFields(Map constantMap, Class c) { |
51 | 0 | Field[] fields = c.getDeclaredFields(); |
52 | 0 | for (Field field : fields) { |
53 | 0 | int modifier = field.getModifiers(); |
54 | |
|
55 | |
|
56 | 0 | if (Modifier.isStatic(modifier) && Modifier.isFinal(modifier) && !Modifier.isPrivate(modifier)) { |
57 | |
try { |
58 | 0 | String fieldName = field.getName(); |
59 | |
|
60 | 0 | constantMap.put(fieldName, field.get(null)); |
61 | 0 | } catch (IllegalAccessException e) {} |
62 | |
} |
63 | |
} |
64 | |
|
65 | |
|
66 | 0 | publishMemberClassFields(constantMap, c); |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
protected void publishMemberClassFields(Map constantMap, Class c) { |
77 | 0 | Class[] memberClasses = c.getClasses(); |
78 | |
|
79 | 0 | for (Class memberClass : memberClasses) { |
80 | 0 | if (!memberClass.isAnonymousClass()) { |
81 | 0 | String memberPrefix = memberClass.getSimpleName(); |
82 | |
|
83 | 0 | Map subclassMap = new HashMap(); |
84 | 0 | publishFields(subclassMap, memberClass); |
85 | 0 | constantMap.put(memberClass.getSimpleName(), subclassMap); |
86 | |
} |
87 | |
} |
88 | 0 | } |
89 | |
|
90 | |
public void clear() { |
91 | 0 | if (!initialised) |
92 | 0 | super.clear(); |
93 | |
else |
94 | 0 | throw new UnsupportedOperationException("Cannot modify this map"); |
95 | 0 | } |
96 | |
|
97 | |
public Object put(Object key, Object value) { |
98 | 0 | if (!initialised) |
99 | 0 | return super.put(key, value); |
100 | |
else |
101 | 0 | throw new UnsupportedOperationException("Cannot modify this map"); |
102 | |
} |
103 | |
|
104 | |
public void putAll(Map m) { |
105 | 0 | if (!initialised) |
106 | 0 | super.putAll(m); |
107 | |
else |
108 | 0 | throw new UnsupportedOperationException("Cannot modify this map"); |
109 | 0 | } |
110 | |
|
111 | |
public Object remove(Object key) { |
112 | 0 | if (!initialised) |
113 | 0 | return super.remove(key); |
114 | |
else |
115 | 0 | throw new UnsupportedOperationException("Cannot modify this map"); |
116 | |
} |
117 | |
} |