1 /*
2 * Registry.java
3 * Created on August 13, 2003
4 *
5 * The Blues Framework - A lightweight application framework
6 * Copyright (C) 2003 Lonnie Pryor
7 * http://blues.lonniepryor.com
8 *
9 * This library is free software; you can redistribute it and/or modify it under the
10 * terms of the GNU Lesser General Public License as published by the Free Software
11 * Foundation; either version 2.1 of the License, or (at your option) any later
12 * version.
13 *
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License along
19 * with this library; if not, write to:
20 *
21 * The Free Software Foundation, Inc.
22 * 59 Temple Place, Suite 330
23 * Boston, MA 02111-1307 USA
24 *
25 */
26 package com.lonniepryor.blues.sys;
27
28 import java.util.HashMap;
29 import java.util.LinkedList;
30 import java.util.List;
31 import java.util.Map;
32
33 import com.lonniepryor.blues.Lifecycle;
34
35 /***
36 * A registry that collects the individual elements of an aplication.
37 *
38 * @author Lonnie Pryor
39 * @version $Revision: 1.1 $
40 */
41 public final class Registry {
42 /*** The singletons in this application. */
43 private final Map singletons = new HashMap();
44 /*** The services in this application. */
45 private final Map services = new HashMap();
46 /*** The dispatchers in this application. */
47 private final Map dispatchers = new HashMap();
48 /*** The instances of lifecycle in this application. */
49 private final List lifecycles = new LinkedList();
50
51 /***
52 * Creates a new Registry object.
53 */
54 Registry () {
55 }
56
57 /***
58 * Returns the singletons in this application.
59 *
60 * @return The singletons in this application.
61 */
62 public Map getSingletons () {
63 return singletons;
64 }
65
66 /***
67 * Returns the services in this application.
68 *
69 * @return The services in this application.
70 */
71 public Map getServices () {
72 return services;
73 }
74
75 /***
76 * Returns the dispatchers in this application.
77 *
78 * @return The dispatchers in this application.
79 */
80 public Map getDispatchers () {
81 return dispatchers;
82 }
83
84 /***
85 * Returns the instances of lifecycle in this application.
86 *
87 * @return The instances of lifecycle in this application.
88 */
89 public List getLifecycles () {
90 return lifecycles;
91 }
92
93 /***
94 * Registers a singleton with this registry.
95 *
96 * @param singletonType The public type of the singleton.
97 * @param singletonInstance The singleton instance.
98 */
99 void registerSingleton (Class singletonType, Object singletonInstance) {
100 singletons.put(singletonType, singletonInstance);
101 if (singletonInstance instanceof Lifecycle)
102 lifecycles.add(singletonInstance);
103 }
104
105 /***
106 * Registers a service with this registry.
107 *
108 * @param serviceName The fully-qualified name of the service.
109 * @param serviceInstance The service instance.
110 */
111 void registerService (String serviceName, Object serviceInstance) {
112 services.put(serviceName, serviceInstance);
113 if (serviceInstance instanceof Lifecycle)
114 lifecycles.add(serviceInstance);
115 }
116
117 /***
118 * Registers an advice with this registry.
119 *
120 * @param adviceInstance The advice instance.
121 */
122 void registerAdvice (Object adviceInstance) {
123 if (adviceInstance instanceof Lifecycle)
124 lifecycles.add(adviceInstance);
125 }
126
127 /***
128 * Registers a dispatcher with this registry.
129 *
130 * @param observerInterface The observer interface.
131 * @param dispatcherInstance The dispatcher instance.
132 */
133 void registerDispatcher (Class observerInterface, Object dispatcherInstance) {
134 dispatchers.put(observerInterface, dispatcherInstance);
135 }
136 }
This page was automatically generated by Maven