KickJava   Java API By Example, From Geeks To Geeks.

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


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.ObjectName JavaDoc;
30 import javax.management.MBeanServerConnection JavaDoc;
31 import javax.management.MalformedObjectNameException JavaDoc;
32 import javax.management.InstanceNotFoundException JavaDoc;
33 import javax.management.IntrospectionException JavaDoc;
34 import javax.management.ReflectionException JavaDoc;
35
36
37 import java.util.Vector JavaDoc;
38 import java.io.IOException JavaDoc;
39 import java.util.StringTokenizer JavaDoc;
40
41 /**
42  * This is to find out if IMQ is alive or not
43  * @version $Revision: 1.3 $
44  */

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

55     public boolean validateOptions() throws CommandValidationException
56     {
57         return super.validateOptions();
58     }
59    
60     /**
61      * Executes the command
62      * @throws CommandException
63      */

64     public void runCommand() throws CommandException, CommandValidationException
65     {
66         if (!validateOptions())
67             throw new CommandValidationException("Validation is false");
68         String JavaDoc objectName = getObjectName();
69         Object JavaDoc[] params = getParamsInfo();
70         String JavaDoc operationName = getOperationName();
71         String JavaDoc[] types = getTypesInfo();
72
73     MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(),
74                                   getPort(),
75                                   getUser(),
76                                   getPassword());
77
78         try
79         {
80             String JavaDoc returnValue = (String JavaDoc) mbsc.invoke(new ObjectName JavaDoc(objectName),
81                                      operationName, params, types);
82         CLILogger.getInstance().printMessage(getLocalizedString(
83                                                     "JMSPingStatus",
84                                                     new Object JavaDoc[] {returnValue}));
85             // Ping was successful
86
CLILogger.getInstance().printDetailMessage(getLocalizedString(
87                                "CommandSuccessful",
88                                new Object JavaDoc[] {name}));
89         }
90         catch(Exception JavaDoc e)
91         {
92         if (e.getLocalizedMessage() != null)
93         CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
94             throw new CommandException(getLocalizedString("CommandUnSuccessful",
95                              new Object JavaDoc[] {name} ), e);
96         }
97     }
98
99 }
100
Popular Tags