KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > event > AdminEventListenerRegistry


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31 package com.sun.enterprise.admin.event;
32
33 import java.util.ArrayList JavaDoc;
34 import java.util.HashMap JavaDoc;
35
36 import com.sun.enterprise.admin.event.availability.*;
37 import com.sun.enterprise.admin.event.http.*;
38 import com.sun.enterprise.admin.event.jms.*;
39 import com.sun.enterprise.admin.event.log.*;
40 import com.sun.enterprise.admin.event.tx.*;
41 import com.sun.enterprise.admin.event.wsmgmt.WebServiceEndpointEvent;
42 import com.sun.enterprise.admin.event.wsmgmt.WebServiceEndpointEventListener;
43 import com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEvent;
44 import com.sun.enterprise.admin.event.wsmgmt.TransformationRuleEventListener;
45 import com.sun.enterprise.admin.event.wsmgmt.RegistryLocationEvent;
46 import com.sun.enterprise.admin.event.wsmgmt.RegistryLocationEventListener;
47 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEvent;
48 import com.sun.enterprise.admin.event.selfmanagement.ManagementRuleEventListener;
49
50
51 //i18n import
52
import com.sun.enterprise.util.i18n.StringManager;
53
54 /**
55  * Event Listener registry for admin events. This is a singleton object that
56  * tracks all registered event handlers.
57  */

58 public class AdminEventListenerRegistry {
59
60     /**
61      * Constant used to refer to Notification Event listenerMap
62      */

63     static final String JavaDoc notificationEventType = "javax.management.Notification";
64
65     /**
66      * Add an event listener of type BaseDeployEventListener to the registry.
67      * Once registered using this method, a BaseDeployEventListener receives
68      * all subsequent BaseDeployEvents.
69      */

70     public static void addBaseDeployEventListener(
71             BaseDeployEventListener listener) {
72         AdminEventMulticaster.addListener(BaseDeployEvent.eventType, listener);
73     }
74
75     /**
76      * Add an event listener of type ApplicationDeployEventListener to the
77      * registry. Once registered using this method, an
78      * ApplicationDeployEventListener receives all subsequent
79      * ApplicationDeployEvents.
80      */

81     public static void addApplicationDeployEventListener(
82             ApplicationDeployEventListener listener) {
83         AdminEventMulticaster.addListener(ApplicationDeployEvent.eventType, listener);
84     }
85
86     /**
87      * Add an event listener of type ModuleDeployEventListener to the registry.
88      * Once registered using this method, a ModuleDeployEventListener receives
89      * all subsequent ModuleDeployEvents.
90      */

91     public static void addModuleDeployEventListener(
92             ModuleDeployEventListener listener) {
93         AdminEventMulticaster.addListener(ModuleDeployEvent.eventType, listener);
94     }
95
96     /**
97      * Add an event listener of type ResourceDeployEventListener to the
98      * registry. Once registered using this method, a
99      * ResourceDeployEventListener receives all subsequent ResourceDeployEvents.
100      */

101     public static void addResourceDeployEventListener(
102             ResourceDeployEventListener listener) {
103         AdminEventMulticaster.addListener(ResourceDeployEvent.eventType, listener);
104     }
105
106     /**
107      * Add an event listener of type ConfigChangeEventListener to the registry.
108      * Once registered using this method, a ConfigChangeEventListener receives
109      * all subsequent ConfigChangeEvents.
110      */

111     public static void addConfigChangeEventListener(
112             ConfigChangeEventListener listener) {
113         AdminEventMulticaster.addListener(ConfigChangeEvent.eventType, listener);
114     }
115
116     /**
117      * Add an event listener of type MonitoringEventListener to the registry.
118      * Once registered using this method, a MonitoringEventListener receives
119      * all subsequent MonitoringEvents.
120      */

121     public static void addMonitoringEventListener(
122             MonitoringEventListener listener) {
123         AdminEventMulticaster.addListener(MonitoringEvent.eventType, listener);
124     }
125
126     /**
127      * Remove specified event listener from event registry.
128      * @param listener the event listener to remove
129      */

130     public static void removeEventListener(AdminEventListener listener) {
131         AdminEventMulticaster.removeListener(listener);
132     }
133
134     /**
135      * Add a listener for ConfigChangeEvent that is invoked only if any of
136      * the config attributes as defined by ConfigChangeCategory have been
137      * changed.
138      * @see com.sun.enterprise.admin.event.ConfigChangeCategory
139      */

140     public static void addConfigChangeEventListener(
141             ConfigChangeCategory category, ConfigChangeEventListener listener) {
142         AdminEventMulticaster.addListener(ConfigChangeEvent.eventType, category,
143                 listener);
144     }
145
146     /**
147      * Add a listener for LogLevelChangeEvent
148      * @see com.sun.enterprise.admin.event.LogLevelChangeEvent
149      */

150     public static void addLogLevelChangeEventListener(
151             LogLevelChangeEventListener listener) {
152         AdminEventMulticaster.addListener(
153                 LogLevelChangeEvent.eventType, listener);
154     }
155
156     /**
157      * Add a listener for ElementChangeEvent
158      * @see com.sun.enterprise.admin.event.ElementChangeEvent
159      */

160     public static void addElementChangeEventListener(
161             ElementChangeEventListener listener) {
162         AdminEventMulticaster.addListener(
163                 ElementChangeEvent.eventType, listener);
164     }
165
166     /**
167      * Add a listener for SecurityServiceEvent
168      * @see com.sun.enterprise.admin.event.SecurityServiceEvent
169      */

170     public static void addSecurityServiceEventListener(
171             SecurityServiceEventListener listener) {
172         AdminEventMulticaster.addListener(
173                 SecurityServiceEvent.eventType, listener);
174     }
175
176     /**
177      * Add a listener for AuditModuleEvent
178      * @see com.sun.enterprise.admin.event.AuditModuleEvent
179      */

180     public static void addAuditModuleEventListener(
181             AuditModuleEventListener listener) {
182         AdminEventMulticaster.addListener(
183                 AuditModuleEvent.eventType, listener);
184     }
185
186     /**
187      * Add a listener for AuthRealmEvent
188      * @see com.sun.enterprise.admin.event.AuthRealmEvent
189      */

190     public static void addAuthRealmEventListener(
191             AuthRealmEventListener listener) {
192         AdminEventMulticaster.addListener(
193                 AuthRealmEvent.eventType, listener);
194     }
195
196     /**
197      * Add a listener for UserMgmtEvent
198      * @see com.sun.enterprise.admin.event.UserMgmtEvent
199      */

200     public static void addUserMgmtEventListener(
201             UserMgmtEventListener listener) {
202         AdminEventMulticaster.addListener(
203                 UserMgmtEvent.eventType, listener);
204     }
205
206     /**
207      * Add a listener for EjbTimerEvent
208      * @see com.sun.enterprise.admin.event.EjbTimerEvent
209      */

210     public static void addEjbTimerEventListener(
211             EjbTimerEventListener listener) {
212         AdminEventMulticaster.addListener(
213                 EjbTimerEvent.eventType, listener);
214     }
215
216     /**
217      * Add a listener for MonitoringLevelChangeEvent
218      * @see com.sun.enterprise.admin.event.MonitoringLevelChangeEvent
219      */

220     public static void addMonitoringLevelChangeEventListener(
221             MonitoringLevelChangeEventListener listener) {
222         AdminEventMulticaster.addListener(
223                 MonitoringLevelChangeEvent.eventType, listener);
224     }
225
226     /**
227      * Add a listener for ShutdownEvent
228      * @see com.sun.enterprise.admin.event.ShutdownEvent
229      */

230     public static void addShutdownEventListener(ShutdownEventListener listener) {
231         AdminEventMulticaster.addListener(ShutdownEvent.eventType, listener);
232     }
233
234     /**
235      * Add a listener for AdminEvent
236      * @see com.sun.enterprise.admin.event.AdminEvent
237      *
238      * @param eventType type of the event
239      * @param listener listener implemention for notifications
240      *
241      * @throws IllegalArgumentException if event type and listener type
242      * are not compatible
243      */

244     public static void addEventListener(
245             String JavaDoc eventType, AdminEventListener listener) {
246
247         validateRegistration(eventType, listener);
248
249         AdminEventMulticaster.addListener(
250                 eventType, listener);
251     }
252
253     //---- PRIVATE VARS and PRIVATE METHODS------------------
254

255     private static void validateRegistration(String JavaDoc eventType,AdminEventListener
256                                     listener) {
257
258         if ( (eventType == null) || (listener == null)) {
259             String JavaDoc msg = localStrings.getString("admin.null_not_supported");
260             throw new IllegalArgumentException JavaDoc(msg);
261         }
262
263         // Expected listener interface class
264
Class JavaDoc listenerImplClass = (Class JavaDoc) listenerMap.get(eventType);
265         if (listenerImplClass == null) {
266             // event type is not valid or not supported.
267
String JavaDoc msg = localStrings.getString("admin.event.invalid_event_type" , eventType);
268             throw new IllegalArgumentException JavaDoc(msg);
269         }
270         
271         // get the interfaces of the passed in class
272
Class JavaDoc[] classes = listener.getClass().getInterfaces();
273
274         if (classes == null) {
275             String JavaDoc msg = localStrings.getString("admin.event.does_not_implement" ,listener.getClass().getName());
276             throw new IllegalArgumentException JavaDoc(msg);
277         }
278
279         boolean found = false;
280         // go through all interface names
281
for(int i=0; i< classes.length; i++) {
282           String JavaDoc cName = classes[i].getName();
283           if (cName != null ) {
284             // compare interface name to expected interface name
285
if (cName.equals(listenerImplClass.getName() )){
286                 found = true;
287                 break;
288             }
289           }
290         }
291         if(!found) {
292             String JavaDoc msg = localStrings.getString("admin.event.not_compatible",
293                     eventType,listenerImplClass.getName(),
294                         listener.getClass().getName()) ;
295             throw new IllegalArgumentException JavaDoc();
296         }
297         
298     }
299
300     private static HashMap JavaDoc listenerMap = null;
301
302     static {
303
304         listenerMap = new HashMap JavaDoc();
305
306         listenerMap.put(AdminEvent.eventType, AdminEventListener.class);
307         listenerMap.put(ConfigChangeEvent.eventType,
308                         ConfigChangeEventListener.class);
309         listenerMap.put(MonitoringEvent.eventType,
310                         MonitoringEventListener.class);
311         listenerMap.put(ShutdownEvent.eventType, ShutdownEventListener.class);
312         listenerMap.put(BaseDeployEvent.eventType,
313                         BaseDeployEventListener.class);
314         listenerMap.put(ApplicationDeployEvent.eventType,
315                         ApplicationDeployEventListener.class);
316         listenerMap.put(ModuleDeployEvent.eventType,
317                         ModuleDeployEventListener.class);
318         listenerMap.put(ResourceDeployEvent.eventType,
319                         ResourceDeployEventListener.class);
320         listenerMap.put(LogLevelChangeEvent.eventType,
321                         LogLevelChangeEventListener.class);
322         listenerMap.put(MonitoringLevelChangeEvent.eventType,
323                         MonitoringLevelChangeEventListener.class);
324         //listenerMap.put(AdminEventListenerRegistry.notificationEventType,
325
// Listener.class);
326
listenerMap.put(AvailabilityServiceEvent.eventType,
327                         AvailabilityServiceEventListener.class);
328         listenerMap.put(AuthRealmEvent.eventType,
329                         AuthRealmEventListener.class);
330         listenerMap.put(AuditModuleEvent.eventType,
331                         AuditModuleEventListener.class);
332         listenerMap.put(SecurityServiceEvent.eventType,
333                         SecurityServiceEventListener.class);
334         listenerMap.put(ElementChangeEvent.eventType,
335                         ElementChangeEventListener.class);
336         listenerMap.put(UserMgmtEvent.eventType, UserMgmtEventListener.class);
337         listenerMap.put(EjbTimerEvent.eventType, EjbTimerEventListener.class);
338         listenerMap.put(HSServiceEvent.eventType,
339                         HSServiceEventListener.class);
340         listenerMap.put(HSAccessLogEvent.eventType,
341                         HSAccessLogEventListener.class);
342         listenerMap.put(HSHttpAccessLogEvent.eventType,
343                         HSHttpAccessLogEventListener.class);
344         listenerMap.put(HSHttpListenerEvent.eventType,
345                         HSHttpListenerEventListener.class);
346         listenerMap.put(HSSslEvent.eventType, HSSslEventListener.class);
347         listenerMap.put(HSVirtualServerEvent.eventType,
348                         HSVirtualServerEventListener.class);
349         listenerMap.put(JmsServiceEvent.eventType,
350                         JmsServiceEventListener.class);
351         listenerMap.put(JmsHostEvent.eventType,
352                         JmsHostEventListener.class);
353         listenerMap.put(LogServiceEvent.eventType,
354                         LogServiceEventListener.class);
355         listenerMap.put(DynamicReconfigEvent.eventType,
356                         DynamicReconfigEventListener.class);
357         listenerMap.put(TransactionsRecoveryEvent.eventType,
358                         TransactionsRecoveryEventListener.class);
359         listenerMap.put(JTSEvent.eventType,
360                         JTSEventListener.class);
361         listenerMap.put(WebServiceEndpointEvent.eventType,
362                         WebServiceEndpointEventListener.class);
363         listenerMap.put(TransformationRuleEvent.eventType,
364                         TransformationRuleEventListener.class);
365         listenerMap.put(RegistryLocationEvent.eventType,
366                         RegistryLocationEventListener.class);
367         listenerMap.put(MBeanElementChangeEvent.EVENT_TYPE, MBeanElementChangeEventListener.class);
368         listenerMap.put(ManagementRuleEvent.eventType,
369                         ManagementRuleEventListener.class);
370         listenerMap.put(ClusterEvent.eventType,
371                         ClusterEventListener.class);
372     }
373
374     // i18n StringManager
375
private static StringManager localStrings = StringManager.getManager(
376             AdminEventListenerRegistry.class );
377
378 }
379
Popular Tags