@Override
    public BatchedCommand toBatchedCommand(String line) throws OperationFormatException {

      if (line.isEmpty()) {
        throw new IllegalArgumentException("Null command line.");
      }

      final String originalCommand = this.cmd;
      final String originalArguments = this.parsedArgs.getArgumentsString();
      if (isOperation(line)) {
        try {
          setArgs(null, line);
          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 {
          setArgs(originalCommand, originalArguments);
        }
      }

      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 {
        setArgs(cmd, cmdArgs);
        ModelNode request = ((OperationCommand) handler).buildRequest(this);
        return new DefaultBatchedCommand(line, request);
      } finally {
        setArgs(originalCommand, originalArguments);
      }
    }
  protected static void processLine(final CommandContextImpl cmdCtx, String line) {
    if (line.isEmpty()) {
      return;
    }

    if (isOperation(line)) {
      cmdCtx.setArgs(null, line);
      if (cmdCtx.isBatchMode()) {
        DefaultOperationRequestBuilder builder =
            new DefaultOperationRequestBuilder(cmdCtx.getPrefix());
        try {
          cmdCtx.getOperationRequestParser().parse(line, builder);
          ModelNode request = builder.buildRequest();
          StringBuilder op = new StringBuilder();
          op.append(cmdCtx.getPrefixFormatter().format(builder.getAddress()));
          op.append(line.substring(line.indexOf(':')));
          DefaultBatchedCommand batchedCmd = new DefaultBatchedCommand(op.toString(), request);
          Batch batch = cmdCtx.getBatchManager().getActiveBatch();
          batch.add(batchedCmd);
          cmdCtx.printLine("#" + batch.size() + " " + batchedCmd.getCommand());
        } catch (CommandFormatException e) {
          cmdCtx.printLine(e.getLocalizedMessage());
        }
      } else {
        cmdCtx.operationHandler.handle(cmdCtx);
      }

    } else {
      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;
        }
      }
      cmdCtx.setArgs(cmd, cmdArgs);

      CommandHandler handler = cmdRegistry.getCommandHandler(cmd.toLowerCase());
      if (handler != null) {
        if (cmdCtx.isBatchMode() && handler.isBatchMode()) {
          if (!(handler instanceof OperationCommand)) {
            cmdCtx.printLine("The command is not allowed in a batch.");
          } else {
            try {
              ModelNode request = ((OperationCommand) handler).buildRequest(cmdCtx);
              BatchedCommand batchedCmd = new DefaultBatchedCommand(line, request);
              Batch batch = cmdCtx.getBatchManager().getActiveBatch();
              batch.add(batchedCmd);
              cmdCtx.printLine("#" + batch.size() + " " + batchedCmd.getCommand());
            } catch (OperationFormatException e) {
              cmdCtx.printLine("Failed to add to batch: " + e.getLocalizedMessage());
            }
          }
        } else {
          handler.handle(cmdCtx);
        }
      } else {
        cmdCtx.printLine(
            "Unexpected command '" + line + "'. Type 'help' for the list of supported commands.");
      }
    }
    cmdCtx.setArgs(null, null);
  }