01: /*
02: * Created on Nov 11, 2005
03: */
04: package uk.org.ponder.rsf.uitype;
05:
06: import java.util.HashMap;
07:
08: public class UITypes {
09: private static HashMap types = new HashMap();
10: private static HashMap names = new HashMap();
11: private static HashMap classes = new HashMap();
12:
13: public static void registerType(UIType toregister) {
14: types.put(toregister.getPlaceholder(), toregister);
15: names.put(toregister.getName(), toregister);
16: classes.put(toregister.getPlaceholder().getClass(), toregister);
17: }
18:
19: static {
20: registerType(StringArrayUIType.instance);
21: registerType(StringUIType.instance);
22: registerType(BooleanUIType.instance);
23: }
24:
25: public static boolean isPlaceholder(Object o) {
26: UIType type = forObject(o);
27: // Must compare by REFERENCE!
28: return type == null ? false : o == type.getPlaceholder();
29: }
30:
31: /** Look up a UIType entry based on the class of the submitted object.
32: * Returns <code>null</code> if this is not a recognised UIType.
33: */
34: public static UIType forObject(Object o) {
35: return (UIType) classes.get(o.getClass());
36: }
37:
38: public static UIType forName(String name) {
39: return (UIType) names.get(name);
40: }
41: }
|