KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > GenericCommand


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.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27 import javax.management.Attribute JavaDoc;
28 import javax.management.AttributeList JavaDoc;
29 import javax.management.remote.JMXServiceURL JavaDoc;
30 import javax.management.remote.JMXConnector JavaDoc;
31 import javax.management.remote.JMXConnectorFactory JavaDoc;
32 import javax.management.MBeanServerConnection JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34 import javax.management.MalformedObjectNameException JavaDoc;
35 import javax.management.InstanceNotFoundException JavaDoc;
36 import javax.management.IntrospectionException JavaDoc;
37 import javax.management.ReflectionException JavaDoc;
38
39 import java.util.Vector JavaDoc;
40 import java.net.MalformedURLException JavaDoc;
41 import java.io.IOException JavaDoc;
42 import java.util.StringTokenizer JavaDoc;
43
44 /**
45  * This is a sample Deploy command
46  * @version $Revision: 1.5 $
47  */

48 public class GenericCommand extends S1ASCommand
49 {
50
51     /**
52      * An abstract method that validates the options
53      * on the specification in the xml properties file
54      * This method verifies for the correctness of number of
55      * operands and if all the required options are supplied by the client.
56      * @return boolean returns true if success else returns false
57      */

58     public boolean validateOptions() throws CommandValidationException
59     {
60         return super.validateOptions();
61     }
62    
63     /**
64      * An abstract method that Executes the command
65      * @throws CommandException
66      */

67     public void runCommand() throws CommandException, CommandValidationException
68     {
69         if (!validateOptions())
70             throw new CommandValidationException("Validation is false");
71             //use http connector
72
MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
73                                                               getUser(), getPassword());
74         final String JavaDoc objectName = getObjectName();
75         final Object JavaDoc[] params = getParamsInfo();
76         final String JavaDoc operationName = getOperationName();
77         final String JavaDoc[] types = getTypesInfo();
78
79         try
80         {
81         //if (System.getProperty("Debug") != null) printDebug(mbsc, objectName);
82
Object JavaDoc returnValue = mbsc.invoke(new ObjectName JavaDoc(objectName),
83                          operationName, params, types);
84             handleReturnValue(returnValue);
85         CLILogger.getInstance().printDetailMessage(getLocalizedString(
86                                "CommandSuccessful",
87                                new Object JavaDoc[] {name}));
88         }
89         catch(Exception JavaDoc e)
90         {
91             displayExceptionMessage(e);
92         }
93     }
94
95
96     private void printDebug(MBeanServerConnection JavaDoc mbsc, String JavaDoc objectName)
97     throws Exception JavaDoc
98     {
99         CLILogger.getInstance().printDebugMessage("********** queryNames **********");
100         CLILogger.getInstance().printDebugMessage("LIST OF ALL REGISTERED MBEANS:");
101         final java.util.Set JavaDoc allMBeans = mbsc.queryNames( null, null);
102         int jj=1;
103         for (java.util.Iterator JavaDoc ii = allMBeans.iterator(); ii.hasNext(); ) {
104             ObjectName JavaDoc name = (ObjectName JavaDoc) ii.next();
105             CLILogger.getInstance().printDebugMessage("("+ jj++ + ") " + name.toString());
106         }
107
108
109         CLILogger.getInstance().printDebugMessage("********** getMBeanInfo **********");
110         final javax.management.MBeanInfo JavaDoc mbinfo = mbsc.getMBeanInfo(new ObjectName JavaDoc(objectName));
111         CLILogger.getInstance().printDebugMessage("Description = " + mbinfo.getDescription());
112         CLILogger.getInstance().printDebugMessage("Classname = " + mbinfo.getClassName());
113         final javax.management.MBeanOperationInfo JavaDoc[] mboinfo = mbinfo.getOperations();
114         for (int ii=0; ii<mboinfo.length; ii++)
115         {
116             CLILogger.getInstance().printDebugMessage("("+ii+") Description = " +
117                                                       mboinfo[ii].getDescription());
118             CLILogger.getInstance().printDebugMessage("("+ii+") Name = " +
119                                                       mboinfo[ii].getName());
120         }
121
122     }
123
124 }
125
Popular Tags