com.sun.enterprise.admin.cli.remote
Class RemoteCommand

java.lang.Object
  extended by com.sun.enterprise.admin.cli.CLICommand
      extended by com.sun.enterprise.admin.cli.remote.RemoteCommand
All Implemented Interfaces:
org.jvnet.hk2.component.PostConstruct

public class RemoteCommand
extends CLICommand

A remote command handled by the asadmin CLI.


Nested Class Summary
private  class RemoteCommand.CLIRemoteAdminCommand
          A special RemoteAdminCommand that overrides methods so that we can handle the interactive requirements of a CLI command.
 
Field Summary
private  java.util.Map<java.lang.String,java.lang.String> attrs
           
private static org.jvnet.hk2.component.Habitat manHabitat
          A habitat just for finding man pages.
private static java.lang.ClassLoader moduleClassLoader
          A class loader for the "modules" directory.
private  java.lang.String output
           
private  java.io.File outputDir
           
private  RemoteCommand.CLIRemoteAdminCommand rac
           
private  java.lang.String responseFormatType
           
private  boolean returnAttributes
           
private  boolean returnOutput
           
private static LocalStringsImpl strings
           
private  java.lang.String usage
           
private  java.io.OutputStream userOut
           
 
Fields inherited from class com.sun.enterprise.admin.cli.CLICommand
argv, commandModel, CONNECTION_ERROR, env, ERROR, INVALID_COMMAND_ERROR, logger, metadataErrors, name, operands, options, passwords, programOpts, SUCCESS, WARNING
 
Constructor Summary
RemoteCommand()
          Construct a new remote command object.
RemoteCommand(java.lang.String name, ProgramOptions po, Environment env)
          Construct a new remote command object.
RemoteCommand(java.lang.String name, ProgramOptions po, Environment env, java.lang.String responseFormatType, java.io.OutputStream userOut)
          Construct a new remote command object.
 
Method Summary
protected  boolean checkHelp()
          We do all our help processing in executeCommand.
 java.util.Map<java.lang.String,java.lang.String> executeAndReturnAttributes(java.lang.String... args)
          Execute the command and return the main attributes from the manifest instead of writing out the output.
 java.lang.String executeAndReturnOutput(java.lang.String... args)
          Execute the command and return the output as a string instead of writing it out.
protected  int executeCommand()
          Runs the command using the specified arguments.
private static java.lang.String getCommandClass(java.lang.String cmdName)
          Given a command name, return the name of the class that implements that command in the server.
private  java.io.BufferedReader getLocalManPage()
          Try to find a local version of the man page for this command.
private static org.jvnet.hk2.component.Habitat getManHabitat()
          Return a Habitat used just for reading man pages from the modules in the modules directory.
 java.io.BufferedReader getManPage()
          Get the man page from the server.
private static java.lang.ClassLoader getModuleClassLoader()
          Return a ClassLoader that loads classes from all the modules (jar files) in the /modules directory.
 java.lang.String getUsage()
          Get the usage text.
private  CommandModel helpModel()
          Return a CommandModel that only includes the --help option.
private  void initializeAuth()
           
private  void initializeRemoteAdminCommand()
           
protected  void prepare()
          The prepare method must ensure that the commandModel field is set.
 void setFileOutputDirectory(java.io.File dir)
          Set the directory in which any returned files will be stored.
protected  void validate()
          If it's a help request, don't prompt for any missing options.
 
Methods inherited from class com.sun.enterprise.admin.cli.CLICommand
execute, getBooleanOption, getCommand, getName, getOperandModel, getOption, getPassword, getProgramOptions, getSystemProperties, getSystemProperty, initializeLogger, initializePasswords, inject, ok, parse, postConstruct, prevalidate, printExceptionStackTrace, processProgramOptions, quote, readPassword, toString, usageOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

strings

private static final LocalStringsImpl strings

returnOutput

private boolean returnOutput

output

private java.lang.String output

returnAttributes

private boolean returnAttributes

attrs

private java.util.Map<java.lang.String,java.lang.String> attrs

usage

private java.lang.String usage

responseFormatType

private java.lang.String responseFormatType

userOut

private java.io.OutputStream userOut

outputDir

private java.io.File outputDir

rac

private RemoteCommand.CLIRemoteAdminCommand rac

moduleClassLoader

private static java.lang.ClassLoader moduleClassLoader
A class loader for the "modules" directory.


manHabitat

private static org.jvnet.hk2.component.Habitat manHabitat
A habitat just for finding man pages.

Constructor Detail

RemoteCommand

public RemoteCommand()
              throws CommandException
Construct a new remote command object. The command and arguments are supplied later using the execute method in the superclass.

Throws:
CommandException

RemoteCommand

public RemoteCommand(java.lang.String name,
                     ProgramOptions po,
                     Environment env)
              throws CommandException
Construct a new remote command object. The command and arguments are supplied later using the execute method in the superclass.

Throws:
CommandException

RemoteCommand

public RemoteCommand(java.lang.String name,
                     ProgramOptions po,
                     Environment env,
                     java.lang.String responseFormatType,
                     java.io.OutputStream userOut)
              throws CommandException
Construct a new remote command object. The command and arguments are supplied later using the execute method in the superclass. This variant is used by the RemoteDeploymentFacility class to control and capture the output.

Throws:
CommandException
Method Detail

setFileOutputDirectory

public void setFileOutputDirectory(java.io.File dir)
Set the directory in which any returned files will be stored. The default is the user's home directory.


prepare

protected void prepare()
                throws CommandException,
                       CommandValidationException
Description copied from class: CLICommand
The prepare method must ensure that the commandModel field is set.

Overrides:
prepare in class CLICommand
Throws:
CommandException
CommandValidationException

validate

protected void validate()
                 throws CommandException,
                        CommandValidationException
If it's a help request, don't prompt for any missing options.

Overrides:
validate in class CLICommand
Throws:
CommandException - if execution of the command fails
CommandValidationException - if there's something wrong with the options or arguments

checkHelp

protected boolean checkHelp()
                     throws CommandException,
                            CommandValidationException
We do all our help processing in executeCommand.

Overrides:
checkHelp in class CLICommand
Throws:
CommandException
CommandValidationException

executeCommand

protected int executeCommand()
                      throws CommandException,
                             CommandValidationException
Runs the command using the specified arguments.

Specified by:
executeCommand in class CLICommand
Returns:
the exit code
Throws:
CommandException - if execution of the command fails
CommandValidationException - if there's something wrong with the options or arguments

executeAndReturnOutput

public java.lang.String executeAndReturnOutput(java.lang.String... args)
                                        throws CommandException,
                                               CommandValidationException
Execute the command and return the output as a string instead of writing it out.

Throws:
CommandException
CommandValidationException

executeAndReturnAttributes

public java.util.Map<java.lang.String,java.lang.String> executeAndReturnAttributes(java.lang.String... args)
                                                                            throws CommandException,
                                                                                   CommandValidationException
Execute the command and return the main attributes from the manifest instead of writing out the output.

Throws:
CommandException
CommandValidationException

getUsage

public java.lang.String getUsage()
Get the usage text. If we got usage information from the server, use it.

Overrides:
getUsage in class CLICommand
Returns:
usage text

getManPage

public java.io.BufferedReader getManPage()
Get the man page from the server. If the man page isn't available, e.g., because the server is down, try to find it locally by looking in the modules directory.

Overrides:
getManPage in class CLICommand

helpModel

private CommandModel helpModel()
Return a CommandModel that only includes the --help option.


getLocalManPage

private java.io.BufferedReader getLocalManPage()
Try to find a local version of the man page for this command.


initializeRemoteAdminCommand

private void initializeRemoteAdminCommand()
                                   throws CommandException
Throws:
CommandException

initializeAuth

private void initializeAuth()
                     throws CommandException
Throws:
CommandException

getCommandClass

private static java.lang.String getCommandClass(java.lang.String cmdName)
Given a command name, return the name of the class that implements that command in the server.


getManHabitat

private static org.jvnet.hk2.component.Habitat getManHabitat()
Return a Habitat used just for reading man pages from the modules in the modules directory.


getModuleClassLoader

private static java.lang.ClassLoader getModuleClassLoader()
Return a ClassLoader that loads classes from all the modules (jar files) in the /modules directory.



Copyright © 2012 GlassFish Community. All Rights Reserved.