FileDocCategorySizeDatePackage
BaseLoggingCommand.javaAPI DocGlassfish v2 API5442Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

BaseLoggingCommand

public abstract class BaseLoggingCommand extends S1ASCommand
author
prashanth

Fields Summary
private static final String
TARGET_OPTION
Constructors Summary
Methods Summary
public voidrunCommand()
method that Executes the command

throws
CommandException


                  
         
    
        validateOptions();
        try        
        {
            //use http connector
            final MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(),
                                                                  getUser(), getPassword());
            final String instanceName = getOption(TARGET_OPTION);
            verifyTargetInstance(mbsc, instanceName);
            final String objectName = getObjectName();
            final Object[] params = getParamsInfo();
            final String operationName = getOperationName();
            final String[] types = getTypesInfo();

            //if (System.getProperty("Debug") != null) printDebug(mbsc, objectName);
            Object returnValue = mbsc.invoke(new ObjectName(objectName),
                                             operationName, params, types);
            handleReturnValue(returnValue);
            CLILogger.getInstance().printDetailMessage(getLocalizedString(
                                                       "CommandSuccessful",
                                                       new Object[] {name}));
        }
        catch(Exception e)
        {
            displayExceptionMessage(e);
        }
    
protected voidverifyTargetInstance(javax.management.MBeanServerConnection mbsc, java.lang.String instanceName)

        try 
        {
            final DomainRoot domainRoot = 
                    ProxyFactory.getInstance(mbsc).getDomainRoot();
            boolean isServer=false;
            isServer = domainRoot.getDomainConfig().getServerConfigMap().keySet().contains(instanceName);
            if ( ! isServer ) 
            {
                throw new CommandException(getLocalizedString("TargetNotAnInstance", 
                                                     new Object[] {instanceName}));
            }
            else
            {
                final Map<String,J2EEServer> servers =
                    domainRoot.getJ2EEDomain().getJ2EEServerMap();
                final J2EEServer server = servers.get( instanceName );

                final boolean running = server != null &&
                                    server.getstate() == server.STATE_RUNNING || 
                                    server.getstate() == server.STATE_STARTING;
                if (!running)
                    throw new CommandException(getLocalizedString("InstanceNotRunning",
                                                      new Object[] {instanceName}));
            }        
        }
        catch (Exception e)
        {
            throw new CommandException(e);
        }