1 23 24 31 package com.sun.enterprise.admin.event; 32 33 import java.util.ArrayList ; 34 import java.util.HashMap ; 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 import com.sun.enterprise.util.i18n.StringManager; 53 54 58 public class AdminEventListenerRegistry { 59 60 63 static final String notificationEventType = "javax.management.Notification"; 64 65 70 public static void addBaseDeployEventListener( 71 BaseDeployEventListener listener) { 72 AdminEventMulticaster.addListener(BaseDeployEvent.eventType, listener); 73 } 74 75 81 public static void addApplicationDeployEventListener( 82 ApplicationDeployEventListener listener) { 83 AdminEventMulticaster.addListener(ApplicationDeployEvent.eventType, listener); 84 } 85 86 91 public static void addModuleDeployEventListener( 92 ModuleDeployEventListener listener) { 93 AdminEventMulticaster.addListener(ModuleDeployEvent.eventType, listener); 94 } 95 96 101 public static void addResourceDeployEventListener( 102 ResourceDeployEventListener listener) { 103 AdminEventMulticaster.addListener(ResourceDeployEvent.eventType, listener); 104 } 105 106 111 public static void addConfigChangeEventListener( 112 ConfigChangeEventListener listener) { 113 AdminEventMulticaster.addListener(ConfigChangeEvent.eventType, listener); 114 } 115 116 121 public static void addMonitoringEventListener( 122 MonitoringEventListener listener) { 123 AdminEventMulticaster.addListener(MonitoringEvent.eventType, listener); 124 } 125 126 130 public static void removeEventListener(AdminEventListener listener) { 131 AdminEventMulticaster.removeListener(listener); 132 } 133 134 140 public static void addConfigChangeEventListener( 141 ConfigChangeCategory category, ConfigChangeEventListener listener) { 142 AdminEventMulticaster.addListener(ConfigChangeEvent.eventType, category, 143 listener); 144 } 145 146 150 public static void addLogLevelChangeEventListener( 151 LogLevelChangeEventListener listener) { 152 AdminEventMulticaster.addListener( 153 LogLevelChangeEvent.eventType, listener); 154 } 155 156 160 public static void addElementChangeEventListener( 161 ElementChangeEventListener listener) { 162 AdminEventMulticaster.addListener( 163 ElementChangeEvent.eventType, listener); 164 } 165 166 170 public static void addSecurityServiceEventListener( 171 SecurityServiceEventListener listener) { 172 AdminEventMulticaster.addListener( 173 SecurityServiceEvent.eventType, listener); 174 } 175 176 180 public static void addAuditModuleEventListener( 181 AuditModuleEventListener listener) { 182 AdminEventMulticaster.addListener( 183 AuditModuleEvent.eventType, listener); 184 } 185 186 190 public static void addAuthRealmEventListener( 191 AuthRealmEventListener listener) { 192 AdminEventMulticaster.addListener( 193 AuthRealmEvent.eventType, listener); 194 } 195 196 200 public static void addUserMgmtEventListener( 201 UserMgmtEventListener listener) { 202 AdminEventMulticaster.addListener( 203 UserMgmtEvent.eventType, listener); 204 } 205 206 210 public static void addEjbTimerEventListener( 211 EjbTimerEventListener listener) { 212 AdminEventMulticaster.addListener( 213 EjbTimerEvent.eventType, listener); 214 } 215 216 220 public static void addMonitoringLevelChangeEventListener( 221 MonitoringLevelChangeEventListener listener) { 222 AdminEventMulticaster.addListener( 223 MonitoringLevelChangeEvent.eventType, listener); 224 } 225 226 230 public static void addShutdownEventListener(ShutdownEventListener listener) { 231 AdminEventMulticaster.addListener(ShutdownEvent.eventType, listener); 232 } 233 234 244 public static void addEventListener( 245 String eventType, AdminEventListener listener) { 246 247 validateRegistration(eventType, listener); 248 249 AdminEventMulticaster.addListener( 250 eventType, listener); 251 } 252 253 255 private static void validateRegistration(String eventType,AdminEventListener 256 listener) { 257 258 if ( (eventType == null) || (listener == null)) { 259 String msg = localStrings.getString("admin.null_not_supported"); 260 throw new IllegalArgumentException (msg); 261 } 262 263 Class listenerImplClass = (Class ) listenerMap.get(eventType); 265 if (listenerImplClass == null) { 266 String msg = localStrings.getString("admin.event.invalid_event_type" , eventType); 268 throw new IllegalArgumentException (msg); 269 } 270 271 Class [] classes = listener.getClass().getInterfaces(); 273 274 if (classes == null) { 275 String msg = localStrings.getString("admin.event.does_not_implement" ,listener.getClass().getName()); 276 throw new IllegalArgumentException (msg); 277 } 278 279 boolean found = false; 280 for(int i=0; i< classes.length; i++) { 282 String cName = classes[i].getName(); 283 if (cName != null ) { 284 if (cName.equals(listenerImplClass.getName() )){ 286 found = true; 287 break; 288 } 289 } 290 } 291 if(!found) { 292 String msg = localStrings.getString("admin.event.not_compatible", 293 eventType,listenerImplClass.getName(), 294 listener.getClass().getName()) ; 295 throw new IllegalArgumentException (); 296 } 297 298 } 299 300 private static HashMap listenerMap = null; 301 302 static { 303 304 listenerMap = new HashMap (); 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(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 private static StringManager localStrings = StringManager.getManager( 376 AdminEventListenerRegistry.class ); 377 378 } 379 | Popular Tags |