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

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

execute the command given.

Implements henplus::Command.

Definition at line 103 of file PluginCommand.java.

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

                                                                            {
      StringTokenizer st = new StringTokenizer(param);
      int argc = st.countTokens();
      
      if ("list-plugins".equals(cmd)) {
          if (argc != 0) return SYNTAX_ERROR;
          HenPlus.msg().println("loaded plugins are marked with '*'");
          DRV_META[0].resetWidth();
          DRV_META[1].resetWidth();
          TableRenderer table = new TableRenderer(DRV_META, HenPlus.out());
          Iterator it = _plugins.entrySet().iterator();
          while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Column[] row = new Column[2];
            Command c = (Command) entry.getValue();
            String clsName = (String) entry.getKey();
            row[0] = new Column(((c != null) ? "* ":"  ")
                            + clsName);
            if (c != null) {
                StringBuffer cmds = new StringBuffer();
                String[] cmdList = c.getCommandList();
                for (int i=0; i < cmdList.length; ++i) {
                  cmds.append(cmdList[i]).append("\n");
                }
                row[1] = new Column( cmds.toString().trim() );
            }
            else {
                row[1] = new Column( null );
            }
            table.addRow(row);
          }
          table.closeTable();
          return SUCCESS;
      }
      else if ("plug-in".equals(cmd)) {
          if (argc != 1) return SYNTAX_ERROR;
          String pluginClass = (String) st.nextElement();
          if (_plugins.containsKey(pluginClass)) {
            HenPlus.msg().println("plugin '" + pluginClass 
                           + "' already loaded");
            return EXEC_FAILED;
          }
          Command plugin = null;
          try {
            plugin = loadPlugin(pluginClass);
          }
          catch (Exception e) {
            HenPlus.msg().println("couldn't load plugin: " + e.getMessage());
            return EXEC_FAILED;
          }
          if (plugin != null) {
            _plugins.put(pluginClass, plugin);
            String[] cmds = plugin.getCommandList();
            HenPlus.out().print("adding commands: ");
            for (int i=0; i < cmds.length; ++i) {
                if (i!=0) HenPlus.out().print(", ");
                HenPlus.out().print(cmds[i]);
            }
            HenPlus.out().println();
          }
      }
      else if ("plug-out".equals(cmd)) {
          if (argc != 1) return SYNTAX_ERROR;
          String pluginClass = (String) st.nextElement();
          if (!_plugins.containsKey(pluginClass)) {
            HenPlus.msg().println("unknown plugin '" + pluginClass + "'");
            return EXEC_FAILED;
          }
          else {
            Command c = (Command) _plugins.remove(pluginClass);
            _henplus.getDispatcher().unregister(c);
          }
      }
      return SUCCESS;
    }


Generated by  Doxygen 1.6.0   Back to index