KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > services > jmx > server > weblogic > WebLogicMBeanServerServiceImpl


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.services.jmx.server.weblogic;
19
20
21
22 import javax.management.MBeanServer JavaDoc;
23 import javax.naming.AuthenticationException JavaDoc;
24 import javax.naming.CommunicationException JavaDoc;
25 import javax.naming.Context JavaDoc;
26 import javax.naming.NamingException JavaDoc;
27
28 import org.sape.carbon.core.component.ComponentConfiguration;
29 import org.sape.carbon.core.component.lifecycle.Configurable;
30 import org.sape.carbon.core.exception.ExceptionUtility;
31 import org.sape.carbon.services.jmx.server.MBeanServerService;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import weblogic.jndi.Environment;
36 import weblogic.management.MBeanHome;
37
38 /**
39  * <P>Weblogic specific implementation of the MBeanServerProvider interface.</p>
40  *
41  * Copyright 2002 Sapient
42  * @author Greg Hinkle
43  * @version $Revision: 1.8 $ ($Author: dvoet $)
44  */

45 public class WebLogicMBeanServerServiceImpl
46         implements MBeanServerService, Configurable {
47
48
49     /**
50      * Provides a handle to Apache-commons logger
51      */

52     private Log log = LogFactory.getLog(this.getClass());
53
54     /** Configuration for the service. */
55     protected WebLogicMBeanServerServiceConfiguration config;
56
57     /**
58      * Gets the instance of the Weblogic MBean Server.
59      *
60      * @return instance of the Weblogic MBean server
61      */

62     public MBeanServer JavaDoc getMBeanServer() {
63         MBeanServer JavaDoc mbeanServer = null;
64         MBeanHome home = null;
65         try {
66             Environment env = new Environment();
67             if (config != null) {
68                 if (config.getInitialContextFactory() != null) {
69                     env.setInitialContextFactory(
70                         config.getInitialContextFactory());
71                 }
72
73                 if (config.getPrincipal() != null) {
74                     env.setSecurityPrincipal(config.getPrincipal());
75                 }
76
77                 if (config.getCredentials() != null) {
78                     env.setSecurityCredentials(config.getCredentials());
79                 }
80             }
81
82             Context JavaDoc ctx = env.getInitialContext();
83             home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
84             mbeanServer = home.getMBeanServer();
85
86             if (mbeanServer != null) {
87                 if (log.isTraceEnabled()) {
88                     log.trace("Got back MBeanServer of type ["
89                         + mbeanServer.getClass().getName() + "]");
90                 }
91             }
92         } catch (AuthenticationException JavaDoc e) {
93             if (log.isTraceEnabled()) {
94                 log.trace("Caught exception: " + e
95                     + ExceptionUtility.captureStackTrace(e));
96             }
97         } catch (CommunicationException JavaDoc e) {
98             if (log.isTraceEnabled()) {
99                 log.trace("Caught exception: " + e
100                     + ExceptionUtility.captureStackTrace(e));
101             }
102         } catch (NamingException JavaDoc e) {
103             if (log.isTraceEnabled()) {
104                 log.trace("Caught exception: " + e
105                     + ExceptionUtility.captureStackTrace(e));
106             }
107         }
108         return mbeanServer;
109     }
110
111     /**
112      * Configures the service.
113      *
114      * @param configuration <code>WebLogicMBeanServerServiceConfiguration</code>
115      * configuration object for the service
116      */

117     public void configure(ComponentConfiguration configuration) {
118         try {
119             this.config =
120                 (WebLogicMBeanServerServiceConfiguration) configuration;
121
122             if (log.isTraceEnabled()) {
123                 log.trace(
124                     "Specifed proper WebLogicMBeanServerServiceConfiguration."
125                     + "Using values from configuration file.");
126             }
127
128         } catch (ClassCastException JavaDoc cce) {
129             this.config = null;
130             if (log.isTraceEnabled()) {
131                 log.trace(
132                     "Specifed WebLogicMBeanServerServiceConfiguration does not "
133                     + "implement correct interface. Empty InitialContext "
134                     + "settings will be used.");
135             }
136         }
137     }
138 }
Popular Tags