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 48 public class AMXCreateResourceCommand extends S1ASCommand 49 { 50 public final static String DOMAIN_CONFIG_OBJECT_NAME = "amx:j2eeType=X-DomainConfig,name=na"; 51 public final static String SERVER_CONFIG_OBJECT_NAME = "amx:j2eeType=X-StandaloneServerConfig,name="; 52 public final static String CLUSTER_CONFIG_OBJECT_NAME = "amx:j2eeType=X-ClusterConfig,name="; 53 public final static String TARGET_NAME = "target"; 54 55 62 public boolean validateOptions() throws CommandValidationException 63 { 64 return super.validateOptions(); 65 } 66 67 71 public void runCommand() throws CommandException, CommandValidationException 72 { 73 if (!validateOptions()) 74 throw new CommandValidationException("Validation is false"); 75 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 Object returnValue = mbsc.invoke(Util.newObjectName(DOMAIN_CONFIG_OBJECT_NAME), 94 operationName, 95 params, types); 96 if (scON!=null) 97 { 98 mbsc.invoke(scON, "createResourceRefConfig", 100 new Object []{new String ((String )getOperands().get(0))}, 101 new String []{"java.lang.String"} ); 102 } 103 CLILogger.getInstance().printDetailMessage(getLocalizedString( 104 "CommandSuccessful", 105 new Object [] {name})); 106 107 } 108 catch (Exception e) { 109 displayExceptionMessage(e); 110 } 111 } 112 113 121 public void displayExceptionMessage(Exception e) throws CommandException 122 { 123 Throwable rootException = ExceptionUtil.getRootCause(e); 125 126 if (rootException.getLocalizedMessage() != null) 127 CLILogger.getInstance().printDetailMessage(rootException.getLocalizedMessage()); 128 throw new CommandException(getLocalizedString("CommandUnSuccessful", 129 new Object [] {name} ), e); 130 131 } 132 133 134 141 private ObjectName getTargetConfigObjectName(final MBeanServerConnection mbsc, 142 final String targetName) 143 throws CommandException 144 { 145 try { 146 ObjectName scON = Util.newObjectName(SERVER_CONFIG_OBJECT_NAME+targetName); 147 if (!mbsc.isRegistered(scON)) 148 scON = Util.newObjectName(CLUSTER_CONFIG_OBJECT_NAME+targetName); 149 if (!mbsc.isRegistered(scON)) 150 throw new CommandException(getLocalizedString("InvalidTargetName")); 151 152 return scON; 153 } 154 catch (RuntimeOperationsException roe) 155 { 156 throw new CommandException(roe); 157 } 158 catch (IOException ioe) 159 { 160 throw new CommandException(ioe); 161 } 162 } 163 } 164 | Popular Tags |