KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.config.serverbeans.ServerTags;
28
29 import javax.management.MBeanServerConnection JavaDoc;
30 import javax.management.ObjectName JavaDoc;
31 import java.util.List JavaDoc;
32
33 public class ListMBeansCommand extends GenericCommand
34 {
35     private final static String JavaDoc ENABLED_OPERATION = "isMBeanEnabled";
36     /**
37      * An abstract method that Executes the command
38      * @throws CommandException
39      */

40     public void runCommand() throws CommandException, CommandValidationException
41     {
42         if (!validateOptions())
43             throw new CommandValidationException("Validation is false");
44
45             //use http connector
46
MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
47                                                               getUser(), getPassword());
48         final String JavaDoc objectName = getObjectName();
49         final Object JavaDoc[] params = getParamsInfo();
50         final String JavaDoc operationName = getOperationName();
51         final String JavaDoc[] types = getTypesInfo();
52
53         try
54         {
55         //if (System.getProperty("Debug") != null) printDebug(mbsc, objectName);
56
List JavaDoc returnValue = (List JavaDoc) mbsc.invoke(new ObjectName JavaDoc(objectName),
57                          operationName, params, types);
58             if (returnValue.size() == 0)
59             {
60                 CLILogger.getInstance().printDetailMessage(
61                                             getLocalizedString("NoElementsToList"));
62             }
63             ObjectName JavaDoc objName;
64             String JavaDoc target = getOperands().size() > 0 ?
65                             (String JavaDoc) getOperands().get(0):null;
66             CLILogger.getInstance().printDebugMessage("target = " + target);
67             CLILogger.getInstance().printDebugMessage("list size = " + returnValue.size());
68             
69             for (int ii=0; ii<returnValue.size(); ii++)
70             {
71                 objName = (ObjectName JavaDoc) returnValue.get(ii);
72                 CLILogger.getInstance().printDebugMessage("objName = " + objName.toString());
73                 String JavaDoc mbeanName = (String JavaDoc) mbsc.getAttribute(objName, ServerTags.NAME);
74                 String JavaDoc mbeanObjName = (String JavaDoc) mbsc.getAttribute(objName,
75                                                                 ServerTags.OBJECT_NAME);
76                 final String JavaDoc boolVal = (String JavaDoc) mbsc.getAttribute(objName, ServerTags.ENABLED);
77                 boolean enabled = Boolean.valueOf(boolVal);
78
79                 //CLILogger.getInstance().printDebugMessage("enabled = " + enabled);
80
String JavaDoc printString = mbeanName + " " + mbeanObjName + " " +
81                                         (enabled ? getLocalizedString("Enabled")
82                                                 : getLocalizedString("Disabled"));
83                 CLILogger.getInstance().printMessage(printString);
84             }
85             
86         CLILogger.getInstance().printDetailMessage(getLocalizedString(
87                                "CommandSuccessful",
88                                new Object JavaDoc[] {name}));
89         }
90         catch(Exception JavaDoc e)
91         {
92             displayExceptionMessage(e);
93         }
94     }
95 }
96
Popular Tags