Logo Search packages:      
Sourcecode: henplus version File versions  Download package

void henplus::CommandDispatcher::execute ( SQLSession  session,
final String  givenCommand 
) [inline]

execute the command given. This strips whitespaces and trailing semicolons and calls the Command class.

Definition at line 209 of file CommandDispatcher.java.

References henplus::Command::execute(), getCommandNameFrom(), henplus::Command::getSynopsis(), and henplus::Command::requiresValidSession().

Referenced by henplus::commands::AliasCommand::execute().

                                                                       {
      if (givenCommand == null)
          return;

      // remove trailing ';' and whitespaces.
      StringBuffer cmdBuf = new StringBuffer(givenCommand.trim());
      int i = 0;
      for (i = cmdBuf.length()-1; i > 0; --i) {
          char c = cmdBuf.charAt(i);
          if (c != ';'
            && !Character.isWhitespace(c))
            break;
      }
      if (i < 0) {
          return;
      }
      cmdBuf.setLength(i+1);
      String cmd = cmdBuf.toString();
      //System.err.println("## '" + cmd + "'");
      String cmdStr = getCommandNameFrom(cmd);
      Command c = getCommandFromCooked(cmdStr);
      //System.err.println("name: "+  cmdStr + "; c=" + c);
      if (c != null) {
          try {
            String params = cmd.substring(cmdStr.length());
            if (session == null && c.requiresValidSession(cmdStr)) {
                HenPlus.msg().println("not connected.");
                return;
            }
                
                int result;
                informBeforeListeners(session, givenCommand);
                result = c.execute(session, cmdStr, params);
                informAfterListeners(session, givenCommand, result);

            switch ( result ) {
            case Command.SYNTAX_ERROR: {
                String synopsis = c.getSynopsis(cmdStr);
                if (synopsis != null) {
                  HenPlus.msg().println("usage: " + synopsis);
                }
                else {
                  HenPlus.msg().println("syntax error.");
                }
            }
                break;
            case Command.EXEC_FAILED: {
                    /*
                     * if we are in batch mode, then no message is written
                     * to the screen by default. Thus we don't know, _what_
                     * command actually failed. So in this case, write out
                     * the offending command.
                     */
                if ( isInBatch() ) {
                  HenPlus.msg().println("-- failed command: ");
                  HenPlus.msg().println(givenCommand);
                }
            }
                break;
                default:
                    /* nope */
            }
          }
          catch (Throwable e) {
            if (verbose) e.printStackTrace();
            HenPlus.msg().println(e.toString());
                informAfterListeners(session, givenCommand, 
                                     Command.EXEC_FAILED);
          }
      }
    }


Generated by  Doxygen 1.6.0   Back to index