1 23 24 28 29 package com.sun.enterprise.admin.selfmanagement.event; 30 31 import javax.management.NotificationEmitter ; 32 import javax.management.MBeanServer ; 33 import javax.management.ObjectName ; 34 import javax.management.MalformedObjectNameException ; 35 36 import com.sun.enterprise.config.serverbeans.ElementProperty; 37 import com.sun.enterprise.admin.selfmanagement.configuration.JavaBeanConfigurator; 38 import com.sun.enterprise.util.SystemPropertyConstants; 39 import static com.sun.enterprise.admin.selfmanagement.event.ManagementRuleConstants.*; 40 import com.sun.enterprise.server.ApplicationServer; 41 import java.util.regex.Pattern ; 42 import java.util.regex.Matcher ; 43 44 49 public class NotificationEventFactory extends EventAbstractFactory{ 50 51 52 private NotificationEventFactory() { 53 super(); 54 EventBuilder.getInstance().addEventFactory(EVENT_NOTIFICATION, this); 55 } 56 57 public Event instrumentEvent( 58 ElementProperty[] properties, String description ) { 59 String sourceMbeanObjName = null; 62 String sourceMbeanName = null; 63 for( int i = 0; i < properties.length; i++ ){ 64 ElementProperty property = properties[i]; 65 String propertyName = property.getName( ).toLowerCase( ); 66 if (propertyName.equals(PROPERTY_NOTIFICATION_SOURCE_OBJ_NAME)) { 67 sourceMbeanObjName = property.getValue(); 68 } else if (propertyName.equals(PROPERTY_NOTIFICATION_SOURCEMBEAN)) { 69 sourceMbeanName = property.getValue(); 70 } 71 } 72 if (sourceMbeanName == null && sourceMbeanObjName == null) { 73 throw new IllegalArgumentException ( 74 sm.getString("selfmgmt_event.invalid_event_property","sourceMBean","notification")); 75 } 76 String sourceMbean = null; 77 if(sourceMbeanObjName != null) { 78 Pattern pat = Pattern.compile("\\$\\{instance.name\\}"); 80 Matcher m = pat.matcher(sourceMbeanObjName); 81 if(m.find()) { 82 sourceMbean = m.replaceAll(instanceName); 83 } else { 84 sourceMbean = sourceMbeanObjName; 85 } 86 } else if(sourceMbeanName != null) { 87 sourceMbean = ManagementRulesMBeanHelper.getObjName(sourceMbeanName); 88 } 89 92 93 try { 94 ObjectName oName = new ObjectName (sourceMbean); 95 return new NotificationEvent(oName, description); 96 } catch (MalformedObjectNameException ex) { 97 throw new IllegalArgumentException ( 98 sm.getString("selfmgmt_event.invalid_event_property","sourceMBean","notification")); 99 } 100 } 101 102 static NotificationEventFactory getInstance() { 103 return instance; 104 } 105 106 107 private static NotificationEventFactory instance = new NotificationEventFactory(); 108 private static String instanceName = (ApplicationServer.getServerContext()).getInstanceName(); 109 } 110 | Popular Tags |