private Request buildFolderRequestFromCommand(Command command, String commandName, String[] commandArgs, String root) throws Exception {
String thisPackage = BadRequestResponse.class.getPackage().getName(); // TODO [low] Medium-dirty hack.
String camelCaseMessageType = StringUtil.toCamelCase(commandName) + FolderRequest.class.getSimpleName();
String fqMessageClassName = thisPackage + "." + camelCaseMessageType;
FolderRequest folderRequest;
try {
Class<? extends FolderRequest> folderRequestClass = Class.forName(fqMessageClassName).asSubclass(FolderRequest.class);
folderRequest = folderRequestClass.newInstance();
}
catch (Exception e) {
logger.log(Level.INFO, "Could not find FQCN " + fqMessageClassName, e);
throw new Exception("Cannot read request class from request type: " + commandName, e);
}
OperationOptions operationOptions = command.parseOptions(commandArgs);
int requestId = Math.abs(new Random().nextInt());
folderRequest.setRoot(root);
folderRequest.setId(requestId);
folderRequest.setOptions(operationOptions);
return folderRequest;
}