KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > CustomMBeanRegistrationHelper


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 package com.sun.enterprise.admin.server.core;
25 import com.sun.enterprise.config.serverbeans.Mbean;
26 import java.lang.reflect.Constructor JavaDoc;
27 import javax.management.MBeanServer JavaDoc;
28 import com.sun.enterprise.config.ConfigContext;
29 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
30 import com.sun.enterprise.util.SystemPropertyConstants;
31 import java.util.List JavaDoc;
32
33 class CustomMBeanRegistrationHelper {
34     private final MBeanServer JavaDoc mbs;
35     private final ConfigContext cc;
36     private final String JavaDoc myName;
37     private final CustomMBeanRegistration cmr;
38     CustomMBeanRegistrationHelper(final MBeanServer JavaDoc mbs, final ConfigContext cc) throws Exception JavaDoc {
39         this.mbs = mbs;
40         this.cc = cc;
41         myName = System.getProperty(SystemPropertyConstants.SERVER_NAME);
42         cmr = mbeanRegistrationFactory();
43     }
44     
45     void registerMBeans() throws Exception JavaDoc {
46         final List JavaDoc<Mbean> m2r = getMBeans2Register();
47         cmr.registerMBeans(m2r);
48     }
49     
50     ///// private methods /////
51
private CustomMBeanRegistration mbeanRegistrationFactory() throws Exception JavaDoc {
52         final String JavaDoc CUSTOM_REGRISTRATION_IMPL_CLASS = "com.sun.enterprise.admin.mbeans.custom.loading.CustomMBeanRegistrationImpl";
53         final Class JavaDoc c = Class.forName(CUSTOM_REGRISTRATION_IMPL_CLASS);
54         final Class JavaDoc[] pts = new Class JavaDoc[]{javax.management.MBeanServer JavaDoc.class};
55         final Constructor JavaDoc ctor = c.getConstructor(pts);
56         final Object JavaDoc[] aps = new Object JavaDoc[]{mbs};
57         return ( (CustomMBeanRegistration) ctor.newInstance(aps) );
58     }
59     
60     private List JavaDoc<Mbean> getMBeans2Register() throws Exception JavaDoc {
61         return ( ServerBeansFactory.getFullyEnabledUserDefinedMBeans(cc, myName) );
62     }
63     ///// private methods /////
64
}
Popular Tags