From 06dc34882e70da6158464bfb18dd30ef86e1bc1d Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Mon, 03 Jun 2013 07:42:27 +0000
Subject: [PATCH] CR-1777-OPENDJ - Upgrade code cleanup - The upgrade context is now set in the CLI. - The upgrade context contains now the callback handler which simplify all the function (removed all calls to callbackhandler, functions just need the context at this point). - The context contains the CLI user selected options which simplify the code, removed the CheckCLIUserOption, the task have just to check the context for those parameters. - Removed the useless VerificationCallback.java - Added a TaskType in UpgradeTask.java. - Added function verifyTaskType in UpgradeTasks.java which verify user selected options are correct. - Modified tools.properties message numbers

---
 opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java        |  358 +++++++-------------
 /dev/null                                                                  |  119 -------
 opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java |   10 
 opends/src/messages/messages/tools.properties                              |   74 ++--
 opends/src/server/org/opends/server/tools/upgrade/UpgradeContext.java      |  181 +++++++---
 opends/src/server/org/opends/server/tools/upgrade/UpgradeTask.java         |   53 +-
 opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java          |   87 ----
 opends/src/server/org/opends/server/tools/upgrade/Upgrade.java             |  114 ++----
 8 files changed, 383 insertions(+), 613 deletions(-)

diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index 4a28ef6..a35ba90 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -2628,63 +2628,61 @@
 or restore capabilities. Therefore, it is the responsibility of the OpenDJ administrator to take \
 necessary precautions before performing the upgrade
 SEVERE_ERR_UPGRADE_MAIN_UPGRADE_PROCESS_1800=The upgrade failed to complete for the following reason: %s
-INFO_UPGRADE_SUCCESSFUL_1802=OpenDJ was successfully upgraded from version %s to %s
-INFO_UPGRADE_PERFORMING_TASKS_1804=Performing upgrade
-INFO_UPGRADE_TITLE_1805=OpenDJ Upgrade Utility
-INFO_UPGRADE_SUMMARY_1806=OpenDJ will be upgraded from version %s to %s
-SEVERE_ERR_UPGRADE_REQUIRES_SERVER_OFFLINE_1811=OpenDJ cannot be upgraded because the server is currently \
+INFO_UPGRADE_SUCCESSFUL_1801=OpenDJ was successfully upgraded from version %s to %s
+INFO_UPGRADE_PERFORMING_TASKS_1802=Performing upgrade
+INFO_UPGRADE_TITLE_1803=OpenDJ Upgrade Utility
+INFO_UPGRADE_SUMMARY_1804=OpenDJ will be upgraded from version %s to %s
+SEVERE_ERR_UPGRADE_REQUIRES_SERVER_OFFLINE_1805=OpenDJ cannot be upgraded because the server is currently \
 running. Please stop the server and try again
-SEVERE_ERR_UPGRADE_VERSION_UP_TO_DATE_1812=OpenDJ has already been upgraded to version %s
-SEVERE_ERR_UPGRADE_DISPLAY_NOTIFICATION_ERROR_1813=An unexpected error occurred \
+SEVERE_ERR_UPGRADE_VERSION_UP_TO_DATE_1806=OpenDJ has already been upgraded to version %s
+SEVERE_ERR_UPGRADE_DISPLAY_NOTIFICATION_ERROR_1807=An unexpected error occurred \
 while attempting to display a notification: %s
-SEVERE_ERR_UPGRADE_DISPLAY_CONFIRM_ERROR_1814=An unexpected error occurred \
+SEVERE_ERR_UPGRADE_DISPLAY_CONFIRM_ERROR_1808=An unexpected error occurred \
 while attempting to display a confirmation : %s
-SEVERE_ERR_UPGRADE_DISPLAY_CHECK_ERROR_1815=An unexpected error occurred \
-while attempting to check a user's option: %s
-SEVERE_ERR_UPGRADE_INVALID_USER_OPTIONS_SELECTED_1816=Invalid user's \
+SEVERE_ERR_UPGRADE_INVALID_USER_OPTIONS_SELECTED_1809=Invalid user's \
 options selected
-INFO_UPGRADE_CHANGE_DONE_IN_SPECIFIC_FILE_1817=...Change(s) done in %s (x%s)
-INFO_UPGRADE_NO_CHANGE_DONE_IN_SPECIFIC_FILE_1818=...No change applied in %s
-SEVERE_ERR_UPGRADE_TASKS_FAIL_1827=\nAn error occurred while performing an upgrade task: %s
-INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM_1828=%s.%nDo you want to make this configuration change?
-INFO_UPGRADE_DISPLAY_CONFIRM_START_1829=The upgrade is ready to proceed. Do you \
+INFO_UPGRADE_CHANGE_DONE_IN_SPECIFIC_FILE_1810=...Change(s) done in %s (x%s)
+INFO_UPGRADE_NO_CHANGE_DONE_IN_SPECIFIC_FILE_1811=...No change applied in %s
+SEVERE_ERR_UPGRADE_TASKS_FAIL_1812=\nAn error occurred while performing an upgrade task: %s
+INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM_1813=%s.%nDo you want to make this configuration change?
+INFO_UPGRADE_DISPLAY_CONFIRM_START_1814=The upgrade is ready to proceed. Do you \
 wish to continue?
-INFO_UPGRADE_ABORTED_BY_USER_1830=The upgrade has been canceled
-SEVERE_ERR_UPGRADE_UNKNOWN_OC_ATT_1831=The %s %s doesn't exist \
+INFO_UPGRADE_ABORTED_BY_USER_1815=The upgrade has been canceled
+SEVERE_ERR_UPGRADE_UNKNOWN_OC_ATT_1816=The %s %s doesn't exist \
 in the template configuration
-SEVERE_ERR_UPGRADE_CONFIG_ERROR_UPGRADE_FOLDER_1832=An error occurred when \
+SEVERE_ERR_UPGRADE_CONFIG_ERROR_UPGRADE_FOLDER_1817=An error occurred when \
 trying to upgrade the config/upgrade folder: %s
-INFO_UPGRADE_REQUIREMENTS_1833=Preparing to upgrade
-INFO_UPGRADE_VERSION_IS_NOT_SUPPORTED_1836=This tool cannot be used for \
+INFO_UPGRADE_REQUIREMENTS_1818=Preparing to upgrade
+INFO_UPGRADE_VERSION_IS_NOT_SUPPORTED_1819=This tool cannot be used for \
 upgrading versions of OpenDJ which are older than '%s'. Please upgrade to \
 '%s' first before attempting further upgrades
-INFO_LICENSE_CLI_ACCEPT_INVALID_RESPONSE_1837=Invalid response
-INFO_LICENSE_DETAILS_CLI_LABEL_1838=Please read the License Agreement above.%n\
+INFO_LICENSE_CLI_ACCEPT_INVALID_RESPONSE_1820=Invalid response
+INFO_LICENSE_DETAILS_CLI_LABEL_1821=Please read the License Agreement above.%n\
  You must accept the terms of the agreement before continuing with the \
  installation
-INFO_LICENSE_ACCEPT_1839=Do you accept the License Agreement?
-INFO_ERROR_COPYING_FILE_1840=An error occurred while copying the file '%s' to '%s'
-INFO_ERROR_DELETING_DIRECTORY_1841=An error occurred while deleting directory '%s'. \
+INFO_LICENSE_ACCEPT_1822=Do you accept the License Agreement?
+INFO_ERROR_COPYING_FILE_1823=An error occurred while copying the file '%s' to '%s'
+INFO_ERROR_DELETING_DIRECTORY_1824=An error occurred while deleting directory '%s'. \
  Check that you have the rights to delete this directory and that there is no other \
  application using it
-INFO_ERROR_DELETING_FILE_1843=An error occurred while deleting file '%s'. Check \
+INFO_ERROR_DELETING_FILE_1825=An error occurred while deleting file '%s'. Check \
 that you have the rights to delete this file and that there is no other application using it
-INFO_ERROR_RENAMING_FILE_1844=An error occurred while renaming file '%s' to '%s'
-SEVERE_ERR_UPGRADE_FAILS_1846=The upgrade failed because %d errors were \
+INFO_ERROR_RENAMING_FILE_1826=An error occurred while renaming file '%s' to '%s'
+SEVERE_ERR_UPGRADE_FAILS_1827=The upgrade failed because %d errors were \
 encountered. Please check log for further details
-SEVERE_ERR_UPGRADE_COPYSCHEMA_FAILS_1847=An error occurred while copying \
+SEVERE_ERR_UPGRADE_COPYSCHEMA_FAILS_1828=An error occurred while copying \
 the schema file '%s': %s
-SEVERE_ERR_UPGRADE_ADDATTRIBUTE_FAILS_1848=An error occurred while adding \
+SEVERE_ERR_UPGRADE_ADDATTRIBUTE_FAILS_1829=An error occurred while adding \
 one or more attributes to the schema file '%s': %s
-SEVERE_ERR_UPGRADE_ADDOBJECTCLASS_FAILS_1849=An error occurred while adding \
+SEVERE_ERR_UPGRADE_ADDOBJECTCLASS_FAILS_1830=An error occurred while adding \
 one or more object classes to the schema file '%s': %s
-INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS_1850=See '%s' for a detailed log of this operation
-INFO_UPGRADE_TASK_REPLACE_SCHEMA_FILE_1851=Replacing schema file '%s'
-INFO_UPGRADE_TASK_REFRESH_UPGRADE_DIRECTORY_1852=Archiving concatenated schema
-INFO_UPGRADE_TASK_ADD_CONFIG_FILE_1853=Adding '%s' configuration file
-SEVERE_ERR_UPGRADE_ADD_CONFIG_FILE_FAILS_1854=An error occurred while adding \
+INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS_1831=See '%s' for a detailed log of this operation
+INFO_UPGRADE_TASK_REPLACE_SCHEMA_FILE_1832=Replacing schema file '%s'
+INFO_UPGRADE_TASK_REFRESH_UPGRADE_DIRECTORY_1833=Archiving concatenated schema
+INFO_UPGRADE_TASK_ADD_CONFIG_FILE_1834=Adding '%s' configuration file
+SEVERE_ERR_UPGRADE_ADD_CONFIG_FILE_FAILS_1835=An error occurred while adding \
 configuration file '%s': %s
-INFO_OPTION_ACCEPT_LICENSE_1855=Automatically accepts the product license \
+INFO_OPTION_ACCEPT_LICENSE_1836=Automatically accepts the product license \
 (if present)
 
 # Upgrade tasks
diff --git a/opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java b/opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java
index 465b839..062477f 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java
@@ -26,8 +26,6 @@
  */
 package org.opends.server.tools.upgrade;
 
-import javax.security.auth.callback.CallbackHandler;
-
 import org.opends.server.tools.ClientException;
 
 /**
@@ -47,7 +45,7 @@
    * {@inheritDoc}
    */
   @Override
-  public void end(UpgradeContext context, CallbackHandler handler)
+  public void end(UpgradeContext context)
       throws ClientException
   {
     // Nothing to do.
@@ -57,7 +55,7 @@
    * {@inheritDoc}
    */
   @Override
-  public void interact(UpgradeContext context, CallbackHandler handler)
+  public void interact(UpgradeContext context)
       throws ClientException
   {
     // Nothing to do.
@@ -67,7 +65,7 @@
    * {@inheritDoc}
    */
   @Override
-  public void start(UpgradeContext context, CallbackHandler handler)
+  public void start(UpgradeContext context)
       throws ClientException
   {
     // Nothing to do.
@@ -77,7 +75,7 @@
    * {@inheritDoc}
    */
   @Override
-  public void verify(UpgradeContext context, CallbackHandler handler)
+  public void verify(UpgradeContext context)
       throws ClientException
   {
     // Nothing to do.
diff --git a/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java b/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
index 128eafd..cc708ea 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
@@ -32,7 +32,6 @@
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.server.tools.upgrade.FormattedNotificationCallback.*;
 import static org.opends.server.tools.upgrade.UpgradeTasks.*;
-import static org.opends.server.tools.upgrade.VerificationCallback.*;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -45,7 +44,6 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.callback.ConfirmationCallback;
 
 import org.opends.messages.Message;
@@ -315,46 +313,35 @@
     return tasks;
   }
 
-
-
   /**
-   * Upgrades the server from {@code fromVersion} to {@code toVersion}.
+   * Upgrades the server from {@code fromVersion} to {@code toVersion} located
+   * in the upgrade context.
    *
-   * @param fromVersion
-   *          The old version.
-   * @param toVersion
-   *          The new version.
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
+   * @param context
+   *          The context of the upgrade.
    * @throws ClientException
    *           If an error occurred while performing the upgrade.
    */
-  public static void upgrade(final BuildVersion fromVersion,
-      final BuildVersion toVersion, final CallbackHandler handler)
+  public static void upgrade(final UpgradeContext context)
       throws ClientException
   {
-    /*
-     * Context through which tasks can interact with the server installation
-     * (e.g. config).
-     */
-    UpgradeContext context = new UpgradeContext(fromVersion, toVersion);
+
 
     // Checks and validate the version number.
-    isVersionCanBeUpdated(context, handler);
+    isVersionCanBeUpdated(context);
 
     // Server offline ?
     checkIfServerIsRunning();
 
-    context.notify(handler, INFO_UPGRADE_TITLE.get(), TITLE_CALLBACK);
-    context.notify(handler, INFO_UPGRADE_SUMMARY.get(context.getFromVersion()
+    context.notify( INFO_UPGRADE_TITLE.get(), TITLE_CALLBACK);
+    context.notify( INFO_UPGRADE_SUMMARY.get(context.getFromVersion()
         .toString(), context.getToVersion().toString()), NOTICE_CALLBACK);
-    context.notify(handler, INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS
+    context.notify( INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS
         .get(UpgradeUtils.getInstallationPath() + File.separator
             + UpgradeLog.UPGRADELOGNAME), NOTICE_CALLBACK);
 
     // Checks License.
-    checkLicence(context, handler);
+    checkLicence(context);
 
     /*
      * Get the list of required upgrade tasks.
@@ -363,7 +350,7 @@
         context.getToVersion());
     if (tasks.isEmpty())
     {
-      changeBuildInfoVersion(context, handler);
+      changeBuildInfoVersion(context);
       return;
     }
 
@@ -373,16 +360,16 @@
      * and the application is non-interactive then, the process
      * may abort immediately.
      */
-    verify(context, tasks, handler);
+    verify(context, tasks);
 
     /*
      * Asking upgrade requirements if needed to user.
      */
-    context.notify(handler, INFO_UPGRADE_REQUIREMENTS.get(), TITLE_CALLBACK);
-    interact(context, tasks, handler);
+    context.notify(INFO_UPGRADE_REQUIREMENTS.get(), TITLE_CALLBACK);
+    interact(context, tasks);
 
     // Starts upgrade.
-    final int userResponse = context.confirmYN(handler,
+    final int userResponse = context.confirmYN(
         INFO_UPGRADE_DISPLAY_CONFIRM_START.get(), ConfirmationCallback.YES);
     if (userResponse == ConfirmationCallback.NO)
     {
@@ -392,50 +379,43 @@
 
     try
     {
-      // If the ignore errors mode is selected.
-      if (context.checkCLIUserOption(handler, IGNORE_ERRORS_MODE)
-          == ConfirmationCallback.YES)
-      {
-        context.setIgnoreErrorsMode(true);
-      }
-
       /*
        * Perform the upgrade tasks.
        */
-      context.notify(handler, INFO_UPGRADE_PERFORMING_TASKS.get(),
+      context.notify(INFO_UPGRADE_PERFORMING_TASKS.get(),
           TITLE_CALLBACK);
 
-      perform(context, tasks, handler);
+      perform(context, tasks);
       if (UpgradeTasks.countErrors == 0)
       {
         // At the end, and if only if succeed, we need to change the buildInfo
         // file with the version number updated.
-        changeBuildInfoVersion(context, handler);
+        changeBuildInfoVersion(context);
 
         // Writes the license if needed.
         LicenseFile.createFileLicenseApproved();
       }
       else
       {
-        context.notify(handler,
+        context.notify(
             ERR_UPGRADE_FAILS.get(UpgradeTasks.countErrors), TITLE_CALLBACK);
       }
     }
     catch (final ClientException e)
     {
       LOG.log(Level.SEVERE, e.getMessage());
-      context.notify(handler, e.getMessageObject());
+      context.notify( e.getMessageObject());
       throw e;
     }
     catch (final Exception e)
     {
       LOG.log(Level.SEVERE, e.getMessage());
-      context.notify(handler, ERR_UPGRADE_TASKS_FAIL.get(e.getMessage()));
+      context.notify(ERR_UPGRADE_TASKS_FAIL.get(e.getMessage()));
       throw new ClientException(EXIT_CODE_ERROR, Message.raw(e.getMessage()));
     }
     finally
     {
-      context.notify(handler, INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS
+      context.notify(INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS
           .get(UpgradeUtils.getInstallationPath() + File.separator
               + UpgradeLog.UPGRADELOGNAME), NOTICE_CALLBACK);
     }
@@ -444,7 +424,7 @@
 
 
   private static void perform(final UpgradeContext context,
-      final List<UpgradeTask> tasks, final CallbackHandler handler)
+      final List<UpgradeTask> tasks)
       throws ClientException
   {
     /*
@@ -452,7 +432,7 @@
      */
     for (final UpgradeTask task : tasks)
     {
-      task.start(context, handler);
+      task.start(context);
     }
 
     /*
@@ -460,7 +440,7 @@
      */
     for (final UpgradeTask task : tasks)
     {
-      task.perform(context, handler);
+      task.perform(context);
     }
 
     /*
@@ -469,7 +449,7 @@
      */
     for (final UpgradeTask task : tasks)
     {
-      task.end(context, handler);
+      task.end(context);
     }
   }
 
@@ -493,7 +473,7 @@
   }
 
   private static void interact(final UpgradeContext context,
-      final List<UpgradeTask> tasks, final CallbackHandler handler)
+      final List<UpgradeTask> tasks)
       throws ClientException
   {
     /*
@@ -501,14 +481,14 @@
      */
     for (final UpgradeTask task : tasks)
     {
-      task.interact(context, handler);
+      task.interact(context);
     }
   }
 
 
 
   private static void verify(final UpgradeContext context,
-      final List<UpgradeTask> tasks, final CallbackHandler handler)
+      final List<UpgradeTask> tasks)
       throws ClientException
   {
     /*
@@ -516,7 +496,7 @@
      */
     for (final UpgradeTask task : tasks)
     {
-      task.verify(context, handler);
+      task.verify(context);
     }
   }
 
@@ -564,13 +544,11 @@
    *
    * @param context
    *          The current context which running the upgrade.
-   * @param callbackHandler
-   *          The callback handler in use.
    * @throws ClientException
    *           If an exception occurs - stops the process.
    */
-  private static void isVersionCanBeUpdated(final UpgradeContext context,
-      final CallbackHandler callbackHandler) throws ClientException
+  private static void isVersionCanBeUpdated(final UpgradeContext context)
+      throws ClientException
   {
     if (context.getFromVersion().equals(context.getToVersion()))
     {
@@ -599,15 +577,13 @@
    *
    * @param context
    *          The current context which running the upgrade.
-   * @param callbackHandler
-   *          The callback handler in use.
    * @throws ClientException
    *           If an exception occurs when displaying the message.
    * @throws IOException
    *           If an exception occurs when trying to write the file.
    */
-  private static void changeBuildInfoVersion(final UpgradeContext context,
-      final CallbackHandler callbackHandler) throws ClientException
+  private static void changeBuildInfoVersion(final UpgradeContext context)
+      throws ClientException
   {
     FileWriter buildInfo = null;
     try
@@ -618,7 +594,7 @@
       // Write the new version
       buildInfo.write(context.getToVersion().toString());
 
-      context.notify(callbackHandler, INFO_UPGRADE_SUCCESSFUL.get(context
+      context.notify(INFO_UPGRADE_SUCCESSFUL.get(context
           .getFromVersion().toString(), context.getToVersion().toString()),
           TITLE_CALLBACK);
 
@@ -634,28 +610,26 @@
   }
 
 
-
-  private static void checkLicence(final UpgradeContext context,
-      final CallbackHandler handler) throws ClientException
+  private static void checkLicence(final UpgradeContext context)
+      throws ClientException
   {
     // Check license
     if (!LicenseFile.isAlreadyApproved())
     {
       if (LicenseFile.exists())
       {
-        context.notify(handler, Message.raw(LicenseFile.getText()));
+        context.notify(Message.raw(LicenseFile.getText()));
 
         // If the user asks for no-prompt. We just display the license text.
         // User doesn't asks for no-prompt. We just display the license text
         // and force to accept it.
-        context.notify(handler, INFO_LICENSE_DETAILS_CLI_LABEL.get());
+        context.notify(INFO_LICENSE_DETAILS_CLI_LABEL.get());
 
-        if (context.checkCLIUserOption(handler, ACCEPT_LICENSE_MODE)
-            == ConfirmationCallback.NO)
+        if (!context.isAcceptLicenseMode())
         {
 
           final int answer =
-              context.confirmYN(handler, INFO_LICENSE_ACCEPT.get(),
+              context.confirmYN(INFO_LICENSE_ACCEPT.get(),
                   ConfirmationCallback.NO);
 
           if (answer == ConfirmationCallback.NO)
@@ -669,8 +643,8 @@
         }
         else
         {
-          context.notify(handler, INFO_LICENSE_ACCEPT.get());
-          context.notify(handler, INFO_PROMPT_YES_COMPLETE_ANSWER.get());
+          context.notify(INFO_LICENSE_ACCEPT.get());
+          context.notify(INFO_PROMPT_YES_COMPLETE_ANSWER.get());
           LicenseFile.setApproval(true);
         }
       }
diff --git a/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java b/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
index eb78921..a2fec11 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
@@ -40,7 +40,6 @@
 FormattedNotificationCallback.TITLE_CALLBACK;
 import static org.opends.server.tools.upgrade.Upgrade.EXIT_CODE_ERROR;
 import static org.opends.server.tools.upgrade.Upgrade.EXIT_CODE_SUCCESS;
-import static org.opends.server.tools.upgrade.VerificationCallback.*;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -359,12 +358,22 @@
     // Main process
     try
     {
+
+      // Upgrade's context.
+      UpgradeContext context =
+          new UpgradeContext(BuildVersion.instanceVersion(), BuildVersion
+              .binaryVersion(), this);
+
+      context.setIgnoreErrorsMode(isIgnoreErrors());
+      context.setAcceptLicenseMode(isAcceptLicense());
+      context.setInteractiveMode(isInteractive());
+      context.setForceUpgradeMode(isForceUpgrade());
+
       // Creates the log file.
       UpgradeLog.initLogFileHandler();
 
       // Starts upgrade.
-      Upgrade.upgrade(BuildVersion.instanceVersion(), BuildVersion
-          .binaryVersion(), this);
+      Upgrade.upgrade(context);
     }
     catch (ClientException ex)
     {
@@ -437,72 +446,6 @@
           throw new IOException("Unsupported message type: ");
         }
       }
-      else if (c instanceof VerificationCallback)
-      {
-        final VerificationCallback cc = (VerificationCallback) c;
-        // Checks user's options.
-        if (cc.getRequiredOptions() != null)
-        {
-          for (final int opt : cc.getRequiredOptions())
-          {
-            if (opt == NEED_USER_INTERACTION)
-            {
-              if (!isInteractive())
-              {
-                cc.setSelectedIndex(cc.getDefaultOption());
-                return;
-              }
-            }
-
-            if (opt == MANDATORY_USER_INTERACTION)
-            {
-              if (!isInteractive() && !isForceUpgrade())
-              {
-                println(Style.ERROR, ERR_UPGRADE_USER_INTERACTION_REQUIRED
-                    .get(OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE), 0);
-                cc.setSelectedIndex(ConfirmationCallback.NO);
-                return;
-              }
-              else if (!isInteractive() && isForceUpgrade())
-              {
-                cc.setSelectedIndex(ConfirmationCallback.YES);
-              }
-            }
-
-            if (opt == TAKE_LONG_TIME_TO_COMPLETE
-                || opt == CANNOT_BE_REVERTED)
-            {
-              if (!isInteractive() && !isForceUpgrade())
-              {
-                println(Style.ERROR, ERR_UPGRADE_USER_INTERACTION_REQUIRED
-                    .get(OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE), 0);
-                cc.setSelectedIndex(ConfirmationCallback.NO);
-                return;
-              }
-            }
-
-            // Does the user specify the ignore errors mode ?
-            if (opt == IGNORE_ERRORS_MODE) {
-              if (!isIgnoreErrors())
-              {
-                cc.setSelectedIndex(ConfirmationCallback.NO);
-                return;
-              }
-              cc.setSelectedIndex(ConfirmationCallback.YES);
-            }
-
-            if (opt == ACCEPT_LICENSE_MODE) {
-              if (!isAcceptLicense())
-              {
-                cc.setSelectedIndex(ConfirmationCallback.NO);
-                return;
-              }
-              cc.setSelectedIndex(ConfirmationCallback.YES);
-            }
-          }
-          return;
-        }
-      }
       else if (c instanceof ConfirmationCallback)
       {
         final ConfirmationCallback cc = (ConfirmationCallback) c;
@@ -597,14 +540,14 @@
             LOG.log(INFO, value);
           }
         }
-        else
+        else // Non interactive mode :
         {
-          // Non interactive mode
+          // Force mode.
           if (isForceUpgrade())
           {
             cc.setSelectedIndex(ConfirmationCallback.YES);
           }
-          else
+          else // Default non interactive mode.
           {
             cc.setSelectedIndex(cc.getDefaultOption());
           }
diff --git a/opends/src/server/org/opends/server/tools/upgrade/UpgradeContext.java b/opends/src/server/org/opends/server/tools/upgrade/UpgradeContext.java
index 8f8e384..679d008 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/UpgradeContext.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/UpgradeContext.java
@@ -28,10 +28,9 @@
 package org.opends.server.tools.upgrade;
 
 import static org.opends.messages.ToolMessages.
-  ERR_UPGRADE_DISPLAY_NOTIFICATION_ERROR;
+ERR_UPGRADE_DISPLAY_NOTIFICATION_ERROR;
 import static org.opends.messages.ToolMessages.
-  ERR_UPGRADE_DISPLAY_CONFIRM_ERROR;
-import static org.opends.messages.ToolMessages.ERR_UPGRADE_DISPLAY_CHECK_ERROR;
+ERR_UPGRADE_DISPLAY_CONFIRM_ERROR;
 import static org.opends.messages.ToolMessages.INFO_PROMPT_NO_COMPLETE_ANSWER;
 import static org.opends.messages.ToolMessages.INFO_PROMPT_YES_COMPLETE_ANSWER;
 import static org.opends.messages.ToolMessages.INFO_TASKINFO_CMD_CANCEL_CHAR;
@@ -64,23 +63,48 @@
   private final BuildVersion toVersion;
 
   /**
+   * The call-back handler for interacting with the upgrade application.
+   */
+  private CallbackHandler handler;
+
+  /**
    * If ignore errors is enabled.
    */
   private boolean isIgnoreErrorsMode;
 
   /**
+   * If accept license is enabled.
+   */
+  private boolean isAcceptLicenseMode;
+
+  /**
+   * If interactive mode is enabled.
+   */
+  private boolean isInteractiveMode;
+
+  /**
+   * If force upgrade is enabled.
+   */
+  private boolean isForceUpgradeMode;
+
+
+  /**
    * Constructor for the upgrade context.
    *
    * @param fromVersion
    *          The version number from we upgrade from.
    * @param toVersion
    *          The version number we want to upgrade to.
+   * @param handler
+   *          The call-back handler for interacting with the upgrade
+   *          application.
    */
-  UpgradeContext(final BuildVersion fromVersion, final BuildVersion toVersion)
+  UpgradeContext(final BuildVersion fromVersion, final BuildVersion toVersion,
+      CallbackHandler handler)
   {
     this.fromVersion = fromVersion;
     this.toVersion = toVersion;
-    this.isIgnoreErrorsMode = false;
+    this.handler = handler;
   }
 
   /**
@@ -106,7 +130,7 @@
   /**
    * Returns the ignore error mode.
    *
-   * @return {@true} if ignore error mode is activated.
+   * @return {code true} if ignore error mode is activated.
    */
   public boolean isIgnoreErrorsMode()
   {
@@ -116,7 +140,8 @@
   /**
    * Sets the ignore errors mode.
    *
-   * @param isIgnoreErrorsMode {@true} if ignore error mode is activated.
+   * @param isIgnoreErrorsMode
+   *          {@code true} if ignore error mode is activated.
    */
   public void setIgnoreErrorsMode(boolean isIgnoreErrorsMode)
   {
@@ -124,18 +149,99 @@
   }
 
   /**
-   * Sends notification message to the application via the call-back handler.
+   * Returns the accept license mode.
+   *
+   * @return {@code true} if accept license mode is activated.
+   */
+  public boolean isAcceptLicenseMode()
+  {
+    return isAcceptLicenseMode;
+  }
+
+  /**
+   * Sets the accept license mode.
+   *
+   * @param isAcceptLicenseMode
+   *          {@code true} if the accept license mode is activated.
+   */
+  public void setAcceptLicenseMode(boolean isAcceptLicenseMode)
+  {
+    this.isAcceptLicenseMode = isAcceptLicenseMode;
+  }
+
+  /**
+   * Returns the callback handler.
+   *
+   * @return The actual callback handler.
+   */
+  public CallbackHandler getHandler()
+  {
+    return handler;
+  }
+
+  /**
+   * Sets the upgrade callback handler.
    *
    * @param handler
    *          The call-back handler for interacting with the upgrade
    *          application.
+   */
+  public void setHandler(CallbackHandler handler)
+  {
+    this.handler = handler;
+  }
+
+  /**
+   * Returns the status of the interactive mode.
+   *
+   * @return {@code true} if interactive mode is activated.
+   */
+  public boolean isInteractiveMode()
+  {
+    return isInteractiveMode;
+  }
+
+  /**
+   * Sets the interactive mode.
+   *
+   * @param isInteractiveMode
+   *          {@code true} if the interactive mode is activated.
+   */
+  public void setInteractiveMode(boolean isInteractiveMode)
+  {
+    this.isInteractiveMode = isInteractiveMode;
+  }
+
+  /**
+   * Returns the status of the force upgrade mode.
+   *
+   * @return {@code true} if the force upgrade mode is activated.
+   */
+  public boolean isForceUpgradeMode()
+  {
+    return isForceUpgradeMode;
+  }
+
+  /**
+   * Sets the force upgrade mode.
+   *
+   * @param isForceUpgradeMode
+   *          {@code true} if the force upgrade mode is activated.
+   */
+  public void setForceUpgradeMode(boolean isForceUpgradeMode)
+  {
+    this.isForceUpgradeMode = isForceUpgradeMode;
+  }
+
+  /**
+   * Sends notification message to the application via the call-back handler.
+   *
    * @param message
    *          The message to be reported.
    * @throws ClientException
    *           If an error occurred while reporting the message.
    */
-  public void notify(final CallbackHandler handler, final Message message)
-      throws ClientException
+  public void notify(final Message message) throws ClientException
   {
     try
     {
@@ -153,9 +259,6 @@
    * Sends notification message to the application via the call-back handler
    * containing specific sub type message.
    *
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
    * @param message
    *          The message to be reported.
    * @param msgType
@@ -163,8 +266,8 @@
    * @throws ClientException
    *           If an error occurred while reporting the message.
    */
-  public void notify(final CallbackHandler handler, final Message message,
-      final int msgType) throws ClientException
+  public void notify(final Message message, final int msgType)
+      throws ClientException
   {
     try
     {
@@ -181,16 +284,13 @@
   /**
    * Displays a progress callback.
    *
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
    * @param callback
    *          The callback to display.
    * @throws ClientException
    *           If an error occurred while reporting the message.
    */
-  public void notifyProgress(final CallbackHandler handler,
-      final ProgressNotificationCallback callback) throws ClientException
+  public void notifyProgress(final ProgressNotificationCallback callback)
+      throws ClientException
   {
     try
     {
@@ -206,9 +306,6 @@
   /**
    * Asks a confirmation to the user. Answer is yes or no.
    *
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
    * @param message
    *          The message to be reported.
    * @param defaultOption
@@ -217,8 +314,8 @@
    *           If an error occurred while reporting the message.
    * @return an integer corresponding to the user's answer.
    */
-  public int confirmYN(final CallbackHandler handler, final Message message,
-      final int defaultOption) throws ClientException
+  public int confirmYN(final Message message, final int defaultOption)
+      throws ClientException
   {
     final ConfirmationCallback confirmYNCallback =
         new ConfirmationCallback(message.toString(),
@@ -237,40 +334,6 @@
   }
 
   /**
-   * Checks the user's options. If a required option is not present in the
-   * user's options list, stops the process.
-   *
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
-   * @param options
-   *          The options which should be present in the user's upgrade options.
-   * @throws ClientException
-   *           If an error occurred while reporting the message.
-   * @return An integer which represents the user selected index.
-   */
-  public int checkCLIUserOption(final CallbackHandler handler,
-      final int... options) throws ClientException
-  {
-    final VerificationCallback checkCLICallback =
-        new VerificationCallback(VerificationCallback.WARNING,
-            ConfirmationCallback.OK_CANCEL_OPTION, ConfirmationCallback.OK,
-            options);
-
-    try
-    {
-      handler.handle(new Callback[] { checkCLICallback });
-    }
-    catch (final Exception e)
-    {
-      throw new ClientException(EXIT_CODE_ERROR,
-          ERR_UPGRADE_DISPLAY_CHECK_ERROR.get(e.getMessage()));
-    }
-    return checkCLICallback.getSelectedIndex();
-
-  }
-
-  /**
    * Returns the default option string.
    *
    * @param defaultOption
diff --git a/opends/src/server/org/opends/server/tools/upgrade/UpgradeTask.java b/opends/src/server/org/opends/server/tools/upgrade/UpgradeTask.java
index 60278f1..f433ddc 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/UpgradeTask.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/UpgradeTask.java
@@ -27,8 +27,6 @@
 
 package org.opends.server.tools.upgrade;
 
-import javax.security.auth.callback.CallbackHandler;
-
 import org.opends.server.tools.ClientException;
 
 /**
@@ -38,6 +36,32 @@
 {
 
   /**
+   * Defines the different types of upgrade tasks.
+   */
+  public enum TaskType {
+    /**
+     * Defines a standard task.
+     */
+    NORMAL,
+    /**
+     * Defines a task which require a standard user interaction.
+     */
+    NEED_USER_INTERACTION,
+    /**
+     * Defines a critical task which require an imperative user interaction.
+     */
+    MANDATORY_USER_INTERACTION,
+    /**
+     * Defines a task which take a long time to complete.
+     */
+    TAKE_LONG_TIME_TO_COMPLETE,
+    /**
+     * Defines a task which cannot be reverted once started.
+     */
+    CANNOT_BE_REVERTED
+  }
+
+  /**
    * Notifies this task that the upgrade has completed. This method will be
    * invoked after all upgrade tasks have completed successfully. Most task
    * implementation will not need to do anything.
@@ -45,13 +69,10 @@
    * @param context
    *          Context through which tasks can interact with the server
    *          installation.
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
    * @throws ClientException
    *           If an error occurred while performing the task.
    */
-  void end(UpgradeContext context, CallbackHandler handler)
+  void end(UpgradeContext context)
       throws ClientException;
 
   /**
@@ -60,13 +81,10 @@
    * @param context
    *          Context through which tasks can interact with the server
    *          installation.
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
    * @throws ClientException
    *           If an error occurred while performing the task.
    */
-  void perform(UpgradeContext context, CallbackHandler handler)
+  void perform(UpgradeContext context)
       throws ClientException;
 
   /**
@@ -77,13 +95,10 @@
    * @param context
    *          Context through which tasks can interact with the server
    *          installation.
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
    * @throws ClientException
    *           If an error occurred while starting the task.
    */
-  void start(UpgradeContext context, CallbackHandler handler)
+  void start(UpgradeContext context)
       throws ClientException;
 
   /**
@@ -92,13 +107,10 @@
    * @param context
    *          Context through which tasks can interact with the server
    *          installation.
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
    * @throws ClientException
    *           If the upgrade cannot proceed.
    */
-  void verify(UpgradeContext context, CallbackHandler handler)
+  void verify(UpgradeContext context)
       throws ClientException;
 
   /**
@@ -109,12 +121,9 @@
    * @param context
    *          Context through which tasks can interact with the server
    *          installation.
-   * @param handler
-   *          The call-back handler for interacting with the upgrade
-   *          application.
    * @throws ClientException
    *           If the upgrade cannot proceed.
    */
-  void interact(UpgradeContext context, CallbackHandler handler)
+  void interact(UpgradeContext context)
       throws ClientException;
 }
diff --git a/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java b/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
index fd55162..3728290 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -27,9 +27,9 @@
 
 package org.opends.server.tools.upgrade;
 
-
-
 import static org.opends.messages.ToolMessages.*;
+import static org.opends.server.tools.ToolConstants.OPTION_LONG_FORCE_UPGRADE;
+import static org.opends.server.tools.ToolConstants.OPTION_LONG_NO_PROMPT;
 import static org.opends.server.tools.upgrade.FileManager.copy;
 import static org.opends.server.tools.upgrade.Upgrade.*;
 import static org.opends.server.tools.upgrade.UpgradeUtils.*;
@@ -40,15 +40,13 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.callback.ConfirmationCallback;
 
 import org.opends.messages.Message;
 import org.opends.server.controls.PersistentSearchChangeType;
 import org.opends.server.protocols.ldap.LDAPFilter;
 import org.opends.server.tools.ClientException;
-
-
+import org.opends.server.tools.upgrade.UpgradeTask.TaskType;
 
 /**
  * Factory methods for create new upgrade tasks.
@@ -66,8 +64,6 @@
   static private final Logger LOG = Logger
       .getLogger(UpgradeCli.class.getName());
 
-
-
   /**
    * Returns a new upgrade task which applies an LDIF record to all
    * configuration entries matching the provided filter.
@@ -85,8 +81,6 @@
     return addConfigEntry0(summary, summary, false, ldif);
   }
 
-
-
   /**
    * Returns a new upgrade task which applies an LDIF record to all
    * configuration entries matching the provided filter.
@@ -106,8 +100,6 @@
     return addConfigEntry0(summary, description, true, ldif);
   }
 
-
-
   /**
    * This task copies the file placed in parameter within the config / schema
    * folder. If the file already exists, it's overwritten.
@@ -123,8 +115,7 @@
     return new AbstractUpgradeTask()
     {
       @Override
-      public void perform(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void perform(final UpgradeContext context) throws ClientException
       {
         final Message msg = INFO_UPGRADE_TASK_REPLACE_SCHEMA_FILE.get(fileName);
         LOG.log(Level.INFO, msg.toString());
@@ -132,45 +123,40 @@
         final ProgressNotificationCallback pnc =
             new ProgressNotificationCallback(0, msg, 0);
 
-        final File schemaFileTemplate = new File(templateConfigSchemaDirectory,
-            fileName);
+        final File schemaFileTemplate =
+            new File(templateConfigSchemaDirectory, fileName);
 
         try
         {
-          context.notifyProgress(handler, pnc.changeProgress(20));
+          context.notifyProgress(pnc.changeProgress(20));
 
           copy(schemaFileTemplate, configSchemaDirectory, true);
-          context.notifyProgress(handler, pnc.changeProgress(100));
+          context.notifyProgress(pnc.changeProgress(100));
         }
         catch (final IOException e)
         {
-          manageTaskException(
-              context,
-              handler,
-              ERR_UPGRADE_COPYSCHEMA_FAILS.get(schemaFileTemplate.getName(),
-                  e.getMessage()), pnc);
+          manageTaskException(context, ERR_UPGRADE_COPYSCHEMA_FAILS.get(
+              schemaFileTemplate.getName(), e.getMessage()), pnc);
         }
       }
     };
   }
 
   /**
-   * This task copies the file placed in parameter within the config
-   * folder. If the file already exists, it's overwritten.
+   * This task copies the file placed in parameter within the config folder. If
+   * the file already exists, it's overwritten.
    *
    * @param fileName
    *          The name of the file which need to be copied.
    * @return A task which copy the the file placed in parameter within the
-   *         config folder. If the file already exists, it's
-   *         overwritten.
+   *         config folder. If the file already exists, it's overwritten.
    */
   public static UpgradeTask addConfigFile(final String fileName)
   {
     return new AbstractUpgradeTask()
     {
       @Override
-      public void perform(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void perform(final UpgradeContext context) throws ClientException
       {
         final Message msg = INFO_UPGRADE_TASK_ADD_CONFIG_FILE.get(fileName);
         LOG.log(Level.INFO, msg.toString());
@@ -178,29 +164,24 @@
         final ProgressNotificationCallback pnc =
             new ProgressNotificationCallback(0, msg, 0);
 
-        final File configFile = new File(templateConfigDirectory,
-            fileName);
+        final File configFile = new File(templateConfigDirectory, fileName);
 
         try
         {
-          context.notifyProgress(handler, pnc.changeProgress(20));
+          context.notifyProgress(pnc.changeProgress(20));
 
           copy(configFile, configDirectory, true);
-          context.notifyProgress(handler, pnc.changeProgress(100));
+          context.notifyProgress(pnc.changeProgress(100));
         }
         catch (final IOException e)
         {
-          manageTaskException(
-              context,
-              handler,
-              ERR_UPGRADE_ADD_CONFIG_FILE_FAILS.get(configFile.getName(),
-                  e.getMessage()), pnc);
+          manageTaskException(context, ERR_UPGRADE_ADD_CONFIG_FILE_FAILS.get(
+              configFile.getName(), e.getMessage()), pnc);
         }
       }
     };
   }
 
-
   /**
    * Returns a new upgrade task which applies an LDIF record to all
    * configuration entries matching the provided filter.
@@ -220,8 +201,6 @@
     return modifyConfigEntry(summary, summary, false, filter, ldif);
   }
 
-
-
   /**
    * Returns a new upgrade task which applies an LDIF record to all
    * configuration entries matching the provided filter.
@@ -243,8 +222,6 @@
     return modifyConfigEntry(summary, description, true, filter, ldif);
   }
 
-
-
   /**
    * This task adds a new attribute type (must exists in the original file) to
    * the specified file placed in parameter. The destination must be a file
@@ -253,11 +230,9 @@
    * already exists in the 00-core.ldif template schema file.
    *
    * <pre>
-   * register(
-   *     &quot;2.5.0.7192&quot;,
-   *     newAttributeTypes(Message.raw(&quot;New attribute etag&quot;), false,
-   *         &quot;00-core.ldif&quot;,
-   *         &quot;etag&quot;));
+   * register(&quot;2.5.0.7192&quot;,
+   *   newAttributeTypes(Message.raw(&quot;New attribute etag&quot;),
+   *   false, &quot;00-core.ldif&quot;, &quot;etag&quot;));
    * </pre>
    *
    * @param summary
@@ -277,40 +252,37 @@
     return new AbstractUpgradeTask()
     {
       @Override
-      public void perform(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void perform(final UpgradeContext context) throws ClientException
       {
         LOG.log(Level.INFO, summary.toString());
 
         final ProgressNotificationCallback pnc =
             new ProgressNotificationCallback(0, summary, 20);
-        context.notifyProgress(handler, pnc);
+        context.notifyProgress(pnc);
 
-        final File schemaFileTemplate = new File(templateConfigSchemaDirectory,
-            fileName);
+        final File schemaFileTemplate =
+            new File(templateConfigSchemaDirectory, fileName);
 
         final File pathDestination = new File(configSchemaDirectory, fileName);
         try
         {
-          final int changeCount = updateSchemaFile(schemaFileTemplate,
-              pathDestination, names, null);
+          final int changeCount =
+              updateSchemaFile(schemaFileTemplate, pathDestination,
+                  names, null);
 
           displayChangeCount(pathDestination.getPath(), changeCount);
 
-          context.notifyProgress(handler, pnc.changeProgress(100));
+          context.notifyProgress(pnc.changeProgress(100));
         }
         catch (final IOException e)
         {
-          manageTaskException(context, handler,
-              ERR_UPGRADE_ADDATTRIBUTE_FAILS.get(schemaFileTemplate.getName(),
-                  e.getMessage()), pnc);
+          manageTaskException(context, ERR_UPGRADE_ADDATTRIBUTE_FAILS.get(
+              schemaFileTemplate.getName(), e.getMessage()), pnc);
         }
       }
     };
   }
 
-
-
   /**
    * This task adds a new object class (must exists in the original file) to the
    * specified file placed in parameter. The destination must be a file
@@ -333,43 +305,40 @@
     return new AbstractUpgradeTask()
     {
       @Override
-      public void perform(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void perform(final UpgradeContext context) throws ClientException
       {
         LOG.log(Level.INFO, summary.toString());
 
         final ProgressNotificationCallback pnc =
             new ProgressNotificationCallback(0, summary, 20);
-        context.notifyProgress(handler, pnc);
+        context.notifyProgress(pnc);
 
-        final File schemaFileTemplate = new File(templateConfigSchemaDirectory,
-            fileName);
+        final File schemaFileTemplate =
+            new File(templateConfigSchemaDirectory, fileName);
 
         final File pathDestination = new File(configSchemaDirectory, fileName);
 
-        context.notifyProgress(handler, pnc.changeProgress(20));
+        context.notifyProgress(pnc.changeProgress(20));
 
         try
         {
-          final int changeCount = updateSchemaFile(schemaFileTemplate,
-              pathDestination, null, names);
+          final int changeCount =
+              updateSchemaFile(schemaFileTemplate, pathDestination,
+                  null, names);
 
           displayChangeCount(pathDestination.getPath(), changeCount);
 
-          context.notifyProgress(handler, pnc.changeProgress(100));
+          context.notifyProgress(pnc.changeProgress(100));
         }
         catch (final IOException e)
         {
-          manageTaskException(context, handler,
-              ERR_UPGRADE_ADDOBJECTCLASS_FAILS.get(
-                  schemaFileTemplate.getName(), e.getMessage()), pnc);
+          manageTaskException(context, ERR_UPGRADE_ADDOBJECTCLASS_FAILS.get(
+              schemaFileTemplate.getName(), e.getMessage()), pnc);
         }
       }
     };
   }
 
-
-
   /**
    * Creates a rebuild all indexes task.
    *
@@ -383,62 +352,37 @@
     {
 
       @Override
-      public void end(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void end(final UpgradeContext context) throws ClientException
       {
         // Nothing to do.
       }
 
-
-
       @Override
-      public void interact(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void interact(final UpgradeContext context) throws ClientException
       {
         // Nothing to do.
       }
 
-
-
       @Override
-      public void perform(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void perform(final UpgradeContext context) throws ClientException
       {
         // TODO
       }
 
-
-
       @Override
-      public void start(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void start(final UpgradeContext context) throws ClientException
       {
-        context.notify(handler, summary);
+        context.notify(summary);
       }
 
-
-
       @Override
-      public void verify(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void verify(final UpgradeContext context) throws ClientException
       {
-        // This task which may take a long time to complete,
-        // we need to check user CLI options.
-        final int res = context.checkCLIUserOption(handler,
-            VerificationCallback.TAKE_LONG_TIME_TO_COMPLETE);
-
-        // The option is not present ? Stops the process.
-        if (res == ConfirmationCallback.NO)
-        {
-          throw new ClientException(EXIT_CODE_MANUAL_INTERVENTION,
-              ERR_UPGRADE_INVALID_USER_OPTIONS_SELECTED.get());
-        }
+        verifyTaskType(TaskType.MANDATORY_USER_INTERACTION, context);
       }
     };
   }
 
-
-
   /**
    * Creates a file object representing config/upgrade/schema.ldif.current which
    * the server creates the first time it starts if there are schema
@@ -453,35 +397,31 @@
     return new AbstractUpgradeTask()
     {
       @Override
-      public void perform(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void perform(final UpgradeContext context) throws ClientException
       {
         final Message msg = INFO_UPGRADE_TASK_REFRESH_UPGRADE_DIRECTORY.get();
         LOG.log(Level.INFO, msg.toString());
 
         final ProgressNotificationCallback pnc =
             new ProgressNotificationCallback(0, msg, 20);
-        context.notifyProgress(handler, pnc);
+        context.notifyProgress(pnc);
 
         try
         {
-          updateConfigUpgradeSchemaFile(configSchemaDirectory,
-              String.valueOf(context.getToVersion().getRevisionNumber()));
+          updateConfigUpgradeSchemaFile(configSchemaDirectory, String
+              .valueOf(context.getToVersion().getRevisionNumber()));
 
-          context.notifyProgress(handler, pnc.changeProgress(100));
+          context.notifyProgress(pnc.changeProgress(100));
         }
         catch (final Exception ex)
         {
-          manageTaskException(context, handler,
-              ERR_UPGRADE_CONFIG_ERROR_UPGRADE_FOLDER.get(ex.getMessage()),
-              pnc);
+          manageTaskException(context, ERR_UPGRADE_CONFIG_ERROR_UPGRADE_FOLDER
+              .get(ex.getMessage()), pnc);
         }
       }
     };
   }
 
-
-
   private static UpgradeTask addConfigEntry0(final Message summary,
       final Message description, final boolean needsUserConfirmation,
       final String... ldif)
@@ -490,42 +430,22 @@
     {
       private boolean userConfirmation = true;
 
-
-
       @Override
-      public void end(final UpgradeContext context,
-          final CallbackHandler handler)
+      public void end(final UpgradeContext context)
       {
         // Nothing to do: no cleanup required.
       }
 
-
-
       @Override
-      public void interact(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void interact(final UpgradeContext context) throws ClientException
       {
         if (needsUserConfirmation)
         {
-          // This task require an interaction with the user
-          // Which means it needs to check if CLI/GUI selected
-          // options are correct.
-          final int res = context.checkCLIUserOption(handler,
-              VerificationCallback.NEED_USER_INTERACTION);
-
           // Process needs to have user's response to perform the current
           // modification.
-          final int answer = context.confirmYN(handler,
-              INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM.get(description),
-              ConfirmationCallback.YES);
-
-          // If the CLI/GUI options are not correct, stops the process
-          // which can happens if user selected non-interactive mode for ex.
-          if (res == ConfirmationCallback.NO)
-          {
-            throw new ClientException(EXIT_CODE_ERROR,
-                ERR_UPGRADE_INVALID_USER_OPTIONS_SELECTED.get());
-          }
+          final int answer =
+              context.confirmYN(INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM
+                  .get(description), ConfirmationCallback.YES);
 
           // The user refuses to perform this task.
           if (answer == ConfirmationCallback.NO)
@@ -535,11 +455,8 @@
         }
       }
 
-
-
       @Override
-      public void perform(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void perform(final UpgradeContext context) throws ClientException
       {
         if (userConfirmation)
         {
@@ -548,71 +465,60 @@
           final ProgressNotificationCallback pnc =
               new ProgressNotificationCallback(0, summary, 20);
 
-          context.notifyProgress(handler, pnc);
+          context.notifyProgress(pnc);
 
           try
           {
             // TODO change the directory to the config if it exists.
-            final File configFile = new File(configDirectory,
-                Installation.CURRENT_CONFIG_FILE_NAME);
+            final File configFile =
+                new File(configDirectory,
+                    Installation.CURRENT_CONFIG_FILE_NAME);
 
-            final int changeCount = updateConfigFile(configFile.getPath(),
-                null, PersistentSearchChangeType.ADD, ldif);
+            final int changeCount =
+                updateConfigFile(configFile.getPath(), null,
+                    PersistentSearchChangeType.ADD, ldif);
 
             displayChangeCount(configFile.getPath(), changeCount);
 
-            context.notifyProgress(handler, pnc.changeProgress(100));
+            context.notifyProgress(pnc.changeProgress(100));
           }
           catch (final Exception e)
           {
-            manageTaskException(context, handler,
-                Message.fromObject(e.getMessage()), pnc);
+            manageTaskException(context, Message.fromObject(e.getMessage()),
+                pnc);
           }
         }
       }
 
-
-
       @Override
-      public void start(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void start(final UpgradeContext context) throws ClientException
       {
         // Nothing to do.
       }
 
-
-
       @Override
-      public void verify(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void verify(final UpgradeContext context) throws ClientException
       {
         // Nothing to do.
       }
     };
   }
 
-
-
   private static void displayChangeCount(final String fileName,
       final int changeCount)
   {
     if (changeCount != 0)
     {
-      LOG.log(
-          Level.INFO,
-          INFO_UPGRADE_CHANGE_DONE_IN_SPECIFIC_FILE.get(fileName,
-              String.valueOf(changeCount)).toString());
+      LOG.log(Level.INFO, INFO_UPGRADE_CHANGE_DONE_IN_SPECIFIC_FILE.get(
+          fileName, String.valueOf(changeCount)).toString());
     }
     else
     {
-      LOG.log(Level.INFO,
-          INFO_UPGRADE_NO_CHANGE_DONE_IN_SPECIFIC_FILE.get(
-              fileName).toString());
+      LOG.log(Level.INFO, INFO_UPGRADE_NO_CHANGE_DONE_IN_SPECIFIC_FILE.get(
+          fileName).toString());
     }
   }
 
-
-
   private static void displayTaskLogInformation(final String summary,
       final String filter, final String... ldif)
   {
@@ -627,14 +533,12 @@
     }
   }
 
-
-
   private static void manageTaskException(final UpgradeContext context,
-      final CallbackHandler handler, final Message message,
-      final ProgressNotificationCallback pnc) throws ClientException
+      final Message message, final ProgressNotificationCallback pnc)
+      throws ClientException
   {
     countErrors++;
-    context.notifyProgress(handler, pnc.changeProgress(-100));
+    context.notifyProgress(pnc.changeProgress(-100));
     LOG.log(Level.SEVERE, message.toString());
     if (!context.isIgnoreErrorsMode())
     {
@@ -642,8 +546,6 @@
     }
   }
 
-
-
   private static UpgradeTask modifyConfigEntry(final Message summary,
       final Message description, final boolean needsUserConfirmation,
       final String filter, final String... ldif)
@@ -652,42 +554,22 @@
     {
       private boolean userConfirmation = true;
 
-
-
       @Override
-      public void end(final UpgradeContext context,
-          final CallbackHandler handler)
+      public void end(final UpgradeContext context)
       {
         // Nothing to do: no cleanup required.
       }
 
-
-
       @Override
-      public void interact(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void interact(final UpgradeContext context) throws ClientException
       {
         if (needsUserConfirmation)
         {
-          // This task require an interaction with the user
-          // Which means it needs to check if CLI/GUI selected
-          // options are correct.
-          final int res = context.checkCLIUserOption(handler,
-              VerificationCallback.NEED_USER_INTERACTION);
-
           // Process needs to have user's response to perform the current
           // modification.
-          final int answer = context.confirmYN(handler,
-              INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM.get(description),
-              ConfirmationCallback.YES);
-
-          // If the CLI/GUI options are not correct, stops the process
-          // which can happen if user selected non-interactive mode for ex.
-          if (res == ConfirmationCallback.NO)
-          {
-            throw new ClientException(EXIT_CODE_ERROR,
-                ERR_UPGRADE_INVALID_USER_OPTIONS_SELECTED.get());
-          }
+          final int answer =
+              context.confirmYN(INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM
+                  .get(description), ConfirmationCallback.YES);
 
           // The user refuses to perform this task.
           if (answer == ConfirmationCallback.NO)
@@ -697,11 +579,8 @@
         }
       }
 
-
-
       @Override
-      public void perform(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void perform(final UpgradeContext context) throws ClientException
       {
         if (userConfirmation)
         {
@@ -710,50 +589,75 @@
           final ProgressNotificationCallback pnc =
               new ProgressNotificationCallback(0, summary, 20);
 
-          context.notifyProgress(handler, pnc);
+          context.notifyProgress(pnc);
 
           try
           {
-            final File configFile = new File(configDirectory,
-                Installation.CURRENT_CONFIG_FILE_NAME);
+            final File configFile =
+                new File(configDirectory,
+                    Installation.CURRENT_CONFIG_FILE_NAME);
 
-            final int changeCount = updateConfigFile(configFile.getPath(),
-                LDAPFilter.decode(filter), PersistentSearchChangeType.MODIFY,
-                ldif);
+            final int changeCount =
+                updateConfigFile(configFile.getPath(), LDAPFilter
+                    .decode(filter), PersistentSearchChangeType.MODIFY, ldif);
 
             displayChangeCount(configFile.getPath(), changeCount);
 
-            context.notifyProgress(handler, pnc.changeProgress(100));
+            context.notifyProgress(pnc.changeProgress(100));
           }
           catch (final Exception e)
           {
-            manageTaskException(context, handler,
-                Message.fromObject(e.getMessage()), pnc);
+            manageTaskException(context, Message.fromObject(e.getMessage()),
+                pnc);
           }
         }
       }
 
-
-
       @Override
-      public void start(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void start(final UpgradeContext context) throws ClientException
       {
         // Nothing to do.
       }
 
-
-
       @Override
-      public void verify(final UpgradeContext context,
-          final CallbackHandler handler) throws ClientException
+      public void verify(final UpgradeContext context) throws ClientException
       {
         // Nothing to do.
       }
     };
   }
 
-
+  @SuppressWarnings("fallthrough")
+  private static void verifyTaskType(final TaskType type,
+      final UpgradeContext context) throws ClientException
+  {
+    /*
+     * Checks CLI/GUI options via context. The process will stop
+     * if user has selected conflicting options.
+     */
+    switch (type)
+    {
+    case NEED_USER_INTERACTION:
+    {
+      // Nothing to do.
+      break;
+    }
+    case MANDATORY_USER_INTERACTION:
+    case TAKE_LONG_TIME_TO_COMPLETE:
+    case CANNOT_BE_REVERTED:
+      // The option is not present ? Stops the process.
+      if (!context.isInteractiveMode() && !context.isForceUpgradeMode())
+      {
+        context.notify(ERR_UPGRADE_USER_INTERACTION_REQUIRED.get(
+            OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE),
+            FormattedNotificationCallback.NOTICE_CALLBACK);
+        throw new ClientException(EXIT_CODE_MANUAL_INTERVENTION,
+            ERR_UPGRADE_INVALID_USER_OPTIONS_SELECTED.get());
+      }
+    default:
+      break;
+    }
+  }
 
   // Prevent instantiation.
   private UpgradeTasks()
diff --git a/opends/src/server/org/opends/server/tools/upgrade/VerificationCallback.java b/opends/src/server/org/opends/server/tools/upgrade/VerificationCallback.java
deleted file mode 100644
index 4c48523..0000000
--- a/opends/src/server/org/opends/server/tools/upgrade/VerificationCallback.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE
- * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at
- * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
- * add the following below this CDDL HEADER, with the fields enclosed
- * by brackets "[]" replaced with your own identifying information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Copyright 2013 ForgeRock AS
- */
-package org.opends.server.tools.upgrade;
-
-import javax.security.auth.callback.ConfirmationCallback;
-
-/**
- * <p>
- * Underlying security services instantiate and pass a
- * <code>VerificationCallback</code> to the <code>handle</code> method of a
- * <code>CallbackHandler</code> to verify user's options.
- */
-public class VerificationCallback extends ConfirmationCallback
-{
-  /**
-   * The serial version UID.
-   */
-  private static final long serialVersionUID = 1L;
-
-  /**
-   * An identifier of a task which need a user interaction.
-   */
-  public static final int NEED_USER_INTERACTION = 0;
-
-  /**
-   * An identifier of a task which require long time to complete.
-   */
-  public static final int TAKE_LONG_TIME_TO_COMPLETE = 1;
-
-  /**
-   * An identifier of a task which cannot be reverted once started.
-   */
-  public static final int CANNOT_BE_REVERTED = 2;
-
-  /**
-   * An identifier of the accept license mode.
-   */
-  public static final int ACCEPT_LICENSE_MODE = 3;
-
-  /**
-   * The identifier of ignore errors mode.
-   */
-  public static final int IGNORE_ERRORS_MODE = 5;
-
-  /**
-   * The identifier of mandatory user interaction.
-   */
-  public static final int MANDATORY_USER_INTERACTION = 6;
-
-
-  // The required options for the verification callback.
-  private int[] requiredOptions;
-
-  /**
-   * Construct a verification callback, which checks user options selected with
-   * required options needed by the process.
-   *
-   * @param messageType
-   *          The type of the message.
-   * @param optionType
-   *          The type of the option.
-   * @param defaultOption
-   *          The default selected option.
-   * @param requiredOptions
-   *          The required option.
-   */
-  public VerificationCallback(int messageType, int optionType,
-      int defaultOption, int... requiredOptions)
-  {
-    super(messageType, optionType, defaultOption);
-    this.requiredOptions = requiredOptions;
-  }
-
-  /**
-   * Returns options required in user's options.
-   *
-   * @return The options required which need to be verified.
-   */
-  public int[] getRequiredOptions()
-  {
-    return requiredOptions;
-  }
-
-  /**
-   * Sets the required options which must be present in the user's options.
-   *
-   * @param requiredOptions
-   *          The options required which need to be verified.
-   */
-  public void setRequiredOptions(final int... requiredOptions)
-  {
-    this.requiredOptions = requiredOptions;
-  }
-
-}

--
Gitblit v1.10.0