1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 import com.sun.appserv.server.util.Version; 28 import javax.management.MBeanServerConnection ; 29 import javax.management.ObjectName ; 30 import java.io.IOException ; 31 32 33 37 public class VersionCommand extends S1ASCommand 38 { 39 private static final String VERBOSE = "verbose"; 40 private static final String FULL_VERSION_ATTR = "applicationServerFullVersion"; 41 private static final String SHORT_VERSION_ATTR = "applicationServerVersion"; 42 43 50 public boolean validateOptions() throws CommandValidationException 51 { 52 return super.validateOptions(); 53 } 54 55 59 public void runCommand() throws CommandException, CommandValidationException 60 { 61 if (!validateOptions()) 65 return; 66 67 String objectName = getObjectName(); 68 try 69 { 70 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 72 getUser(), getPassword()); 73 74 String attribute; 77 if (getBooleanOption("verbose")) 78 attribute = FULL_VERSION_ATTR; 79 else 80 attribute = SHORT_VERSION_ATTR; 81 82 Object returnValue = mbsc.getAttribute(new ObjectName (objectName), 83 attribute); 84 CLILogger.getInstance().printMessage(getLocalizedString("Version", 86 new Object [] {returnValue})); 87 CLILogger.getInstance().printDetailMessage(getLocalizedString( 88 "CommandSuccessful", 89 new Object [] {name})); 90 } 91 catch (IOException ioe) 92 { 93 displayVersionLocally(); 94 } 95 catch (CommandValidationException cve) 96 { 97 displayVersionLocally(); 98 } 99 catch(Exception e) 100 { 101 if (e.getLocalizedMessage() != null) 102 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 103 throw new CommandException(getLocalizedString("CommandUnSuccessful", 104 new Object [] {name} ), e); 105 } 106 } 107 108 111 private void displayVersionLocally() 112 { 113 CLILogger.getInstance().printDetailMessage(getLocalizedString("UnableToCommunicateWithAdminServer")); 116 117 if (getBooleanOption("verbose")) 118 CLILogger.getInstance().printMessage(getLocalizedString("Version", 119 new Object [] {Version.getFullVersion()})); 120 else 121 CLILogger.getInstance().printMessage(getLocalizedString("Version", 122 new Object [] {Version.getVersion()})); 123 CLILogger.getInstance().printDetailMessage(getLocalizedString( 124 "CommandSuccessful", 125 new Object [] {name})); 126 } 127 128 129 132 private void printDebug(MBeanServerConnection mbsc, String objectName) 133 throws Exception 134 { 135 CLILogger.getInstance().printDebugMessage("********** getMBeanInfo **********"); 136 final javax.management.MBeanInfo mbinfo = mbsc.getMBeanInfo(new ObjectName (objectName)); 137 CLILogger.getInstance().printDebugMessage("Description = " + mbinfo.getDescription()); 138 CLILogger.getInstance().printDebugMessage("Classname = " + mbinfo.getClassName()); 139 final javax.management.MBeanOperationInfo [] mboinfo = mbinfo.getOperations(); 140 for (int ii=0; ii<mboinfo.length; ii++) 141 { 142 CLILogger.getInstance().printDebugMessage("("+ii+") Description = " + 143 mboinfo[ii].getDescription()); 144 CLILogger.getInstance().printDebugMessage("("+ii+") Name = " + 145 mboinfo[ii].getName()); 146 CLILogger.getInstance().printDebugMessage("****** TYPE *****"); 147 final javax.management.MBeanParameterInfo [] mbpi = mboinfo[ii].getSignature(); 148 for (int kk=0; kk<mbpi.length; kk++) 149 { 150 CLILogger.getInstance().printDebugMessage("type = " + mbpi[kk].getType()); 151 } 152 CLILogger.getInstance().printDebugMessage("returnType = " + mboinfo[ii].getReturnType()); 153 154 155 } 156 } 157 158 159 168 protected String getUser() throws CommandValidationException 169 { 170 String userValue = getOption(USER); 171 if (userValue == null) 172 { 173 userValue = getUserFromASADMINPASS(); 175 176 if (userValue == null) 178 userValue= getValuesFromASADMINPREFS(USER); 179 if (userValue != null) 180 { 181 CLILogger.getInstance().printDebugMessage( 182 "user value read from " + ASADMINPREFS); 183 } 184 } 185 return userValue; 186 } 187 188 189 194 protected String getPassword() throws CommandValidationException, CommandException 195 { 196 return getPassword(PASSWORD, "AdminPasswordPrompt", "AdminPasswordConfirmationPrompt", 199 true, true, false, false, null, null, false, false, false, true); 200 } 201 202 203 } 204 | Popular Tags |