KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 /**
29  * This command will get the version of the application server
30  * @version $Revision: 1.4 $
31  */

32 public class GenerateJVMReportCommand extends GenericCommand
33 {
34
35     private static final String JavaDoc SUMMARY_OPERATION = "getSummary";
36     private static final String JavaDoc CLASS_OPERATION = "getClassInformation";
37     private static final String JavaDoc MEMORY_OPERATION = "getMemoryInformation";
38     private static final String JavaDoc THREADDUMP_OPERATION = "getThreadDump";
39     private static final String JavaDoc TYPE_OPTION = "type";
40     private String JavaDoc typeOption;
41
42     /**
43      * An abstract method that validates the options
44      * on the specification in the xml properties file
45      * This method verifies for the correctness of number of
46      * operands and if all the required options are supplied by the client.
47      * @return boolean returns true if success else returns false
48      */

49     public boolean validateOptions() throws CommandValidationException
50     {
51         if (!super.validateOptions())
52             return false;
53
54         typeOption = getOption(TYPE_OPTION);
55         if (typeOption.matches("summary|memory|class|thread"))
56         {
57             return true;
58         }
59         else
60         {
61               throw new CommandValidationException(getLocalizedString(
62                                                      "InvalidTypeOption"));
63         }
64     }
65
66
67     /*
68      * Returns the Operation name from the properties
69      * @return operationName returns operation name
70      */

71     protected String JavaDoc getOperationName() throws CommandException
72     {
73         String JavaDoc operationName = SUMMARY_OPERATION;
74         if (typeOption.equals("memory"))
75             operationName = MEMORY_OPERATION;
76         else if (typeOption.equals("class"))
77             operationName = CLASS_OPERATION;
78         else if (typeOption.equals("thread"))
79             operationName = THREADDUMP_OPERATION;
80         return operationName;
81     }
82
83     protected void handleReturnValue(Object JavaDoc returnval)
84     {
85         final Class JavaDoc cl = returnval.getClass();
86         if (cl.getName().equals(String JavaDoc.class.getName()))
87         {
88             final String JavaDoc returnString = (String JavaDoc)returnval;
89             CLILogger.getInstance().printMessage(returnString);
90         }
91     }
92
93 }
94
Popular Tags