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

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

execute the command given.

Implements henplus::Command.

Definition at line 81 of file SetCommand.java.

References henplus::view::TableRenderer::addRow(), henplus::view::TableRenderer::closeTable(), henplus::view::ColumnMetaData::resetWidth(), henplus::Command::SUCCESS, and henplus::Command::SYNTAX_ERROR.

                                                                             {
      StringTokenizer st = new StringTokenizer(param);
      int argc = st.countTokens();
      
      if ("set-var".equals(cmd)) {
            /*
             * no args. only show.
             */
          if (argc == 0) {
            SET_META[0].resetWidth();
            SET_META[1].resetWidth();
            TableRenderer table = new TableRenderer(SET_META, HenPlus.out());
            Iterator vars = _variables.entrySet().iterator();
            while (vars.hasNext()) {
                Map.Entry entry = (Map.Entry) vars.next();
                Column[] row = new Column[4];
                row[0] = new Column((String) entry.getKey());
                row[1] = new Column((String) entry.getValue());
                //row[2] = new Column("");
                //row[3] = new Column("X");
                table.addRow(row);
            }
            table.closeTable();
            return SUCCESS;
          }
            /*
             * more than one arg
             */
          else if (argc >= 2) {
            String varname = (String) st.nextElement();
            int pos = 0;
                int paramLength = param.length();
            // skip whitespace after 'set'
            while (pos < paramLength
                   && Character.isWhitespace(param.charAt(pos))) {
                ++pos;
            }
            // skip non-whitespace after 'set  ': variable name
            while (pos < paramLength
                   && !Character.isWhitespace(param.charAt(pos))) {
                ++pos;
            }
            // skip whitespace before vlue..
            while (pos < paramLength
                   && Character.isWhitespace(param.charAt(pos))) {
                ++pos;
            }
            String value = param.substring(pos);
            if (value.startsWith("\"") && value.endsWith("\"")) {
                value = value.substring(1, value.length()-1);
            }
            else if (value.startsWith("\'") && value.endsWith("\'")) {
                value = value.substring(1, value.length()-1);
            }
            _variables.put(varname, value);
            return SUCCESS;
          }
          return SYNTAX_ERROR;
      }
      else if ("unset-var".equals(cmd)) {
          if (argc >= 1) {
            while (st.hasMoreElements()) {
                String varname = (String) st.nextElement();
                if (!_variables.containsKey(varname)) {
                  HenPlus.msg().println("unknown variable '" 
                                 + varname + "'");
                }
                else {
                  _variables.remove(varname);
                }
            }
            return SUCCESS;
          }
          return SYNTAX_ERROR;
      }
      return SUCCESS;
    }


Generated by  Doxygen 1.6.0   Back to index