if (line.isEmpty()) {
throw new IllegalArgumentException("Null command line.");
}
final DefaultParsedArguments originalParsedArguments = this.parsedArgs;
if(isOperation(line)) {
try {
this.parsedArgs = new DefaultParsedArguments();
setArgs(null, line, null);
DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(getPrefix());
parser.parse(line, builder);
ModelNode request = builder.buildRequest();
StringBuilder op = new StringBuilder();
op.append(prefixFormatter.format(builder.getAddress()));
op.append(line.substring(line.indexOf(':')));
return new DefaultBatchedCommand(op.toString(), request);
} finally {
this.parsedArgs = originalParsedArguments;
}
}
String cmd = line;
String cmdArgs = null;
for (int i = 0; i < cmd.length(); ++i) {
if (Character.isWhitespace(cmd.charAt(i))) {
cmdArgs = cmd.substring(i + 1).trim();
cmd = cmd.substring(0, i);
break;
}
}
CommandHandler handler = cmdRegistry.getCommandHandler(cmd.toLowerCase());
if(handler == null) {
throw new OperationFormatException("No command handler for '" + cmd + "'.");
}
if(!(handler instanceof OperationCommand)) {
throw new OperationFormatException("The command is not allowed in a batch.");
}
try {
this.parsedArgs = new DefaultParsedArguments();
setArgs(cmd, cmdArgs, handler);
ModelNode request = ((OperationCommand)handler).buildRequest(this);
return new DefaultBatchedCommand(line, request);
} finally {
this.parsedArgs = originalParsedArguments;