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

    BatchManager batchManager = ctx.getBatchManager();
    if (!batchManager.isBatchActive()) {
      throw new CommandFormatException("No active batch to holdback.");
    }

    String name = null;
    ParsedCommandLine args = ctx.getParsedCommandLine();
    if (args.hasProperties()) {
      name = args.getOtherProperties().get(0);
    }

    if (batchManager.isHeldback(name)) {
      throw new CommandFormatException(
          "There already is "
              + (name == null ? "unnamed" : "'" + name + "'")
              + " batch held back.");
    }

    if (!batchManager.holdbackActiveBatch(name)) {
      throw new CommandFormatException("Failed to holdback the batch.");
    }
  }
Example #2
0
  @Override
  protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {

    final BatchManager batchManager = ctx.getBatchManager();
    if (!batchManager.isBatchActive()) {
      throw new CommandFormatException("No active batch.");
    }

    final Batch batch = batchManager.getActiveBatch();
    List<BatchedCommand> currentBatch = batch.getCommands();
    if (currentBatch.isEmpty()) {
      batchManager.discardActiveBatch();
      throw new CommandFormatException("The batch is empty.");
    }

    return batch.toRequest();
  }
Example #3
0
  /* (non-Javadoc)
   * @see org.jboss.as.cli.handlers.CommandHandlerWithHelp#doHandle(org.jboss.as.cli.CommandContext)
   */
  @Override
  protected void doHandle(CommandContext ctx) throws CommandLineException {

    String argsStr = ctx.getArgumentsString();
    if (argsStr == null) {
      throw new CommandFormatException("The command is missing arguments.");
    }

    final BatchManager batchManager = ctx.getBatchManager();
    if (batchManager.isBatchActive()) {
      throw new CommandFormatException("if is not allowed while in batch mode.");
    }

    final ParsedCommandLine args = ctx.getParsedCommandLine();
    final String conditionStr = this.condition.getValue(args, true);
    int i = argsStr.indexOf(conditionStr);
    if (i < 0) {
      throw new CommandFormatException(
          "Failed to locate '" + conditionStr + "' in '" + argsStr + "'");
    }
    i = argsStr.indexOf("of", i + conditionStr.length());
    if (i < 0) {
      throw new CommandFormatException("Failed to locate 'of' in '" + argsStr + "'");
    }

    final String line = argsStr.substring(i + 2);
    try {
      IfElseBlock.create(ctx).setCondition(conditionStr, ctx.buildRequest(line));
    } catch (CommandLineException e) {
      IfElseBlock.remove(ctx);
      throw e;
    }

    if (!batchManager.activateNewBatch()) {
      IfElseBlock.remove(ctx);
      // that's more like illegal state
      throw new CommandFormatException("Failed to activate batch mode for if.");
    }
  }
 @Override
 public boolean isBatchMode() {
   return batchManager.isBatchActive();
 }