1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 28 import javax.management.ObjectName ; 29 import javax.management.MBeanServerConnection ; 30 import com.sun.enterprise.admin.common.ObjectNames; 31 32 import java.io.File ; 34 import java.util.Iterator ; 35 36 40 public class ListSubComponentsCommand extends S1ASCommand 41 { 42 private static final String GET_MODULE_COMPONENTS = "getModuleComponents"; 43 private static final String APPNAME_OPTION = "appname"; 44 private static final String TYPE_OPTION = "type"; 45 private static final String EJBS = "ejbs"; 46 private static final String SERVLETS = "servlets"; 47 private static final String EJB_SUB_MODULE = "EJBModule|SessionBean|StatelessSessionBean|StatefulSessionBean|MessageDrivenBean|EntityBean"; 48 private static final String SERVLET_SUB_MODULE = "WebModule|Servlet"; 49 private static final String TYPE_OPTION_VALUES = "ejbs|servlets"; 50 51 58 public boolean validateOptions() throws CommandValidationException 59 { 60 final String typeOption = getOption(TYPE_OPTION); 62 if ((typeOption != null) && !typeOption.matches(TYPE_OPTION_VALUES)) 63 throw new CommandValidationException(getLocalizedString( 64 "InvalidTypeOption")); 65 return super.validateOptions(); 66 } 67 68 69 73 public void runCommand() 74 throws CommandException, CommandValidationException 75 { 76 validateOptions(); 77 78 final String objectName = getObjectName(); 79 final String appname = getOption(APPNAME_OPTION); 80 final String typeOption = getOption(TYPE_OPTION); 81 final Object [] params = getParams(appname); 82 final String [] types = getTypes(appname); 83 84 final MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 86 getUser(), getPassword()); 87 try 88 { 89 91 Object returnValue = mbsc.invoke(new ObjectName (objectName), 92 GET_MODULE_COMPONENTS, params, types); 93 printObjectName(returnValue, typeOption); 94 CLILogger.getInstance().printDetailMessage(getLocalizedString( 95 "CommandSuccessful", 96 new Object [] {name})); 97 } 98 catch(Exception e) 99 { 100 if (e.getLocalizedMessage() != null) 101 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 102 throw new CommandException(getLocalizedString("CommandUnSuccessful", 103 new Object [] {name} ), e); 104 } 105 } 106 107 108 114 private Object [] getParams(String appname) 115 { 116 if (appname == null) 117 { 118 return new Object [] {(String )getOperands().get(0)}; 119 } 120 else 121 { 122 return new Object [] {appname, (String )getOperands().get(0)}; 123 } 124 } 125 126 127 133 private String [] getTypes(String appname) 134 { 135 if (appname == null) 136 { 137 return new String [] {String .class.getName()}; 138 } 139 else 140 { 141 return new String [] {String .class.getName(), String .class.getName()}; 142 } 143 } 144 145 146 150 private void printObjectName(Object returnValue, String typeOption) 151 throws CommandException 152 { 153 if (returnValue == null) 154 { 155 CLILogger.getInstance().printDetailMessage( 156 getLocalizedString("NoElementsToList")); 157 } 158 try 159 { 160 if (returnValue.getClass().getName().equals(STRING_ARRAY)) 161 { 162 final String [] objs = (String [])returnValue; 163 boolean nothingToList = true; 164 165 for (int ii=0; ii<objs.length; ii++) 166 { 167 CLILogger.getInstance().printDebugMessage("***** " + objs[ii]); 168 final ObjectName on = new ObjectName (objs[ii]); 169 if (typeOption != null) 170 { 171 if ((typeOption.equals(EJBS) && 172 on.getKeyProperty("j2eeType").matches(EJB_SUB_MODULE)) || 173 (typeOption.equals(SERVLETS) && 174 on.getKeyProperty("j2eeType").matches(SERVLET_SUB_MODULE))) 175 { 176 printSubComponent(on); 177 nothingToList=false; 178 } 179 } 180 else 181 { 182 printSubComponent(on); 183 nothingToList=false; 184 } 185 } 186 if (nothingToList) 187 { 188 CLILogger.getInstance().printDetailMessage( 189 getLocalizedString("NoElementsToList")); 190 } 191 } 192 } 193 catch (Exception e) 194 { 195 throw new CommandException(e); 196 } 197 } 198 199 200 203 private void printSubComponent(ObjectName on) 204 { 205 CLILogger.getInstance().printMessage(on.getKeyProperty("name") + " <"+ 206 on.getKeyProperty("j2eeType") + ">"); 207 } 208 209 210 213 private void printDebug(MBeanServerConnection mbsc, String objectName) 214 throws Exception 215 { 216 CLILogger.getInstance().printDebugMessage("********** getMBeanInfo **********"); 217 final javax.management.MBeanInfo mbinfo = mbsc.getMBeanInfo(new ObjectName (objectName)); 218 CLILogger.getInstance().printDebugMessage("Description = " + mbinfo.getDescription()); 219 CLILogger.getInstance().printDebugMessage("Classname = " + mbinfo.getClassName()); 220 final javax.management.MBeanOperationInfo [] mboinfo = mbinfo.getOperations(); 221 for (int ii=0; ii<mboinfo.length; ii++) 222 { 223 CLILogger.getInstance().printDebugMessage("("+ii+") Description = " + 224 mboinfo[ii].getDescription()); 225 CLILogger.getInstance().printDebugMessage("("+ii+") Name = " + 226 mboinfo[ii].getName()); 227 CLILogger.getInstance().printDebugMessage("****** TYPE *****"); 228 final javax.management.MBeanParameterInfo [] mbpi = mboinfo[ii].getSignature(); 229 for (int kk=0; kk<mbpi.length; kk++) 230 { 231 CLILogger.getInstance().printDebugMessage("type = " + mbpi[kk].getType()); 232 } 233 CLILogger.getInstance().printDebugMessage("returnType = " + mboinfo[ii].getReturnType()); 234 } 235 } 236 237 238 } 239 | Popular Tags |