01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.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: * Have constants class extend this class to expose them to JSTL as a HashMap.
26: *
27: * @author rkirkend
28: */
29: public class JSTLConstants extends HashMap {
30:
31: private static final long serialVersionUID = 6701136401021219281L;
32: private boolean initialised = false;
33:
34: public JSTLConstants() {
35: Class c = this .getClass();
36: Field[] fields = c.getDeclaredFields();
37: for (int i = 0; i < fields.length; i++) {
38:
39: Field field = fields[i];
40: int modifier = field.getModifiers();
41: if (Modifier.isFinal(modifier)
42: && !Modifier.isPrivate(modifier))
43: try {
44: this .put(field.getName(), field.get(this ));
45: } catch (IllegalAccessException e) {
46: }
47: }
48: initialised = true;
49: }
50:
51: public void clear() {
52: if (!initialised)
53: super .clear();
54: else
55: throw new UnsupportedOperationException(
56: "Cannot modify this map");
57: }
58:
59: public Object put(Object key, Object value) {
60: if (!initialised)
61: return super .put(key, value);
62: else
63: throw new UnsupportedOperationException(
64: "Cannot modify this map");
65: }
66:
67: public void putAll(Map m) {
68: if (!initialised)
69: super .putAll(m);
70: else
71: throw new UnsupportedOperationException(
72: "Cannot modify this map");
73: }
74:
75: public Object remove(Object key) {
76: if (!initialised)
77: return super .remove(key);
78: else
79: throw new UnsupportedOperationException(
80: "Cannot modify this map");
81: }
82: }
|