01: /*
02: * MyGWT Widget Library
03: * Copyright(c) 2007, MyGWT.
04: * licensing@mygwt.net
05: *
06: * http://mygwt.net/license
07: */
08: package net.mygwt.ui.client;
09:
10: import java.util.HashMap;
11: import java.util.Iterator;
12: import java.util.Map;
13:
14: import net.mygwt.ui.client.util.Observable;
15:
16: /**
17: * A local storage of objects stored by id.
18: */
19: public class Registry extends Observable {
20:
21: protected static Map map = new HashMap();
22:
23: /**
24: * Returns the object with the given id.
25: *
26: * @param id the identifier
27: * @return the object or <code>null</code> if no match
28: */
29: public static Object get(String id) {
30: return map.get(id);
31: }
32:
33: /**
34: * Returns a map of all registered objects.
35: *
36: * @return the object map
37: */
38: public static Map getAll() {
39: return map;
40: }
41:
42: /**
43: * Registers an object.
44: *
45: * @param id the indentifier
46: * @param obj the object to be registred
47: */
48: public static void register(String id, Object obj) {
49: map.put(id, obj);
50: }
51:
52: /**
53: * Unregisters an object.
54: *
55: * @param id the identifier
56: */
57: public static void unregister(String id) {
58: map.remove(id);
59: }
60:
61: /**
62: * Unregisters all registered objects.
63: */
64: public static void unregisterAll() {
65: Iterator it = map.keySet().iterator();
66: while (it.hasNext()) {
67: unregister((String) it.next());
68: }
69:
70: }
71:
72: private Registry() {
73: }
74:
75: }
|