KickJava   Java API By Example, From Geeks To Geeks.

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


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 DeleteManagementRuleCommand extends GenericCommand
35 {
36     private static final String JavaDoc TARGET_OPTION = "target";
37
38     
39     /**
40      * An abstract method that Executes the command
41      * @throws CommandException
42      */

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

81     private String JavaDoc resolveTargetToConfig(MBeanServerConnection JavaDoc mbsc,
82                                 String JavaDoc target) throws CommandException
83     {
84         String JavaDoc objectName = "com.sun.appserv:type=configs,category=config";
85         final Object JavaDoc[] params = new Object JavaDoc[] {target};
86         final String JavaDoc operationName = "getConfigNameForTarget";
87         final String JavaDoc[] types = new String JavaDoc[] {"java.lang.String"};
88
89         try
90         {
91             String JavaDoc returnValue = (String JavaDoc) mbsc.invoke(
92                                             new ObjectName JavaDoc(objectName),
93                                             operationName, params, types);
94             return (returnValue);
95         }
96         catch(Exception JavaDoc e)
97         {
98             throw new CommandException(e.getLocalizedMessage());
99         }
100     
101     }
102 }
103
Popular Tags