Exemple #1
0
  void undo(
      MultiStatus status,
      EngineSession session,
      IProfile profile,
      Operand operand,
      ProvisioningAction[] actions,
      ProvisioningContext context) {
    if (operandParameters == null) {
      operandParameters = new HashMap<String, Object>(phaseParameters);
      operandParameters.put(PARM_OPERAND, operand);
      mergeStatus(
          status,
          initializeOperand(profile, operand, operandParameters, new NullProgressMonitor()));
      Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT);
      if (operandTouchpoint != null) {
        mergeStatus(
            status,
            initializeTouchpointParameters(
                profile, operand, operandTouchpoint, new NullProgressMonitor()));
        if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;

        operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint);
      }
      operandParameters = Collections.unmodifiableMap(operandParameters);
    }
    for (int j = 0; j < actions.length; j++) {
      ProvisioningAction action = actions[j];
      Map<String, Object> parameters = operandParameters;
      Touchpoint touchpoint = action.getTouchpoint();
      if (touchpoint != null) {
        mergeStatus(
            status,
            initializeTouchpointParameters(
                profile, operand, touchpoint, new NullProgressMonitor()));
        if (status.matches(IStatus.ERROR)) return;

        parameters = touchpointToTouchpointOperandParameters.get(touchpoint);
      }
      IStatus actionStatus = null;
      try {
        session.recordActionUndo(action, parameters);
        actionStatus = action.undo(parameters);
      } catch (RuntimeException e) {
        // "action.undo" calls user code and might throw an unchecked exception
        // we catch the error here to gather information on where the problem occurred.
        actionStatus =
            new Status(
                IStatus.ERROR,
                EngineActivator.ID,
                NLS.bind(Messages.action_undo_error, action.getClass().getName()),
                e);
      } catch (LinkageError e) {
        // Catch linkage errors as these are generally recoverable but let other Errors propagate
        // (see bug 222001)
        actionStatus =
            new Status(
                IStatus.ERROR,
                EngineActivator.ID,
                NLS.bind(Messages.action_undo_error, action.getClass().getName()),
                e);
      }
      if (actionStatus != null && actionStatus.matches(IStatus.ERROR)) {
        MultiStatus result =
            new MultiStatus(EngineActivator.ID, IStatus.ERROR, getProblemMessage(), null);
        result.add(
            new Status(
                IStatus.ERROR,
                EngineActivator.ID,
                session.getContextString(this, operand, action),
                null));
        result.merge(actionStatus);
      }
    }
    mergeStatus(
        status,
        touchpointCompleteOperand(profile, operand, operandParameters, new NullProgressMonitor()));
    mergeStatus(
        status, completeOperand(profile, operand, operandParameters, new NullProgressMonitor()));
    operandParameters = null;
  }
Exemple #2
0
  private void mainPerform(
      MultiStatus status, EngineSession session, Operand[] operands, SubMonitor subMonitor) {
    IProfile profile = session.getProfile();
    subMonitor.beginTask(null, operands.length);
    for (int i = 0; i < operands.length; i++) {
      subMonitor.setWorkRemaining(operands.length - i);
      if (subMonitor.isCanceled()) throw new OperationCanceledException();
      Operand operand = operands[i];
      if (!isApplicable(operand)) continue;

      session.recordOperandStart(operand);
      List<ProvisioningAction> actions = getActions(operand);
      operandParameters = new HashMap<String, Object>(phaseParameters);
      operandParameters.put(PARM_OPERAND, operand);
      mergeStatus(status, initializeOperand(profile, operand, operandParameters, subMonitor));
      if (status.matches(IStatus.ERROR | IStatus.CANCEL)) {
        operandParameters = null;
        return;
      }

      Touchpoint operandTouchpoint = (Touchpoint) operandParameters.get(PARM_TOUCHPOINT);
      if (operandTouchpoint != null) {
        mergeStatus(
            status,
            initializeTouchpointParameters(profile, operand, operandTouchpoint, subMonitor));
        if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;

        operandParameters = touchpointToTouchpointOperandParameters.get(operandTouchpoint);
      }

      operandParameters = Collections.unmodifiableMap(operandParameters);
      if (actions != null) {
        for (int j = 0; j < actions.size(); j++) {
          ProvisioningAction action = actions.get(j);
          Map<String, Object> parameters = operandParameters;
          Touchpoint touchpoint = action.getTouchpoint();
          if (touchpoint != null) {
            mergeStatus(
                status, initializeTouchpointParameters(profile, operand, touchpoint, subMonitor));
            if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;

            parameters = touchpointToTouchpointOperandParameters.get(touchpoint);
          }
          IStatus actionStatus = null;
          try {
            session.recordActionExecute(action, parameters);
            actionStatus = action.execute(parameters);
          } catch (RuntimeException e) {
            if (!forced) throw e;
            // "action.execute" calls user code and might throw an unchecked exception
            // we catch the error here to gather information on where the problem occurred.
            actionStatus =
                new Status(
                    IStatus.ERROR,
                    EngineActivator.ID,
                    NLS.bind(Messages.forced_action_execute_error, action.getClass().getName()),
                    e);
          } catch (LinkageError e) {
            if (!forced) throw e;
            // Catch linkage errors as these are generally recoverable but let other Errors
            // propagate (see bug 222001)
            actionStatus =
                new Status(
                    IStatus.ERROR,
                    EngineActivator.ID,
                    NLS.bind(Messages.forced_action_execute_error, action.getClass().getName()),
                    e);
          }
          if (forced && actionStatus != null && actionStatus.matches(IStatus.ERROR)) {
            MultiStatus result =
                new MultiStatus(EngineActivator.ID, IStatus.ERROR, getProblemMessage(), null);
            result.add(
                new Status(
                    IStatus.ERROR,
                    EngineActivator.ID,
                    session.getContextString(this, operand, action),
                    null));
            LogHelper.log(result);
            actionStatus = Status.OK_STATUS;
          }
          mergeStatus(status, actionStatus);
          if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;
        }
      }
      mergeStatus(
          status, touchpointCompleteOperand(profile, operand, operandParameters, subMonitor));
      mergeStatus(status, completeOperand(profile, operand, operandParameters, subMonitor));
      if (status.matches(IStatus.ERROR | IStatus.CANCEL)) return;
      operandParameters = null;
      session.recordOperandEnd(operand);
      subMonitor.worked(1);
    }
  }
 public IStatus undo(Map<String, Object> parameters) {
   parameters = processActionParameters(parameters);
   return action.undo(parameters);
 }
 public Touchpoint getTouchpoint() {
   return action.getTouchpoint();
 }
 public IStatus execute(Map<String, Object> parameters) {
   parameters = processActionParameters(parameters);
   return action.execute(parameters);
 }