1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 28 import javax.management.MBeanServerConnection ; 29 import javax.management.ObjectName ; 30 31 import com.sun.appserv.management.util.misc.ExceptionUtil; 32 import com.sun.appserv.management.base.Util; 33 import javax.management.MalformedObjectNameException ; 34 import java.lang.NullPointerException ; 35 import javax.management.RuntimeOperationsException ; 36 37 import java.util.Map ; 38 import java.util.Set ; 39 import java.util.Iterator ; 40 import java.lang.IllegalArgumentException ; 41 import java.io.File ; 42 import java.io.IOException ; 43 44 45 46 49 public class AMXDeleteResourceCommand extends S1ASCommand 50 { 51 public final static String DOMAIN_CONFIG_OBJECT_NAME = "amx:j2eeType=X-DomainConfig,name=na"; 52 public final static String SERVER_CONFIG_OBJECT_NAME = "amx:j2eeType=X-StandaloneServerConfig,name="; 53 public final static String CLUSTER_CONFIG_OBJECT_NAME = "amx:j2eeType=X-ClusterConfig,name="; 54 public final static String TARGET_NAME = "target"; 55 56 63 public boolean validateOptions() throws CommandValidationException 64 { 65 return super.validateOptions(); 66 } 67 68 72 public void runCommand() throws CommandException, CommandValidationException 73 { 74 if (!validateOptions()) 75 throw new CommandValidationException("Validation is false"); 76 77 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 79 getUser(), getPassword()); 80 final String targetName = (String )getOption(TARGET_NAME); 81 82 ObjectName scON = (targetName!=null && !targetName.equals(DOMAIN))? 86 getTargetConfigObjectName(mbsc, targetName):null; 87 88 final Object [] params = getParamsInfo(); 89 final String operationName = getOperationName(); 90 final String [] types = getTypesInfo(); 91 92 try { 93 if (scON!=null) 94 { 95 mbsc.invoke(scON, "removeResourceRefConfig", 97 new Object []{new String ((String )getOperands().get(0))}, 98 new String []{"java.lang.String"} ); 99 100 } 101 Object returnValue = mbsc.invoke(Util.newObjectName(DOMAIN_CONFIG_OBJECT_NAME), 102 operationName, 103 params, types); 104 CLILogger.getInstance().printDetailMessage(getLocalizedString( 105 "CommandSuccessful", 106 new Object [] {name})); 107 } 108 catch (Exception e) { 109 displayExceptionMessage(e); 110 } 111 112 113 } 114 115 116 124 public void displayExceptionMessage(Exception e) throws CommandException 125 { 126 128 Throwable rootException = ExceptionUtil.getRootCause(e); 129 130 if (rootException.getLocalizedMessage() != null) 131 CLILogger.getInstance().printDetailMessage(rootException.getLocalizedMessage()); 132 throw new CommandException(getLocalizedString("CommandUnSuccessful", 133 new Object [] {name} ), e); 134 135 } 136 137 138 139 146 private ObjectName getTargetConfigObjectName(final MBeanServerConnection mbsc, 147 final String targetName) 148 throws CommandException 149 { 150 151 try { 152 ObjectName scON = Util.newObjectName(SERVER_CONFIG_OBJECT_NAME+targetName); 153 if (!mbsc.isRegistered(scON)) 154 scON = Util.newObjectName(CLUSTER_CONFIG_OBJECT_NAME+targetName); 155 if (!mbsc.isRegistered(scON)) 156 throw new CommandException(getLocalizedString("InvalidTargetName")); 157 158 return scON; 159 } 160 catch (RuntimeOperationsException roe) 161 { 162 throw new CommandException(roe); 163 } 164 catch (IOException ioe) 165 { 166 throw new CommandException(ioe); 167 } 168 } 169 170 } 171 | Popular Tags |