KickJava   Java API By Example, From Geeks To Geeks.

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


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 CreateManagementRuleCommand extends GenericCommand
35 {
36     private static final String JavaDoc RULE_DESCRIPTION_OPTION = "ruledescription";
37     private static final String JavaDoc RULE_ENABLED_OPTION = "ruleenabled";
38     private static final String JavaDoc EVENT_TYPE_OPTION = "eventtype";
39     private static final String JavaDoc EVENT_LEVEL_OPTION = "eventlevel";
40     private static final String JavaDoc EVENT_DESCRIPTION_OPTION = "eventdescription";
41     private static final String JavaDoc EVENT_PROPERTIES_OPTION = "eventproperties";
42     private static final String JavaDoc RECORD_EVENT_OPTION = "recordevent";
43     private static final String JavaDoc ACTION_OPTION = "recordevent";
44     private static final String JavaDoc TARGET_OPTION = "target";
45
46     
47     /**
48      * An abstract method that Executes the command
49      * @throws CommandException
50      */

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

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