DRV_META[0].resetWidth();
DRV_META[1].resetWidth();
final TableRenderer table = new TableRenderer(DRV_META, HenPlus.out());
for (Entry<String,Command> entry : _plugins.entrySet()) {
final Column[] row = new Column[2];
final Command c = entry.getValue();
final String clsName = entry.getKey();
row[0] = new Column((c != null ? "* " : " ") + clsName);
if (c != null) {
final StringBuilder cmds = new StringBuilder();
final 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;
}
final 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 (final Exception e) {
HenPlus.msg().println("couldn't load plugin: " + e.getMessage());
return EXEC_FAILED;
}
if (plugin != null) {
_plugins.put(pluginClass, plugin);
final 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;
}
final String pluginClass = (String) st.nextElement();
if (!_plugins.containsKey(pluginClass)) {
HenPlus.msg().println("unknown plugin '" + pluginClass + "'");
return EXEC_FAILED;
} else {
final Command c = _plugins.remove(pluginClass);
_henplus.getDispatcher().unregister(c);
}
}
return SUCCESS;
}