de.uniba.wiai.lspi.util.console
Class Command

java.lang.Object
  extended by de.uniba.wiai.lspi.util.console.Command
Direct Known Subclasses:
ChangeProtocol, CrashNodes, CreateNodes, ExecuteMacro, Exit, Help, Insert, InsertNetwork, JoinNetwork, LeaveNetwork, Remove, RemoveNetwork, Retrieve, RetrieveNetwork, ShowEntries, ShowEntriesNetwork, ShowFingerTable, ShowFingerTableNetwork, ShowNodes, ShowOutputCommand, ShowSuccessorList, ShutdownNodes, Wait

public abstract class Command
extends Object


Field Summary
protected  String HELP_ARG1
          Standard argument for displaying help of this command.
protected  String HELP_ARG2
          Alternative standard argument for displaying help of this command.
protected  PrintStream out
          The PrintStream to print the command's output to.
protected  Map<String,String> parameters
          The parameters passed to this command are contained within this Hashtable.
protected  Object[] toCommand
          The instances to execute the commands on.
 
Constructor Summary
Command(Object[] toCommand, PrintStream out)
          Creates a new instance of Command.
 
Method Summary
 void addParameter(String paramName, String paramValue)
          Add a command line parameter.
abstract  void exec()
          To be overwritten by subclasses for command execution.
 void execute()
          Executes the command.
abstract  String getCommandName()
          Return the name of the command.
abstract  void printOutHelp()
          To be overwritten.
 void setParameters(Map<String,String> parameters)
          Set the parameters for the Command.
 void setPrintStream(PrintStream out)
          Set the PrintStream, to that this command prints its output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toCommand

protected Object[] toCommand
The instances to execute the commands on.


parameters

protected Map<String,String> parameters
The parameters passed to this command are contained within this Hashtable.


HELP_ARG1

protected final String HELP_ARG1
Standard argument for displaying help of this command. If supplied all other parameters are ignored.

See Also:
Constant Field Values

HELP_ARG2

protected final String HELP_ARG2
Alternative standard argument for displaying help of this command. If supplied all other parameters are ignored.

See Also:
Constant Field Values

out

protected PrintStream out
The PrintStream to print the command's output to.

Constructor Detail

Command

public Command(Object[] toCommand,
               PrintStream out)
Creates a new instance of Command.

Parameters:
out - The java.io.PrintStream to that the command's output is printed.
toCommand - The instance to execute the command on.
Method Detail

setPrintStream

public void setPrintStream(PrintStream out)
Set the PrintStream, to that this command prints its output.

Parameters:
out - The PrintStream.

addParameter

public final void addParameter(String paramName,
                               String paramValue)
Add a command line parameter.

Parameters:
paramName - The parameters name. Cannot contain spaces.
paramValue - The parameters value. Cannot contain spaces.

execute

public final void execute()
                   throws ConsoleException
Executes the command.

Throws:
ConsoleException - Exception during execution of command.

exec

public abstract void exec()
                   throws ConsoleException
To be overwritten by subclasses for command execution. The work of a command implementation is done in this method.

Throws:
ConsoleException - Exception during execution.

printOutHelp

public abstract void printOutHelp()
To be overwritten. Display the help text of the Command.


getCommandName

public abstract String getCommandName()
Return the name of the command. Must not contain spaces. To be overwritten by subclasses.

Returns:
The commands name. For example: exit.

setParameters

public void setParameters(Map<String,String> parameters)
Set the parameters for the Command.

Parameters:
parameters - Hashtable containing the parameter names as keys and the parameter values as values. Both represented as Strings. Both must not contain spaces.


Copyright © 2004-2008 Karsten Loesing, Sven Kaffille - Distributed and Mobile Systems Group, Lehrstuhl für Praktische Informatik, Universität Bamberg. All Rights Reserved.