KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > selfmanagement > event > NotificationEventFactory


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  * NotificationEventFactory.java
26  *
27  */

28
29 package com.sun.enterprise.admin.selfmanagement.event;
30
31 import javax.management.NotificationEmitter JavaDoc;
32 import javax.management.MBeanServer JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34 import javax.management.MalformedObjectNameException JavaDoc;
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 JavaDoc;
42 import java.util.regex.Matcher JavaDoc;
43
44 /**
45  *
46  * This is the factory to build and configure Timer Event
47  * @author Sun Micro Systems, Inc
48  */

49 public class NotificationEventFactory extends EventAbstractFactory{
50     
51             /** Creates a new instance of LogEventFactory */
52         private NotificationEventFactory() {
53         super();
54         EventBuilder.getInstance().addEventFactory(EVENT_NOTIFICATION, this);
55     }
56     
57     public Event instrumentEvent(
58             ElementProperty[] properties, String JavaDoc description ) {
59         // sourcembean
60
//String sourceMbean = null;
61
String JavaDoc sourceMbeanObjName = null;
62         String JavaDoc sourceMbeanName = null;
63         for( int i = 0; i < properties.length; i++ ){
64             ElementProperty property = properties[i];
65             String JavaDoc 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 JavaDoc(
74                     sm.getString("selfmgmt_event.invalid_event_property","sourceMBean","notification"));
75         }
76         String JavaDoc sourceMbean = null;
77         if(sourceMbeanObjName != null) {
78             //final String serverNameVal = System.getProperty("com.sun.aas.instanceName");
79
Pattern JavaDoc pat = Pattern.compile("\\$\\{instance.name\\}");
80             Matcher JavaDoc 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         /*if (!(sourceMbean.endsWith(",server=" + instanceName))) {
90             sourceMbean = sourceMbean + ",server=" + instanceName;
91         }*/

92  
93         try {
94             ObjectName JavaDoc oName = new ObjectName JavaDoc(sourceMbean);
95             return new NotificationEvent(oName, description);
96         } catch (MalformedObjectNameException JavaDoc ex) {
97             throw new IllegalArgumentException JavaDoc(
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 JavaDoc instanceName = (ApplicationServer.getServerContext()).getInstanceName();
109 }
110
Popular Tags