From e1e9596f6ae81d9aeb74177cf2792533966f45eb Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Mon, 23 Jul 2007 18:25:05 +0000
Subject: [PATCH] This commit does some initial work in anticipation of the reverter tool:

---
 opends/src/quicksetup/org/opends/quicksetup/Application.java |   93 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 77 insertions(+), 16 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/Application.java b/opends/src/quicksetup/org/opends/quicksetup/Application.java
index 594c160..789d738 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/Application.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/Application.java
@@ -30,7 +30,6 @@
 import org.opends.admin.ads.util.ApplicationTrustManager;
 import org.opends.quicksetup.event.ProgressNotifier;
 import org.opends.quicksetup.event.ProgressUpdateListener;
-import org.opends.quicksetup.event.ProgressUpdateEvent;
 import org.opends.quicksetup.util.ServerController;
 import org.opends.quicksetup.util.Utils;
 import org.opends.quicksetup.util.ProgressMessageFormatter;
@@ -39,9 +38,10 @@
 
 import java.io.PrintStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.HashSet;
 
 /**
  * This class represents an application that can be run in the context of
@@ -56,9 +56,6 @@
   /** Represents current install state. */
   protected CurrentInstallStatus installStatus;
 
-  private HashSet<ProgressUpdateListener> listeners =
-      new HashSet<ProgressUpdateListener>();
-
   private UserData userData;
 
   private Installation installation;
@@ -70,6 +67,9 @@
   /** Formats progress messages. */
   protected ProgressMessageFormatter formatter;
 
+  /** Handler for listeners and event firing. */
+  protected ProgressUpdateListenerDelegate listenerDelegate;
+
   /**
    * Creates an application by instantiating the Application class
    * denoted by the System property
@@ -138,7 +138,7 @@
    */
   public void addProgressUpdateListener(ProgressUpdateListener l)
   {
-    listeners.add(l);
+    listenerDelegate.addProgressUpdateListener(l);
   }
 
   /**
@@ -147,7 +147,7 @@
    */
   public void removeProgressUpdateListener(ProgressUpdateListener l)
   {
-    listeners.remove(l);
+    listenerDelegate.removeProgressUpdateListener(l);
   }
 
   /**
@@ -224,13 +224,8 @@
   public void notifyListeners(Integer ratio, String currentPhaseSummary,
       String newLogDetail)
   {
-    ProgressUpdateEvent ev =
-        new ProgressUpdateEvent(getCurrentProgressStep(), ratio,
-                currentPhaseSummary, newLogDetail);
-    for (ProgressUpdateListener l : listeners)
-    {
-      l.progressUpdate(ev);
-    }
+    listenerDelegate.notifyListeners(getCurrentProgressStep(),
+            ratio, currentPhaseSummary, newLogDetail);
   }
 
   /**
@@ -322,6 +317,7 @@
    */
   public void setProgressMessageFormatter(ProgressMessageFormatter formatter) {
     this.formatter = formatter;
+    this.listenerDelegate = new ProgressUpdateListenerDelegate(formatter);
   }
 
   /**
@@ -585,8 +581,73 @@
     return ui;
   }
 
-  static private String getMessage(String key, String... args) {
-    return ResourceProvider.getInstance().getMsg(key, args);
+  /**
+   * Conditionally notifies listeners of the log file if it
+   * has been initialized.
+   */
+  protected void notifyListenersOfLog() {
+    File logFile = QuickSetupLog.getLogFile();
+    if (logFile != null) {
+      notifyListeners(
+          getFormattedProgress(getMsg("general-see-for-details",
+              logFile.getPath())) +
+          formatter.getLineBreak());
+    }
+  }
+
+  /**
+   * Writes an initial record in the installation's historical
+   * log describing moving from one version to another.
+   * @param fromVersion from with install will be migrated
+   * @param toVersion to which install will be migrated
+   * @return Long ID for this session
+   * @throws ApplicationException if something goes wrong
+   */
+  protected Long writeInitialHistoricalRecord(
+          BuildInformation fromVersion,
+          BuildInformation toVersion)
+          throws ApplicationException {
+    Long id;
+    try {
+      HistoricalLog log =
+              new HistoricalLog(getInstallation().getHistoryLogFile());
+      id = log.append(fromVersion, toVersion,
+              HistoricalRecord.Status.STARTED,
+              "log file '" + QuickSetupLog.getLogFile().getPath() + "'");
+    } catch (IOException e) {
+      String msg = getMsg("error-logging-operation");
+      throw ApplicationException.createFileSystemException(
+              msg, e);
+    }
+    return id;
+  }
+
+  /**
+   * Writes a record into this installation's historical log.
+   * @param id obtained from calling <code>writeInitialHistoricalRecord</code>
+   * @param from version from with install will be migrated
+   * @param to version to which install will be migrated
+   * @param status of the operation
+   * @param note string with additional information
+   * @throws ApplicationException if something goes wrong
+   * @see {@link #writeInitialHistoricalRecord(BuildInformation,
+          BuildInformation)}
+   */
+  protected void writeHistoricalRecord(
+          Long id,
+          BuildInformation from,
+          BuildInformation to,
+          HistoricalRecord.Status status,
+          String note)
+          throws ApplicationException {
+    try {
+      HistoricalLog log =
+              new HistoricalLog(getInstallation().getHistoryLogFile());
+      log.append(id, from, to, status, note);
+    } catch (IOException e) {
+      String msg = getMsg("error-logging-operation");
+      throw ApplicationException.createFileSystemException(msg, e);
+    }
   }
 
   /**

--
Gitblit v1.10.0