1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 import javax.management.Attribute ; 28 import javax.management.AttributeList ; 29 import javax.management.remote.JMXServiceURL ; 30 import javax.management.remote.JMXConnector ; 31 import javax.management.remote.JMXConnectorFactory ; 32 import javax.management.MBeanServerConnection ; 33 import javax.management.ObjectName ; 34 import javax.management.MalformedObjectNameException ; 35 import javax.management.InstanceNotFoundException ; 36 import javax.management.IntrospectionException ; 37 import javax.management.ReflectionException ; 38 import com.sun.appserv.management.client.ProxyFactory; 39 import com.sun.appserv.management.DomainRoot; 40 41 42 import java.util.Vector ; 43 import java.net.MalformedURLException ; 44 import java.io.IOException ; 45 import java.util.StringTokenizer ; 46 import java.util.Iterator ; 47 import java.util.Map ; 48 49 61 public class ListComponentsCommand extends S1ASCommand 62 { 63 private static final String TYPE_OPTION = "type"; 64 private static final String TYPE_OPTION_REG = "application|web|ejb|connector|webservice"; 65 private static final String WEBSERVICE_TYPE = "webservice"; 66 67 74 public boolean validateOptions() throws CommandValidationException 75 { 76 return super.validateOptions(); 77 } 78 79 83 public void runCommand() throws CommandException, CommandValidationException 84 { 85 if (!validateOptions()) 89 return; 90 91 String objectName = getObjectName(); 92 Object [] params = getParamsInfo(); 93 String operationName = getOperationName(); 94 String [] types = getTypesInfo(); 95 96 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 98 getUser(), getPassword()); 99 100 try 101 { 102 if (System.getProperty("Debug") != null) printDebug(mbsc, objectName); 103 String type = getTypeOption(); 105 boolean nothingToList = true; 106 if ((type != null) && (type.equals(WEBSERVICE_TYPE))) 107 { 108 nothingToList = printWebServices(mbsc); 109 } 110 else 111 { 112 Object returnValue = mbsc.invoke(new ObjectName (objectName), 113 operationName, params, types); 114 nothingToList = printDeployedComponents(returnValue); 115 if (type == null) 117 { 118 if (printWebServices(mbsc) == false) 119 nothingToList=false; 120 } 121 } 122 if (nothingToList) 123 { 124 CLILogger.getInstance().printDetailMessage( 125 getLocalizedString("NoElementsToList")); 126 } 127 CLILogger.getInstance().printDetailMessage(getLocalizedString( 128 "CommandSuccessful", 129 new Object [] {name})); 130 } 131 catch(Exception e) 132 { 133 if (e.getLocalizedMessage() != null) 134 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 135 throw new CommandException(getLocalizedString("CommandUnSuccessful", 136 new Object [] {name} ), e); 137 } 138 } 139 140 144 private boolean printDeployedComponents(Object returnValue) 145 throws CommandValidationException 146 { 147 if (returnValue == null) return true; 148 boolean nothingToList = true; 149 if (returnValue.getClass() == new ObjectName [0].getClass()) 150 { 151 final ObjectName [] objs = (ObjectName [])returnValue; 152 final String displayType = (String )((Vector )getProperty(DISPLAY_TYPE)).get(0); 153 final String type = getTypeOption(); 154 for (int ii=0; ii<objs.length; ii++) 155 { 156 final ObjectName objectName = (ObjectName )objs[ii]; 157 CLILogger.getInstance().printDebugMessage("ObjectName = " + objectName); 158 final String componentType = objectName.getKeyProperty("type"); 159 160 if ((type == null) || (componentType.indexOf(type) != -1)) 161 { 162 CLILogger.getInstance().printMessage( 163 objectName.getKeyProperty(displayType) + 164 " <" + componentType + "> " ); 165 nothingToList = false; 166 } 167 } 168 } 169 return nothingToList; 170 } 171 172 173 178 private boolean printWebServices(MBeanServerConnection mbsc) 179 { 180 DomainRoot domainRoot = ProxyFactory.getInstance(mbsc).getDomainRoot(); 181 Map map = domainRoot.getWebServiceMgr().getWebServiceEndpointKeys(); 182 Iterator keys = map.keySet().iterator(); 183 if (!keys.hasNext()) 184 return true; 185 while (keys.hasNext()) 186 CLILogger.getInstance().printMessage(keys.next().toString() + 187 " <" + WEBSERVICE_TYPE + "> "); 188 return false; 189 } 190 196 private String getTypeOption() throws CommandValidationException 197 { 198 final String type = getOption(TYPE_OPTION); 199 if (type == null) return type; 200 if (type.matches(TYPE_OPTION_REG)) 201 return type; 202 throw new CommandValidationException(getLocalizedString("InvalidTypeOption")); 203 } 204 205 206 209 private void printDebug(MBeanServerConnection mbsc, String objectName) 210 throws Exception 211 { 212 CLILogger.getInstance().printDebugMessage("********** getMBeanInfo **********"); 213 final javax.management.MBeanInfo mbinfo = mbsc.getMBeanInfo(new ObjectName (objectName)); 214 CLILogger.getInstance().printDebugMessage("Description = " + mbinfo.getDescription()); 215 CLILogger.getInstance().printDebugMessage("Classname = " + mbinfo.getClassName()); 216 final javax.management.MBeanOperationInfo [] mboinfo = mbinfo.getOperations(); 217 for (int ii=0; ii<mboinfo.length; ii++) 218 { 219 CLILogger.getInstance().printDebugMessage("("+ii+") Description = " + 220 mboinfo[ii].getDescription()); 221 CLILogger.getInstance().printDebugMessage("("+ii+") Name = " + 222 mboinfo[ii].getName()); 223 CLILogger.getInstance().printDebugMessage("****** TYPE *****"); 224 final javax.management.MBeanParameterInfo [] mbpi = mboinfo[ii].getSignature(); 225 for (int kk=0; kk<mbpi.length; kk++) 226 { 227 CLILogger.getInstance().printDebugMessage("type = " + mbpi[kk].getType()); 228 } 229 CLILogger.getInstance().printDebugMessage("returnType = " + mboinfo[ii].getReturnType()); 230 231 232 } 233 } 234 235 } 236 | Popular Tags |