1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 import javax.management.AttributeList ; 28 import javax.management.Attribute ; 29 import javax.management.MBeanServerConnection ; 30 import javax.management.ObjectName ; 31 import java.util.Properties ; 32 import java.util.Enumeration ; 33 34 public class CreateManagementRuleCommand extends GenericCommand 35 { 36 private static final String RULE_DESCRIPTION_OPTION = "ruledescription"; 37 private static final String RULE_ENABLED_OPTION = "ruleenabled"; 38 private static final String EVENT_TYPE_OPTION = "eventtype"; 39 private static final String EVENT_LEVEL_OPTION = "eventlevel"; 40 private static final String EVENT_DESCRIPTION_OPTION = "eventdescription"; 41 private static final String EVENT_PROPERTIES_OPTION = "eventproperties"; 42 private static final String RECORD_EVENT_OPTION = "recordevent"; 43 private static final String ACTION_OPTION = "recordevent"; 44 private static final String TARGET_OPTION = "target"; 45 46 47 51 public void runCommand() throws CommandException, CommandValidationException 52 { 53 validateOptions(); 54 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 55 getUser(), getPassword()); 56 String config = resolveTargetToConfig(mbsc, getOption(TARGET_OPTION)); 57 String objectName = "com.sun.appserv:type=management-rules,config=" + 58 config + ",category=config"; 59 CLILogger.getInstance().printDebugMessage("ObjectName = " + objectName); 60 final Object [] params = getParamsInfo(); 62 final String operationName = getOperationName(); 63 final String [] types = getTypesInfo(); 64 65 try 66 { 67 if (params[0] != null) 68 { 69 Object returnValue = mbsc.invoke(new ObjectName (objectName), 70 operationName, params, types); 71 handleReturnValue(returnValue); 72 } 73 CLILogger.getInstance().printDetailMessage(getLocalizedString( 74 "CommandSuccessful", 75 new Object [] {name})); 76 } 77 catch(Exception e) 78 { 79 displayExceptionMessage(e); 80 } 81 82 } 83 84 85 89 private String resolveTargetToConfig(MBeanServerConnection mbsc, 90 String target) throws CommandException 91 { 92 String objectName = "com.sun.appserv:type=configs,category=config"; 93 final Object [] params = new Object [] {target}; 94 final String operationName = "getConfigNameForTarget"; 95 final String [] types = new String [] {"java.lang.String"}; 96 97 try 98 { 99 String returnValue = (String ) mbsc.invoke( 100 new ObjectName (objectName), 101 operationName, params, types); 102 return (returnValue); 103 } 104 catch(Exception e) 105 { 106 throw new CommandException(e.getLocalizedMessage()); 107 } 108 109 } 110 } 111 | Popular Tags |