log.finer("Request: " + cmdLine);
// Find command, first choose map according to state
Map<String, Command> commandMap = COMMAND_MAPS.get(session
.getMode());
// set to found command
Command command = null;
for (Map.Entry<String, Command> entry : commandMap.entrySet()) {
if (cmdLine.startsWith(entry.getKey() + " ")) {
command = entry.getValue();
// shorten command line to arguments
cmdLine = cmdLine
.substring(entry.getKey().length() + 1);
break;
}
if (cmdLine.equals(entry.getKey())) {
command = entry.getValue();
cmdLine = "";
break;
}
}
// if command found, execute
if (command != null) {
Command.Response resp
= command.execute(session, cmdLine.trim());
respond(resp.getCode(), resp.getMessage());
continue;
}
respond(410, "ERROR unknown command");
}