KickJava   Java API By Example, From Geeks To Geeks.

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


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.AttributeList JavaDoc;
28 import javax.management.Attribute JavaDoc;
29 import javax.management.MBeanServerConnection JavaDoc;
30 import javax.management.ObjectName JavaDoc;
31 import java.util.Properties JavaDoc;
32 import java.util.Enumeration JavaDoc;
33
34 public class ListManagementRulesCommand extends GenericCommand
35 {
36     private static final String JavaDoc DEFAULT_TARGET = "server";
37    
38     /**
39      * An abstract method that Executes the command
40      * @throws CommandException
41      */

42     public void runCommand() throws CommandException, CommandValidationException
43     {
44         validateOptions();
45         MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(), getPort(),
46                                                               getUser(), getPassword());
47         String JavaDoc config = resolveTargetToConfig(mbsc);
48         String JavaDoc objectName = "com.sun.appserv:type=management-rules,config=" +
49                             config + ",category=config";
50         CLILogger.getInstance().printDebugMessage("ObjectName = " + objectName);
51         //use http connector
52
final String JavaDoc operationName = getOperationName();
53
54         try
55         {
56             Object JavaDoc returnValue = mbsc.invoke(new ObjectName JavaDoc(objectName),
57                                             operationName, null, null);
58             handleReturnValue(returnValue);
59         CLILogger.getInstance().printDetailMessage(getLocalizedString(
60                                "CommandSuccessful",
61                                new Object JavaDoc[] {name}));
62         }
63         catch(Exception JavaDoc e)
64         {
65             displayExceptionMessage(e);
66         }
67     
68     }
69
70
71     /**
72      * resolves the target to config name
73      * @throws CommandException
74      */

75     private String JavaDoc resolveTargetToConfig(MBeanServerConnection JavaDoc mbsc) throws CommandException
76     {
77         String JavaDoc objectName = "com.sun.appserv:type=configs,category=config";
78         String JavaDoc target = (getOperands().size() == 1) ?
79                     (String JavaDoc) getOperands().get(0) : DEFAULT_TARGET;
80         final Object JavaDoc[] params = new Object JavaDoc[] {target};
81         final String JavaDoc operationName = "getConfigNameForTarget";
82         final String JavaDoc[] types = new String JavaDoc[] {"java.lang.String"};
83
84         try
85         {
86             String JavaDoc returnValue = (String JavaDoc) mbsc.invoke(
87                                             new ObjectName JavaDoc(objectName),
88                                             operationName, params, types);
89             return (returnValue);
90         }
91         catch(Exception JavaDoc e)
92         {
93             throw new CommandException(e.getLocalizedMessage());
94         }
95     
96     }
97 }
98
Popular Tags