01: /*
02: * $Id: EnumeratedType.java 461109 2006-06-22 19:09:45Z ehillenius $
03: * $Revision: 461109 $ $Date: 2006-06-22 21:09:45 +0200 (Thu, 22 Jun 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.util.lang;
19:
20: import java.util.ArrayList;
21: import java.util.HashMap;
22: import java.util.List;
23: import java.util.Map;
24:
25: import wicket.util.string.StringValue;
26:
27: /**
28: * A base class for defining enumerated types. Since this class extends
29: * StringValue, every enumerated type subclass is a StringValue that can be
30: * manipulated, converted and displayed in useful ways. In addition to
31: * constructing a type with the given name, lists are kept of all enumeration
32: * values by subclass. The list of available values in the enumeration
33: * represented by a given subclass can be retrieved by calling getValues(Class).
34: *
35: * @author Jonathan Locke
36: *
37: * @deprecated To be replaced by JSE 5 constructs in Wicket 2.0
38: */
39: public abstract class EnumeratedType extends StringValue {
40: /** Map of type values by class */
41: private static final Map valueListByClass = new HashMap();
42:
43: /**
44: * Constructor.
45: *
46: * @param name
47: * Name of this enumerated type value
48: */
49: public EnumeratedType(final String name) {
50: super (name);
51:
52: // Add this object to the list of values for our subclass
53: getValues(getClass()).add(this );
54: }
55:
56: /**
57: * Gets the enumerated type values for a given subclass of EnumeratedType.
58: *
59: * @param c
60: * The enumerated type subclass to get values for
61: * @return List of all values of the given subclass
62: */
63: public static List getValues(final Class c) {
64: // Get values for class
65: List valueList = (List) valueListByClass.get(c);
66:
67: // If no list exists
68: if (valueList == null) {
69: // create lazily
70: valueList = new ArrayList();
71: valueListByClass.put(c, valueList);
72: }
73:
74: return valueList;
75: }
76: }
|