/* (non-Javadoc)
   * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
   */
  @Override
  protected void doHandle(CommandContext ctx) {

    ModelNode request;
    try {
      request = buildRequest(ctx);
    } catch (OperationFormatException e) {
      ctx.printLine(e.getLocalizedMessage());
      return;
    }

    ModelControllerClient client = ctx.getModelControllerClient();
    final ModelNode result;
    try {
      result = client.execute(request);
    } catch (Exception e) {
      ctx.printLine("Failed to perform operation: " + e.getLocalizedMessage());
      return;
    }

    if (!Util.isSuccess(result)) {
      ctx.printLine(Util.getFailureDescription(result));
      return;
    }

    ctx.printLine("Sucessfully created queue.");
  }
 protected void assertValidInput(String input) {
   try {
     parse(input);
   } catch (OperationFormatException e) {
     Assert.fail(e.getLocalizedMessage());
   }
 }
  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);
  }