KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > jmx > spi > SunOneHttpProvider


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  * $Header: /cvs/glassfish/admin-cli/cli-api/src/java/com/sun/cli/jmx/spi/SunOneHttpProvider.java,v 1.3 2005/12/25 03:45:42 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:45:42 $
28  */

29
30 package com.sun.cli.jmx.spi;
31
32 import java.util.Map JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.io.IOException JavaDoc;
35 import javax.management.remote.JMXConnector JavaDoc;
36 import javax.management.remote.JMXServiceURL JavaDoc;
37 import com.sun.enterprise.admin.jmx.remote.DefaultConfiguration;
38 import com.sun.enterprise.admin.jmx.remote.SunOneHttpJmxConnectorFactory;
39 import com.sun.cli.jmx.spi.JMXConnectorProvider;
40
41 /**
42  * Implements the provider to Generic CLI for the protocol "s1ashttp".
43  *
44  * @author kedar
45  * @version 1.0
46  */

47
48 public class SunOneHttpProvider implements JMXConnectorProvider {
49     
50     public SunOneHttpProvider() {
51     }
52     
53     static class Info implements JMXConnectorProviderInfo
54     {
55         private static final String JavaDoc DESCRIPTION =
56             "Implements the SunOne Appserver 8.0 PE connector.";
57         private static final String JavaDoc USAGE =
58             "connect --host <host> --port port --protocol s1ashttp " +
59             "--user <user> --password <pass> [connection-name]";
60         
61             public String JavaDoc
62         getDescription() {
63             return( DESCRIPTION );
64         }
65             public String JavaDoc
66         getUsage() {
67             return( USAGE );
68         }
69     }
70     
71         public static JMXConnectorProviderInfo
72     getInfo() {
73         return( new Info() );
74     }
75         
76     
77     public JMXConnector JavaDoc connect(Map JavaDoc m) throws IOException JavaDoc {
78         final String JavaDoc user = (String JavaDoc) m.get(DefaultConfiguration.ADMIN_USER_ENV_PROPERTY_NAME);
79         final String JavaDoc password = (String JavaDoc) m.get(DefaultConfiguration.ADMIN_PASSWORD_ENV_PROPERTY_NAME);
80         final JMXServiceURL JavaDoc url = env2JmxServiceUrl(m);
81         System.out.println("User = " + user);
82         System.out.println("Password = " + password);
83         return ( SunOneHttpJmxConnectorFactory.connect(url, user, password) );
84     }
85     
86     public final static String JavaDoc MY_PROTOCOL = "s1ashttp";
87     
88     public boolean isSupported(Map JavaDoc m) {
89         final boolean hostPresent = m.get(JMXConnectorProvider.HOST) != null;
90         final boolean portPresent = m.get(JMXConnectorProvider.PORT) != null;
91         
92         final String JavaDoc protocol = (String JavaDoc)m.get(JMXConnectorProvider.PROTOCOL);
93         final boolean protocolPresent = protocol != null;
94         final boolean userPresent = m.get(DefaultConfiguration.ADMIN_USER_ENV_PROPERTY_NAME) != null;
95         final boolean passwordPresent = m.get(DefaultConfiguration.ADMIN_PASSWORD_ENV_PROPERTY_NAME) != null;
96         return ( hostPresent && portPresent && protocolPresent && protocol.equals( MY_PROTOCOL ) &&
97                  userPresent && passwordPresent );
98     }
99     
100     private JMXServiceURL JavaDoc env2JmxServiceUrl(Map JavaDoc m) throws java.net.MalformedURLException JavaDoc {
101         final String JavaDoc protocol = (String JavaDoc) m.get(JMXConnectorProvider.PROTOCOL);
102         final String JavaDoc host = (String JavaDoc) m.get(JMXConnectorProvider.HOST);
103         final int port = Integer.parseInt((String JavaDoc)m.get(JMXConnectorProvider.PORT));
104         return ( new JMXServiceURL JavaDoc(protocol, host, port) );
105     }
106 }
107
Popular Tags