KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29 package com.sun.enterprise.admin.selfmanagement.event;
30
31
32 import javax.management.NotificationEmitter JavaDoc;
33 import javax.management.MBeanServer JavaDoc;
34
35 import com.sun.enterprise.config.serverbeans.ElementProperty;
36 import com.sun.enterprise.admin.selfmanagement.configuration.JavaBeanConfigurator;
37 import java.util.logging.Level JavaDoc;
38 import static com.sun.enterprise.admin.selfmanagement.event.ManagementRuleConstants.*;
39
40 /**
41  *
42  * @author Sun Micro Systems, Inc
43  */

44
45 public class LifeCycleEventFactory extends EventAbstractFactory {
46     
47     private LifeCycleEventFactory( ) {
48         super();
49         EventBuilder.getInstance().addEventFactory(EVENT_LIFECYCLE, this);
50         try {
51             LifeCycleImpl impl = (LifeCycleImpl) getMBeanServer().instantiate(
52                     "com.sun.enterprise.admin.selfmanagement.event.LifeCycleImpl");
53             getMBeanServer().registerMBean(impl,LifeCycleEvent.getLifeCycleImplObjectName());
54         } catch (javax.management.ReflectionException JavaDoc rex) {
55             _logger.log(Level.WARNING,"smgt.internal_error", rex);
56         } catch (javax.management.InstanceAlreadyExistsException JavaDoc iex) {
57             _logger.log(Level.WARNING,"smgt.internal_error", iex);
58         } catch (Exception JavaDoc ex) {
59             _logger.log(Level.WARNING,"smgt.internal_error", ex);
60             
61         }
62     }
63     
64     public Event instrumentEvent(
65             ElementProperty[] properties, String JavaDoc description ) {
66         String JavaDoc eventName = null;
67         for( int i = 0; i < properties.length; i++ ){
68             ElementProperty property = properties[i];
69             String JavaDoc propertyName = property.getName( ).toLowerCase( );
70             if( propertyName.equals(PROPERTY_LIFECYCLE_NAME)) {
71                 eventName = "lifecycle." + property.getValue( ).toLowerCase( );
72                 if (!LifeCycleEvent.isValidType(eventName))
73                     throw new IllegalArgumentException JavaDoc(
74                             sm.getString("name","selfmgmt_event.invalid_event_property","lifecycle"));
75             }
76         }
77         return new LifeCycleEvent(eventName, new LifeCycleNotificationFilter(eventName), description);
78     }
79     
80     static LifeCycleEventFactory getInstance() {
81         return instance;
82     }
83     private static LifeCycleEventFactory instance = new LifeCycleEventFactory();
84 }
85
Popular Tags