com.ls.cockpit
Class ExternalCommand

java.lang.Object
  |
  +--com.ls.cockpit.CommandTemplate
        |
        +--com.ls.cockpit.ExternalCommand
All Implemented Interfaces:
ICockpitConstants, ICommand, IFromLars, Runnable

public abstract class ExternalCommand
extends com.ls.cockpit.CommandTemplate

this class is used to disjoin external and internal commands

Version:
$Revision: 1.3 $
Author:
Last modified by $Author: ASchneider $

Field Summary
protected  String revisionInformation
          revision information string, managed by our version control system.
 
Fields inherited from interface com.ls.cockpit.ICockpitConstants
ADD_HISTORY_STRING, ADD_INBOX_STRING, ADD_OUTBOX_STRING, ADMIN_STRING, ADMINISTRATOR_TAG, AGENT_LIST_TAG, AGENT_MANAGER_NAME, AGENT_NUMBER_TAG, AGENT_SYNCHRONIZE_SUPERVISOR_NAME, ALIAS_TAG, ALIASES_TAG, AUTHENTICATE_TIMEOUT, AUTO_COMPRESSION_START_SIZE_TAG, AUTO_COMPRESSION_TAG, BROADCAST_MESSAGE_STRING, BROADCAST_MESSAGE_TAG, CFG_FILE_TAG, CLASS_TAG, CLOSE_CFG_FILE_TAG, CLOSE_CONTENT_TAG, COCKPIT_APPLET_CLASS_NAME, COCKPIT_GUI_CLASS_NAME, COCKPIT_SERVLET_CLASS_NAME, COCKPIT_SHELL_CLASS_NAME, COMMAND_ADD_MONITOR_STRING, COMMAND_CLEAR_HISTORY_STRING, COMMAND_CLEAR_INBOX_STRING, COMMAND_CLEAR_MONITOR_STRING, COMMAND_CLEAR_OUTBOX_STRING, COMMAND_COMMAND_PATH_STRING, COMMAND_COMPRESSION_STRING, COMMAND_CONNECT_STRING, COMMAND_CONNECTION_STRING, COMMAND_CREATE_REPLY_STRING, COMMAND_CURRENT_CONNECTION_STRING, COMMAND_DELETE_GROUP_STRING, COMMAND_DELETE_STRING, COMMAND_DISCONNECT_STRING, COMMAND_FORWARD_MESSAGE_STRING, COMMAND_HELP_PATH_STRING, COMMAND_HELP_STRING, COMMAND_HISTORY_ENTRY_STRING, COMMAND_HISTORY_PATH_STRING, COMMAND_HISTORY_STRING, COMMAND_INBOX_ENTRY_STRING, COMMAND_INBOX_STRING, COMMAND_KILL_GROUP_STRING, COMMAND_KILL_STRING, COMMAND_LIST_ACTIVE_STRING, COMMAND_LIST_INACTIVE_STRING, COMMAND_LIST_PLATFORMS_STRING, COMMAND_LIST_STRING, COMMAND_LOAD_COMMAND_STRING, COMMAND_LOAD_HELP_STRING, COMMAND_LOAD_HISTORY_STRING, COMMAND_LOAD_MONITOR_STRING, COMMAND_LOG_SYSTEM_STRING, COMMAND_MANAGER_CLASS_NAME, COMMAND_MANAGER_PARAMETERS, COMMAND_MONITOR_PATH_STRING, COMMAND_MONITOR_STRING, COMMAND_NEW_STRING, COMMAND_OUTBOX_ENTRY_STRING, COMMAND_OUTBOX_STRING, COMMAND_PING_STRING, COMMAND_QUIT_STRING, COMMAND_RELOAD_STRING, COMMAND_REMOVE_CONNECTION_STRING, COMMAND_REMOVE_MONITOR_STRING, COMMAND_RESTART_GROUP_STRING, COMMAND_RESTART_LARS_STRING, COMMAND_RESTART_MONITOR_STRING, COMMAND_RESTART_STRING, COMMAND_SAVE_HISTORY_STRING, COMMAND_SEND_HISTORY_STRING, COMMAND_SEND_STRING, COMMAND_SEND_SYNC_STRING, COMMAND_SET_COMMAND_PATH_STRING, COMMAND_SET_COMPRESSION_STRING, COMMAND_SET_CONNECTION_STRING, COMMAND_SET_HELP_PATH_STRING, COMMAND_SET_HISTORY_PATH_STRING, COMMAND_SET_MONITOR_PATH_STRING, COMMAND_SHUTDOWN_LARS_STRING, COMMAND_START_LARS_STRING, COMMAND_TAG, COMMAND_UPDATE_MONITOR_STRING, COMMANDLIST_DIR_TAG, COMMANDLIST_TAG, COMPRESSION_CLASS_NAME, COMPRESSION_LEVEL_TAG, COMPRESSION_PARAMETERS, COMPRESSION_TAG, COMPRESSION_TYPE_TAG, CONNECT_CLASS_NAME, CONNECTION_PARAMETERS, CONNECTION_TAG, CONNECTION_TYPE_TAG, CONTENT_TAG, CURRENT_HOPS_TAG, DEFAULT_AUTO_COMPRESSION, DEFAULT_AUTO_COMPRESSION_START_SIZE, DEFAULT_COMPRESSION_LEVEL, DEFAULT_COMPRESSION_TYPE, DEFAULT_CONFIG_FILE_NAME, DEFAULT_CONNECTION_TYPE, DEFAULT_HELP_FILE_NAME, DEFAULT_KEY_FILE, DEFAULT_LOG_FILE_NAME, DEFAULT_LOG_LEVEL, DEFAULT_MESSAGE_LENGTH, DEFAULT_PASSWORD, DEFAULT_PLATFORM_DIRECTORY, DEFAULT_PLATFORM_ID, DEFAULT_PLATFORM_IP, DEFAULT_PLATFORM_PORT, DEFAULT_PROTOCOL, DEFAULT_PROVIDER, DEFAULT_STRING, DEFAULT_USER, DEFAULT_USER_INTERFACE_TYPE, DEFAULT_ZIP_ENTRY_NAME, DEPENDENCIES_TAG, DESCRIPTION_TAG, DIRECTORIES_TAG, EXAMPLE_STRING, EXAMPLE_TAG, EXPIRE_HOPS_TAG, GET_AGENTS_STATUS_STRING, GET_DEPENDENCY_STRING, GLOBAL_DIR_TAG, GROUP_MESSAGE_STRING, GROUP_MESSAGE_TAG, HELP_CLASS_NAME, HELP_DIR_TAG, HELP_FILE_NAME_TAG, HELP_PARAMETERS, HISTORY_CLASS_NAME, HISTORY_DIR_TAG, HISTORY_PARAMETERS, ICOMMAND_INTERFACE_NAME, IN_REPLY_TO_TAG, INBOX_CLASS_NAME, INBOX_NUMBER_TAG, IS_HISTORY_SAVED_STRING, KEY_FILE_TAG, LIST_TAG, LOG_FILE_TAG, LOG_LEVEL_TAG, LOG_SYSTEM_INFORMATION_NAME, LOGGING_TAG, LONG_DESCRIPTION_TAG, MAP_CLASS_NAME, MESSAGE_LENGTH_TAG, MESSAGE_TAG, MONITOR_CLASS_NAME, MONITOR_DIR_TAG, MONITOR_PARAMETERS, MONITORING_TAG, MULTICAST_MESSAGE_STRING, MULTICAST_MESSAGE_TAG, NAME_TAG, OPEN_CFG_FILE_TAG, OPEN_CONTENT_TAG, OUTBOX_CLASS_NAME, PARAMETER_TAG, PARAMETERS_TAG, PASSWORD_STRING, PASSWORD_TAG, PLATFORM_DIRECTORY_TAG, PLATFORM_ID_TAG, PLATFORM_IP_TAG, PLATFORM_PORT_TAG, PLATFORM_TAG, PRIORITY_TAG, PROTOCOL_TAG, PROVIDER_TAG, PWD_STRING, QUALITY_OF_SERVICE_TAG, QUIT_CLASS_NAME, RECEIVER_TAG, REPLY_WITH_TAG, SEND_ALL_MESSAGES_FROM_HISTORY_STRING, SEND_MESSAGE_PARAMETERS, SENDER_TAG, SENT_TIME_TAG, SERVICE_BROADCAST_MESSAGE_STRING, SERVICE_BROADCAST_MESSAGE_TAG, SERVICE_SINGLE_MESSAGE_STRING, SERVICE_SINGLE_MESSAGE_TAG, SERVICE_TAG, SET_AGENTS_STATUS_ACTIVE_STRING, SET_AGENTS_STATUS_INACTIVE_STRING, SET_HISTORY_SAVED_STRING, SHORT_DESCRIPTION_TAG, SINGLE_MESSAGE_STRING, SINGLE_MESSAGE_TAG, STANDARD_COMMAND_LIB_CLASS_NAME, START_AGENT_TAG, STRING_CONTENT_TAG, TYPE_TAG, UI_TAG, USAGE_STRING, USAGE_TAG, USER_INTERFACE_TYPE_APPLET, USER_INTERFACE_TYPE_SERVLET, USER_INTERFACE_TYPE_SHELL, USER_INTERFACE_TYPE_SWING, USER_INTERFACE_TYPE_TAG, USER_TAG, VALID_PARAMETERS, XML_CONTENT_TAG, XML_TAG, ZIP_ENTRY_NAME_TAG
 
Constructor Summary
ExternalCommand()
          the default constuctor
ExternalCommand(Map parameters, Map dependencies, Map description)
          the constructor containing initialize parameters
 
Method Summary
protected static String createReplyId()
          creates a cockpit definite replyId for sending messages
 Object executeCommand(String command, Object arguments)
          executes a command with the specified command (depends on the specified String) and the specified arguments object.
 Object executeCommand(String command, Object[] arguments)
          executes a command with the specified command (depends on the specified String) and the specified arguments object.
protected  String[] generateCommandArguments(String arguments, String[] validKeys)
          generate the command's arguments from the arguments String by checking the key values of validity and by ignoring the key values between an xml content.
protected abstract  Map getAlias()
          initializes all aliases if it's implemented in the commands class You have to imlement this method that it can be called by run method.
protected  Map getFlippedQosMap()
          gets the flipped Map of the description's Map from the Quality of Service.
protected abstract  Map getHelp()
          initializes all description's if it's implemented in the commands class You have to imlement this method that it can be called by run method.
protected abstract  void init()
          initializes all the needed commands
 boolean interpret(Message currentMessage)
          interprets the incoming messages from the lars platform connected to
 void run()
          runs the thread
protected  void setAlias(Map aliasesMap)
          sets the aliases the commands containing this command class
protected  void setDependencies(Map dependencies)
          sets the dependencies for the specified commands for executing them.
protected  void setDescription(Map description)
          sets the description for this command class
 void setUserInterfaceReference(IUserInterface uiReference)
          sets the reference to the user interface for the commandTemplate
 boolean startClass(String className, Map parameters, Map dependencies, Map description)
          tries to instantiate a command class by using the given parameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

revisionInformation

protected String revisionInformation
revision information string, managed by our version control system.
Constructor Detail

ExternalCommand

public ExternalCommand()
the default constuctor

ExternalCommand

public ExternalCommand(Map parameters,
                       Map dependencies,
                       Map description)
the constructor containing initialize parameters
Parameters:
parameters - containing initialize parameters
dependencies - containing dependencies to execute an command
description - containing the description for each command
Method Detail

init

protected abstract void init()
initializes all the needed commands
Overrides:
init in class com.ls.cockpit.CommandTemplate

getHelp

protected abstract Map getHelp()
initializes all description's if it's implemented in the commands class You have to imlement this method that it can be called by run method.
Overrides:
getHelp in class com.ls.cockpit.CommandTemplate
Returns:
Map containing the command's description (short and long), or an empty Map

getAlias

protected abstract Map getAlias()
initializes all aliases if it's implemented in the commands class You have to imlement this method that it can be called by run method.
Overrides:
getAlias in class com.ls.cockpit.CommandTemplate
Returns:
Map containing the aliases of a command, or an empty Map

run

public void run()
runs the thread
Specified by:
run in interface ICommand

setDependencies

protected void setDependencies(Map dependencies)
sets the dependencies for the specified commands for executing them.
Parameters:
dependencies - containing all dependencies for each command to execute them

setDescription

protected void setDescription(Map description)
sets the description for this command class
Parameters:
description - containing all descriptions (short, long) for all commands in this command's class

setAlias

protected void setAlias(Map aliasesMap)
sets the aliases the commands containing this command class
Parameters:
aliasesMap - containing all aliases for commands containing this command's class

setUserInterfaceReference

public void setUserInterfaceReference(IUserInterface uiReference)
sets the reference to the user interface for the commandTemplate
Specified by:
setUserInterfaceReference in interface ICommand
Parameters:
uiReference - the reference to the user interface

getFlippedQosMap

protected Map getFlippedQosMap()
gets the flipped Map of the description's Map from the Quality of Service.
Returns:
Map containing the descriptions (as key) of valid QoS descriptions and the representing 'int' value.

generateCommandArguments

protected String[] generateCommandArguments(String arguments,
                                            String[] validKeys)
                                     throws InvalidArgumentException
generate the command's arguments from the arguments String by checking the key values of validity and by ignoring the key values between an xml content.
Parameters:
arguments - contains the complete arguments String specified by user
validKeys - contains all valid keys for the specified command
Returns:
String[] containing all separated arguments to work with
Throws:
InvalidArgumentException - If the arguments aren't correct

startClass

public boolean startClass(String className,
                          Map parameters,
                          Map dependencies,
                          Map description)
                   throws InvocationTargetException,
                          InstantiationException,
                          IllegalAccessException,
                          LinkageError,
                          ClassNotFoundException,
                          NoSuchMethodException,
                          SecurityException
tries to instantiate a command class by using the given parameters
Specified by:
startClass in interface ICommand
Parameters:
className - the class to be instantiated
parameters - containing all parameters needed by this class
dependencies - containing all dependencies to execute a command
description - containing all command's description
Returns:
boolean true if the class is started
Throws:
InvocationTargetException - If the class can't be invoked
InstantiationException - If the class can't be instantiated
IllegalAccessException - If the class can't be accessed cause of an access violation
LinkageError - If the class can't be linked with the current ClassLoader
ClassNotFoundException - If the class can't be found
NoSuchMethodException - If the needed constructor isn't present
SecurityException - If there is a security violation

createReplyId

protected static String createReplyId()
creates a cockpit definite replyId for sending messages
Returns:
replyId the Id used to send messages (for the replyWith TAG)

interpret

public boolean interpret(Message currentMessage)
interprets the incoming messages from the lars platform connected to
Specified by:
interpret in interface IFromLars
Parameters:
currentMessage - contains the messages sent from lars platform
Returns:
boolean true if successfully interpreted

executeCommand

public final Object executeCommand(String command,
                                   Object arguments)
                            throws CommandNotFoundException,
                                   CommandNotAvailableException,
                                   InvalidArgumentException
executes a command with the specified command (depends on the specified String) and the specified arguments object.
Specified by:
executeCommand in interface ICommand
Parameters:
command - the commands name
arguments - the arguments (could be any object, the command has to care about)
Returns:
Object any return value (could be any object, the sender of a command has to care about)
Throws:
CommandNotFoundException - If the command doesn't exists
CommandNotAvailableException - If the command isn't available in this moment
InvalidArgumentException - If the arguments aren't correct

executeCommand

public final Object executeCommand(String command,
                                   Object[] arguments)
                            throws CommandNotFoundException,
                                   CommandNotAvailableException,
                                   InvalidArgumentException
executes a command with the specified command (depends on the specified String) and the specified arguments object.
Parameters:
command - the commands name
arguments - the arguments (could be any object, the command has to care about)
Returns:
Object any return value (could be any object, the sender of a command has to care about)
Throws:
CommandNotFoundException - If the command doesn't exists
CommandNotAvailableException - If the command isn't available in this moment
InvalidArgumentException - If the arguments aren't correct