KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > jmx > remote > MBeanServerConnectionFactory


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 /* CVS information
25  * $Header: /cvs/glassfish/jmx-remote/rjmx-impl/src/java/com/sun/enterprise/admin/jmx/remote/MBeanServerConnectionFactory.java,v 1.4 2005/12/25 04:26:30 tcfujii Exp $
26  * $Revision: 1.4 $
27  * $Date: 2005/12/25 04:26:30 $
28 */

29
30 package com.sun.enterprise.admin.jmx.remote;
31
32 import java.util.Map JavaDoc;
33 import javax.management.remote.JMXServiceURL JavaDoc;
34 import com.sun.enterprise.admin.jmx.remote.comm.AuthenticationInfo;
35 import com.sun.enterprise.admin.jmx.remote.comm.ConnectionFactory;
36 import com.sun.enterprise.admin.jmx.remote.comm.HttpConnectorAddress;
37 import com.sun.enterprise.admin.jmx.remote.internal.RemoteMBeanServerConnection;
38
39 import javax.management.MBeanServerConnection JavaDoc;
40
41 /** A Factory class that creates the instances of MBeanServerConnection depending upon the given JMXServiceURL {@link javax.management.remote.JMXServiceURL}.
42  * The returned instances are proxies to actual remote MBeanServerConnection.
43  * @author Kedar Mhaswade
44  * @since S1AS8.0
45  * @version 1.0
46 */

47
48 final class MBeanServerConnectionFactory {
49     
50     private MBeanServerConnectionFactory() {
51     }
52
53     /**
54      * The static factory method that creates instance of MBeanServerConnection.
55      * This method always creates a new MBeanServerConnection instance every time
56      * it is called. If the call succeeds, the returned instance can be used to
57      * invoke any MBeanServerConnection method immediately.
58      * @param env a Map containing all the necessary varialbes.
59      * @param serviceUrl an instance of JMXServiceURL specifying the JMXConnector
60      * @return a ready-to-call MBeanServerConnection instance.
61      * @throws Exception, in case the connection could not be established to the server-side.
62     */

63     
64     static MBeanServerConnection getRemoteMBeanServerConnection(Map JavaDoc env, JMXServiceURL JavaDoc serviceUrl)
65     throws Exception JavaDoc {
66         return new RemoteMBeanServerConnection(env2HttpAddress(env, serviceUrl), env);
67     }
68
69     /** Sets the HttpAddress for the given Map and JMXServiceURL */
70     
71     private static HttpConnectorAddress env2HttpAddress(Map JavaDoc env, JMXServiceURL JavaDoc serviceUrl) {
72 /* BEGIN -- S1WS_MOD */
73         final HttpConnectorAddress ad = new HttpConnectorAddress(serviceUrl.getHost(), serviceUrl.getPort(), isHttps(serviceUrl), serviceUrl.getURLPath());
74 /* END -- S1WS_MOD */
75         ad.setAuthenticationInfo(env2AuthenticationInfo(env));
76         return ( ad );
77     }
78     
79     /** Sets the authentication information */
80     
81     private static AuthenticationInfo env2AuthenticationInfo(Map JavaDoc env) {
82         final String JavaDoc user = (String JavaDoc) env.get(DefaultConfiguration.ADMIN_USER_ENV_PROPERTY_NAME);
83         final String JavaDoc pwd = (String JavaDoc) env.get(DefaultConfiguration.ADMIN_PASSWORD_ENV_PROPERTY_NAME);
84         return ( new AuthenticationInfo(user, pwd) );
85     }
86     
87     private static boolean isHttps(JMXServiceURL JavaDoc url) {
88         return ( DefaultConfiguration.S1_HTTPS_PROTOCOL.equals(url.getProtocol()) );
89     }
90 }
91
Popular Tags