KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > installer > util > DateStamp


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4
5 package com.tc.installer.util;
6
7 import java.text.Format JavaDoc;
8 import java.text.SimpleDateFormat JavaDoc;
9 import java.util.Date JavaDoc;
10
11 import com.zerog.ia.api.pub.*;
12
13 /**
14  * This class creates a time stamp with the current time and date. It is created to be used as part of the upgrade
15  * process. The upgrade process renames the parent folder of an existing Terracotta installation with the original name
16  * and a date time stamp appended to the original name.
17  * <p>
18  * Format of renamed folder: "{OLD_NAME}_M-D-YYYY_HH:MM" <br>
19  * e.g. <br>
20  * C:\Program Files\Terracotta <br>
21  * becomes <br>
22  * C:\Program Files\Terracotta_06-23-2006_14:57
23  * <p>
24  * Please take a look at: <a HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">
25  * SimpleDateFormat.java </a> to get the possible Date Format structure.
26  */

27 public class DateStamp extends CustomCodeAction {
28   private static final String JavaDoc INSTALL_MESSAGE = "Creating Date Stamp";
29   private static final String JavaDoc UNINSTALL_MESSAGE = "";
30
31   /**
32    * This is the method that is called at install-time. The InstallerProxy instance provides methods to access
33    * information in the installer, set status, and control flow.
34    * <p>
35    * For the purposes of the this action (DateStamp), this method
36    * <ol>
37    * <li>gets its parameters from the InstallAnywhere Variables $DATE_FORMAT$</li>
38    * <li>sets the InstallAnywhere variable $FORAMATTED_DATE$ with the current date whose <br>
39    * date format is specified by $DATE_FORMAT$</li>
40    * </ol>
41    *
42    * @see com.zerog.ia.api.pub.CustomCodeAction#install
43    */

44   public void install(InstallerProxy ip) throws InstallException {
45
46     try {
47       String JavaDoc DateFormat = ip.substitute("$DATE_FORMAT$");
48       String JavaDoc formattedDate = createFormattedDate(DateFormat);
49       ip.setVariable("FORMATTED_DATE", formattedDate);
50     } catch (Exception JavaDoc e) {
51       throw new NonfatalInstallException(e.getMessage());
52     }
53   }
54
55   /**
56    * This is the method that is called at uninstall-time. The UninstallerProxy instance provides methods to access
57    * information in the installer, set status, and control flow.
58    * <p>
59    * For the purposes of the this action (DateStamp), this method is not used.
60    */

61   public void uninstall(UninstallerProxy up) throws InstallException {
62   }
63
64   
65   /**
66    * Returns the current date/time in the date format specified by dateFormat
67    * @param dateFormat The date format we want for the current date/time
68    */

69   private String JavaDoc createFormattedDate(String JavaDoc dateFormat) {
70     // Make a new Date object. It will be initialized to the current time.
71
Date JavaDoc now = new Date JavaDoc();
72     String JavaDoc formattedDate;
73     Format JavaDoc formatter;
74
75     // Typical value for $DATE_FORMAT$ is "MM-dd-yyyy_HH:mm" e.g. 06-27-2006_14:52
76
formatter = new SimpleDateFormat JavaDoc(dateFormat);
77     formattedDate = formatter.format(now);
78     return formattedDate;
79   }
80
81   /**
82    * This method will be called to display a status message during the installation.
83    *
84    * @see com.zerog.ia.api.pub.CustomCodeAction#getInstallStatusMessage
85    */

86   public String JavaDoc getInstallStatusMessage() {
87     return INSTALL_MESSAGE;
88   }
89
90   /**
91    * This method will be called to display a status message during the uninstall.
92    *
93    * @see com.zerog.ia.api.pub.CustomCodeAction#getUninstallStatusMessage
94    */

95   public String JavaDoc getUninstallStatusMessage() {
96     return UNINSTALL_MESSAGE;
97   }
98 }
99
Popular Tags