/** * Given a command name, look for and register that command from the admin-configured command * definitions. * * @param cmd * @param classes */ private void registerConfigCommand(String cmd) { log.devDebug("processing config defined command ", cmd); Map<String, Object> cmdParams = commandConfig.getCommandParameters(cmd); Class<? extends Command> cmdClass = null; String className = null; Object clazz = cmdParams.get("class"); // if no class given, just assume the name of the commmand if (clazz == null) clazz = cmd; if (clazz != null && clazz instanceof String) { className = (String) clazz; // if class given, but no package given, assume default package if (className.indexOf('.') == -1) { String firstChar = className.substring(0, 1); String theRest = className.substring(1); className = firstChar.toUpperCase() + theRest; cmdClass = findCommandClass(className); } } // if we have no commandClass yet, but we do have a className, then // try to find that className. if (cmdClass == null && className != null) { cmdClass = findCommandClass(className); } if (cmdClass == null) { log.warn("No class defined or found for command ", cmd); return; } try { Command command = (Command) cmdClass.newInstance(); command.setCommandName(cmd.toLowerCase()); // default to name of instance key register(command, cmdParams); } catch (ClassCastException e) { log.warn("class " + cmdClass + " does not implement Command interface"); } catch (Exception e) { log.warn(e, "error loading class " + cmdClass); } }
public void register(Command command) { Map<String, Object> cmdParams = commandConfig.getCommandParameters(command.getCommandName()); register(command, cmdParams); }