Esempio n. 1
0
 /**
  * Returns all the available commands a user can issue through a client's {@link
  * #handleCommand(String)} method. The returned set depends on the command handlers added to this
  * client. At least the commands enabled by the BaseCommandHandler will be returned by this
  * command, because this command handler is always added to any client by default.
  *
  * @return
  */
 public Set<String> getAvailableCommands() {
   Set<String> cmdList = new HashSet<String>();
   for (CommandHandler handler : cmdHandlers) {
     cmdList.addAll(handler.getCommandList());
   }
   return cmdList;
 }
Esempio n. 2
0
 /**
  * Runs a particular command via appropriate command handler. The result is returned in the {@link
  * CommandResult} data structure.
  *
  * @param commandString The command string to be run. It includes command, its options, and
  *     arguments all separated by space. It is upto the relavant command handler to distinguish
  *     between comand, options, and arguments.
  * @return A {@link CommandResult} data structure which includes the result of running the
  *     command. In case of an error, it as well is stored in the returned data strucute.
  * @throws ParseException
  * @see CommandResult
  */
 public CommandResult handleCommand(String commandString) throws ParseException {
   CommandResult cmdResult = new CommandResult(commandString);
   if (!cmdResult.isError()) {
     CommandHandler handler = getCommandHandler(cmdResult.command);
     if (handler == null) {
       cmdResult.errMsg =
           "Command " + cmdResult.command + " is not supported\n" + "Type 'help' for more info";
     } else {
       handler.runCommand(cmdResult);
     }
   }
   return cmdResult;
 }
Esempio n. 3
0
 /**
  * Returns the help text for a particular command. For this command to work properly, the command
  * should be supported by one of the command handlers enabled in the client and the command
  * handler who supports this command should also include a help text for that command.
  *
  * @see #addCommandHandler(CommandHandler), {@link CommandHandler}
  * @param cmd The command for which help needed.
  * @return The help text for the specified command, null if the command is not found in any of the
  *     command handlers.
  */
 public String getCommandHelp(String cmd) {
   for (CommandHandler handler : cmdHandlers) {
     if (handler.supportCommand(cmd)) return handler.getHelp(cmd);
   }
   return null;
 }
Esempio n. 4
0
 /**
  * Returns the command handler that handles the given cmd
  *
  * @param cmd
  * @return
  */
 protected CommandHandler getCommandHandler(String cmd) {
   for (CommandHandler handler : cmdHandlers) {
     if (handler.supportCommand(cmd)) return handler;
   }
   return null;
 }