KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > UninstallManager


1 /*
2  
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5  
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8  
9  */

10
11 package org.mmbase.applications.packaging;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.mmbase.applications.packaging.bundlehandlers.BundleInterface;
16 import org.mmbase.applications.packaging.installhandlers.uninstallThread;
17 import org.mmbase.applications.packaging.packagehandlers.PackageInterface;
18 import org.mmbase.util.logging.Logger;
19 import org.mmbase.util.logging.Logging;
20
21 /**
22  * install manager, keeps track of what is being installed, provides background
23  * threads and logs errors & message to feedback to users.
24  *
25  * @author Daniel Ockeloen (MMBased)
26  */

27 public class UninstallManager {
28     private static Logger log = Logging.getLoggerInstance(UninstallManager.class);
29
30     // is the uninstall manager active (for dependencies reasons)
31
private static boolean active = false;
32
33     // signal if we are installing a bundle or a package
34
private static boolean bundle = false;
35  
36     // package we are uninstalling
37
private static PackageInterface pkg;
38
39     private static BundleInterface bnd;
40
41     private static uninstallThread runner;
42
43     private static String JavaDoc state;
44
45     /**
46     * uninstall a package
47     */

48     public static synchronized boolean uninstallPackage(PackageInterface p) {
49         if (!active) {
50             // turn the uninstallManager to active
51
active = true;
52         
53             // signal we are a package only install
54
bundle = false;
55
56             // set the package
57
pkg = p;
58             state = "uninstalling";
59             p.clearInstallSteps();
60             runner = new uninstallThread();
61             return true;
62         } else {
63             // returning false _allways_ means we where busy
64
// error feedback is provided by the processsteps
65
return false;
66         }
67     }
68
69
70     /**
71     * called by the install thread class, performs the real install in
72     * the background and keeps providing feedback using the steps interfaces
73     */

74     public static void performUninstall() {
75         try {
76             if (bnd != null) {
77                 bnd.uninstall();
78                 state = "waiting";
79                 active = false;
80                 bnd = null;
81             } else if (pkg != null) {
82                 pkg.uninstall();
83                 state = "waiting";
84                 active = false;
85                 pkg = null;
86             }
87         } catch(Exception JavaDoc e) {
88             log.error("performInstall problem");
89         }
90     }
91
92
93     /**
94     * uninstall a package
95     */

96     public static synchronized boolean uninstallBundle(BundleInterface b) {
97         if (!active) {
98             // turn the uninstallManager to active
99
active = true;
100         
101             // signal we are a package only install
102
bundle = true;
103
104             // set the package
105
bnd = b;
106
107             state = "uninstalling";
108
109             b.clearInstallSteps();
110
111             runner = new uninstallThread();
112         
113             return true;
114         } else {
115             // returning false _allways_ means we where busy
116
// error feedback is provided by the processsteps
117
return false;
118         }
119     }
120
121
122     public void setState(String JavaDoc state) {
123         this.state = state;
124     }
125     
126     public String JavaDoc getState() {
127         return state;
128     }
129
130     public static boolean isActive() {
131         return active;
132     }
133
134     public static PackageInterface getUnInstallingPackage() {
135         return pkg;
136     }
137
138     public static BundleInterface getUnInstallingBundle() {
139         return bnd;
140     }
141
142     public static Iterator JavaDoc getUninstallSteps() {
143         return pkg.getInstallSteps();
144     }
145 }
146
Popular Tags