IdentityPatchContext(
      final File backup,
      final PatchContentProvider contentProvider,
      final ContentVerificationPolicy contentPolicy,
      final InstallationManager.InstallationModification modification,
      final PatchingTaskContext.Mode mode,
      final InstalledImage installedImage) {

    this.miscTargetRoot = installedImage.getJbossHome();

    this.mode = mode;
    this.contentProvider = contentProvider;
    this.contentPolicy = contentPolicy;
    this.modification = modification;
    this.installedImage = installedImage;
    this.history =
        PatchingHistory.Factory.getHistory(modification.getUnmodifiedInstallationState());

    if (backup != null) {
      this.miscBackup = new File(backup, PatchContentLoader.MISC);
      this.configBackup = new File(backup, Constants.CONFIGURATION);
    } else {
      this.miscBackup = null; // This will trigger a failure when the root is actually needed
      this.configBackup = null;
    }
    this.identityEntry = new PatchEntry(modification, null);
  }
  /**
   * Create a rollback patch based on the recorded actions.
   *
   * @param patchId the new patch id, depending on release or one-off
   * @param patchType the current patch identity
   * @return the rollback patch
   */
  protected RollbackPatch createRollbackPatch(
      final String patchId, final Patch.PatchType patchType) {
    // Process elements
    final List<PatchElement> elements = new ArrayList<PatchElement>();
    // Process layers
    for (final PatchEntry entry : getLayers()) {
      final PatchElement element = createRollbackElement(entry);
      elements.add(element);
    }
    // Process add-ons
    for (final PatchEntry entry : getAddOns()) {
      final PatchElement element = createRollbackElement(entry);
      elements.add(element);
    }

    final InstalledIdentity installedIdentity = modification.getUnmodifiedInstallationState();
    final String name = installedIdentity.getIdentity().getName();
    final IdentityImpl identity = new IdentityImpl(name, modification.getVersion());
    if (patchType == Patch.PatchType.CUMULATIVE) {
      identity.setPatchType(Patch.PatchType.CUMULATIVE);
      identity.setResultingVersion(installedIdentity.getIdentity().getVersion());
    } else if (patchType == Patch.PatchType.ONE_OFF) {
      identity.setPatchType(Patch.PatchType.ONE_OFF);
    }
    final List<ContentModification> modifications = identityEntry.rollbackActions;
    final Patch delegate =
        new PatchImpl(patchId, "rollback patch", identity, elements, modifications);
    return new PatchImpl.RollbackPatchImpl(delegate, installedIdentity);
  }