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

int henplus::commands::AliasCommand::execute ( SQLSession  currentSession,
String  cmd,
String  param 
) [inline]

execute the command given.

Implements henplus::Command.

Definition at line 106 of file AliasCommand.java.

References _currentExecutedAliases, henplus::view::TableRenderer::addRow(), henplus::view::TableRenderer::closeTable(), henplus::CommandDispatcher::containsCommand(), henplus::Command::EXEC_FAILED, henplus::CommandDispatcher::execute(), henplus::view::ColumnMetaData::resetWidth(), henplus::Command::SUCCESS, and henplus::Command::SYNTAX_ERROR.

                                                                            {
      StringTokenizer st = new StringTokenizer(param);
      int argc = st.countTokens();
      
      if ("list-aliases".equals(cmd)) {
          if (argc != 0) return SYNTAX_ERROR;
          DRV_META[0].resetWidth();
          DRV_META[1].resetWidth();
          TableRenderer table = new TableRenderer(DRV_META, HenPlus.out());
          Iterator it = _aliases.entrySet().iterator();
          while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Column[] row = new Column[2];
            row[0] = new Column((String) entry.getKey());
            row[1] = new Column((String) entry.getValue());
            table.addRow(row);
          }
          table.closeTable();
          return SUCCESS;
      }

      else if ("alias".equals(cmd)) {
          if (argc < 2) return SYNTAX_ERROR;
          String alias = (String) st.nextElement();
          // no quoted aliases..
          if (alias.startsWith("\"") || alias.startsWith("'")) {
            return SYNTAX_ERROR;
          }
          // unless we override an alias, moan, if this command already
          // exists.
          if (!_aliases.containsKey(alias)
            && _dispatcher.containsCommand(alias)) {
            HenPlus.msg().println("cannot alias built-in command!");
            return EXEC_FAILED;
          }
          param = param.trim();
          for (int i=0; i < param.length(); ++i) {
            if (Character.isWhitespace(param.charAt(i))) {
                param = param.substring(i).trim();
                break;
            }
          }
          String value = stripQuotes(param); // rest of values.
          putAlias(alias, value);
      }

      else if ("unalias".equals(cmd)) {
          if (argc >= 1) {
            while (st.hasMoreElements()) {
                String alias = (String) st.nextElement();
                if (!_aliases.containsKey(alias)) {
                  HenPlus.msg().println("unknown alias '" 
                                 + alias + "'");
                }
                else {
                  removeAlias(alias);
                }
            }
            return SUCCESS;
          }
          return SYNTAX_ERROR;
      }

      else {
          String toExecute = (String) _aliases.get(cmd);
            //HenPlus.msg().println("key: '" + cmd + "' - exec: " + toExecute);
          if (toExecute == null) {
            return EXEC_FAILED;
          }
          // not session-proof:
          if (_currentExecutedAliases.contains(cmd)) {
            HenPlus.msg().println("Recursive call to aliases ["
                           + cmd 
                           + "]. Stopping this senseless venture.");
            _currentExecutedAliases.clear();
            return EXEC_FAILED;
          }
          HenPlus.msg().println("execute alias: " + toExecute + param);
          _currentExecutedAliases.add(cmd);
          _dispatcher.execute(currentSession, toExecute + param);
          _currentExecutedAliases.clear();
      }
      return SUCCESS;
    }


Generated by  Doxygen 1.6.0   Back to index