KickJava   Java API By Example, From Geeks To Geeks.

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


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/SunOneHttpJmxConnectorFactory.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 java.util.HashMap JavaDoc;
34 import java.io.IOException JavaDoc;
35
36 import javax.management.remote.JMXServiceURL JavaDoc;
37 import javax.management.remote.JMXConnector JavaDoc;
38 import javax.management.remote.JMXConnectorFactory JavaDoc;
39 import com.sun.enterprise.admin.jmx.remote.DefaultConfiguration;
40
41 /** A convenience class that knows how to setup the client side to get the reference of JMXConnector.
42  * This class is specific to Sun ONE Application Server 8.0. Any
43  * client can use the following to initialize the S1AS 8.0 JSR 160 client.
44  * This class lets the clients to do this under the hood and provide a {@link JMXConnectorFactory} like
45  * API.
46  * @author Kedar Mhaswade
47  * @since S1AS8.0
48  * @version 1.0
49 */

50
51 public class SunOneHttpJmxConnectorFactory {
52
53     /** Creates a new instance of SunOneHttpJmxConnectorFactory */
54     private SunOneHttpJmxConnectorFactory() {
55     }
56     
57     private static Map JavaDoc initEnvironment() {
58         final Map JavaDoc env = new HashMap JavaDoc();
59         final String JavaDoc PKGS = "com.sun.enterprise.admin.jmx.remote.protocol";
60         env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, PKGS);
61         env.put(DefaultConfiguration.HTTP_AUTH_PROPERTY_NAME, DefaultConfiguration.DEFAULT_HTTP_AUTH_SCHEME);
62         
63         return ( env );
64     }
65
66     public static JMXConnector JavaDoc connect(JMXServiceURL JavaDoc url, String JavaDoc user, String JavaDoc password)
67     throws IOException JavaDoc {
68         return connect(url, user, password, null);
69     }
70
71     public static JMXConnector JavaDoc connect(JMXServiceURL JavaDoc url, String JavaDoc user, String JavaDoc password, Map JavaDoc extraEnv)
72     throws IOException JavaDoc {
73         final Map JavaDoc env = initEnvironment();
74         if (user != null)
75             env.put(DefaultConfiguration.ADMIN_USER_ENV_PROPERTY_NAME, user);
76         if (password != null)
77             env.put(DefaultConfiguration.ADMIN_PASSWORD_ENV_PROPERTY_NAME, password);
78         if (extraEnv != null) env.putAll(extraEnv);
79         
80         return ( JMXConnectorFactory.connect(url, env) );
81     }
82 }
83
Popular Tags