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

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

execute the command given.

Implements henplus::Command.

Definition at line 140 of file DriverCommand.java.

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

                                                                            {
      StringTokenizer st = new StringTokenizer(param);
      int argc = st.countTokens();
      
      if ("list-drivers".equals(cmd)) {
          if (argc == 0) {
            HenPlus.msg().println("loaded drivers are marked with '*' (otherwise not found in CLASSPATH)");
            DRV_META[0].resetWidth();
            DRV_META[1].resetWidth();
            DRV_META[2].resetWidth();
            TableRenderer table = new TableRenderer(DRV_META, HenPlus.out());
            Iterator vars = _drivers.entrySet().iterator();
            while (vars.hasNext()) {
                Map.Entry entry = (Map.Entry) vars.next();
                Column[] row = new Column[3];
                DriverDescription desc=(DriverDescription)entry.getValue();
                String dbName = (String) entry.getKey();
                row[0] = new Column(((desc.isLoaded()) ? "* ":"  ")
                              + dbName);
                row[1] = new Column( desc.getClassName());
                row[2] = new Column( desc.getSampleURL());
                table.addRow(row);
            }
            table.closeTable();
            return SUCCESS;
          }
          else
            return SYNTAX_ERROR;
      }
      else if ("register".equals(cmd)) {
          if (argc < 2 || argc > 3)
            return SYNTAX_ERROR;
          String shortname   = (String) st.nextElement();
          String driverClass = (String) st.nextElement();
          String sampleURL   = null;
          if (argc >= 3) {
            sampleURL = (String) st.nextElement();
          }
          DriverDescription drv;
          drv = new DriverDescription(driverClass, sampleURL);
          if (! drv.isLoaded() ) {
            HenPlus.msg().println("cannot load driver class '" 
                           + driverClass + "'");
            return EXEC_FAILED;
          }
          else {
            _drivers.put(shortname, drv);
          }
      }
      else if ("unregister".equals(cmd)) {
          if (argc != 1)
            return SYNTAX_ERROR;
          String shortname   = (String) st.nextElement();
          if (!_drivers.containsKey(shortname)) {
            HenPlus.msg().println("unknown driver for '" + shortname + "'");
            return EXEC_FAILED;
          }
          else {
            _drivers.remove(shortname);
          }
      }
      return SUCCESS;
    }


Generated by  Doxygen 1.6.0   Back to index