KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > startup > ModuleHistory


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.startup;
21
22 // LIMITED INTERACTIONS with APIs and UI--may use ModuleInstall,
23
// and FileSystems API, and localized messages (but not notification),
24
// in addition to what is permitted for central classes (utility APIs
25
// and ModuleInfo-related things). Should be possible to use without
26
// the rest of core.
27

28 import org.openide.modules.SpecificationVersion;
29
30 /** Representation of the history of the module.
31  * This includes information such as: whether the module
32  * has been installed before and now just needs to be restored
33  * (or in fact where it was installed); the previous version
34  * of the module, in case it needs to be upgraded.
35  * Used for communication
36  * between the module lister and the module installer.
37  * @author Jesse Glick
38  */

39
40 public final class ModuleHistory {
41     
42     private final String JavaDoc jar;
43     private int oldMajorVers;
44     private SpecificationVersion oldSpecVers;
45     private boolean upgraded;
46     private byte[] installerState;
47     private boolean installerStateChanged = false;
48     
49     /** Create a module history with essential information.
50      * You also need to specify a relative or absolute JAR name.
51      */

52     public ModuleHistory(String JavaDoc jar) {
53         assert jar != null;
54         this.jar = jar;
55         upgraded = false;
56         oldMajorVers = -1;
57         oldSpecVers = null;
58         installerState = null;
59     }
60     
61     /**
62      * The name of the JAR relative to the installation, or
63      * an absolute path.
64      */

65     String JavaDoc getJar() {
66         return jar;
67     }
68     
69     /** True if this module has been installed before. */
70     boolean isPreviouslyInstalled() {
71         return upgraded;
72     }
73     
74     /** The old major version of the module,
75      * before an upgrade.
76      * -1 if unspecified, or it has never been installed before.
77      */

78     int getOldMajorVersion() {
79         return oldMajorVers;
80     }
81     
82     /** The old specification version of the module,
83      * before an upgrade.
84      * null if unspecified, or it has never been installed before.
85      */

86     SpecificationVersion getOldSpecificationVersion() {
87         return oldSpecVers;
88     }
89     
90     /** Signal that a module has been previously installed,
91      * marking it as a possible candidate for upgrade.
92      */

93     void upgrade(int oldMajorVersion, SpecificationVersion oldSpecificationVersion) {
94         upgraded = true;
95         oldMajorVers = oldMajorVersion;
96         oldSpecVers = oldSpecificationVersion;
97     }
98     
99     /** Get the stored state of the ModuleInstall, if any.
100      * Currently this would be a serialized bytestream.
101      * null if unknown or there was no stored state.
102      */

103     byte[] getInstallerState() {
104         return installerState;
105     }
106     
107     /** Set the stored state of the ModuleInstall.
108      * This may be null to indicate that no state
109      * needs to be stored. Otherwise it would currently
110      * be a serialized bytestream.
111      */

112     void setInstallerState(byte[] state) {
113         if (installerState != null && state != null) {
114             installerStateChanged = true;
115         }
116         installerState = state;
117     }
118     
119     /** True if the state of the installer has changed dynamically. */
120     boolean getInstallerStateChanged() {
121         return installerStateChanged;
122     }
123     
124     /** Reset history after an uninstall. */
125     void resetHistory() {
126         upgraded = false;
127         installerState = null;
128         installerStateChanged = false;
129     }
130     
131 }
132
Popular Tags