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 39 import java.util.Vector ; 40 import java.net.MalformedURLException ; 41 import java.io.IOException ; 42 import java.util.StringTokenizer ; 43 44 54 public class ShowComponentStatusCommand extends S1ASCommand 55 { 56 63 public boolean validateOptions() throws CommandValidationException 64 { 65 return super.validateOptions(); 66 } 67 68 69 73 public void runCommand() throws CommandException, CommandValidationException 74 { 75 validateOptions(); 76 String objectName = getObjectName(); 77 Object [] params = getParamsInfo(); 78 String operationName = getOperationName(); 79 String [] types = getTypesInfo(); 80 81 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 83 getUser(), getPassword()); 84 85 try 86 { 87 final Object returnValue = mbsc.invoke(new ObjectName (objectName), 88 operationName, params, types); 89 displayComponentStatus(returnValue); 90 CLILogger.getInstance().printDetailMessage(getLocalizedString( 91 "CommandSuccessful", 92 new Object [] {name})); 93 } 94 catch(Exception e) 95 { 96 if (e.getLocalizedMessage() != null) 97 CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage()); 98 throw new CommandException(getLocalizedString("CommandUnSuccessful", 99 new Object [] {name} ), e); 100 } 101 } 102 103 104 109 private void displayComponentStatus(Object returnValue) 110 throws CommandException 111 { 112 final String componentName = (String ) getOperands().get(0); 113 if (returnValue == null) 114 throw new CommandException(getLocalizedString("UndetermineStatus", 115 new Object [] {componentName})); 116 else 117 { 118 final String returnValClassName = returnValue.getClass().getName(); 120 if (returnValClassName.equals(BOOLEAN_CLASS)) 121 { 122 final boolean status = ((Boolean )returnValue).booleanValue(); 123 if (status) 124 CLILogger.getInstance().printMessage(getLocalizedString( 125 "ComponentIsEnabled", new Object [] {componentName})); 126 else 127 CLILogger.getInstance().printMessage(getLocalizedString( 128 "ComponentIsDisabled", new Object [] {componentName})); 129 } 130 else 131 throw new CommandException(getLocalizedString("UndetermineStatus", 132 new Object [] {componentName})); 133 } 134 } 135 136 } 137 | Popular Tags |