KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > wminstaller > install > InstallationMgr


1 package de.webman.wminstaller.install;
2
3 import java.util.*;
4 import de.webman.wminstaller.app.*;
5
6
7 public class InstallationMgr
8 {
9     /**
10      * This gives the modules which should be processed in the given order.
11      **/

12     private static final Class JavaDoc MODULES[] = {
13         CoreModInst.class,
14         JdkModInst.class,
15         TomcatModInst.class,
16         WebmanModInst.class,
17         DatabaseModInst.class
18     };
19
20     /**
21      * the working module process order.
22      **/

23     ArrayList modlist = null;
24
25
26     public InstallationMgr() {
27         setupMods();
28     }
29     
30     
31     private static final int INIT = 0;
32     private static final int PRE = 1;
33     private static final int INSTALL = 2;
34     private static final int POST = 3;
35     private static final int CONFIGURE = 4;
36     private static final int STAGES[] = {
37         INIT, PRE, INSTALL, POST, CONFIGURE
38     };
39     
40     public void run(HashMap dict)
41         throws InstallationException
42     {
43         Iterator mi;
44         int stage;
45
46         for (stage = 0; stage < STAGES.length; stage++) {
47             for (mi = modlist.iterator(); mi.hasNext(); ) {
48                 ModWrapper mw = (ModWrapper)mi.next();
49                 
50                 try {
51                     switch (STAGES[stage]) {
52                     case PRE:
53                         System.out.print("Prepare " + mw.inst.getName() + " ... ");
54                         System.out.flush();
55                         mw.flag = mw.inst.pre(dict);
56
57                         if (mw.flag == ModuleInstaller.IGNORE) {
58                             System.out.println("will not be installed");
59                             mi.remove();
60                         }
61                         else
62                             System.out.println("OK");
63                         break;
64                     case INSTALL:
65                         if (mw.flag != ModuleInstaller.CONFIGURE) {
66                             System.out.print("Install " + mw.inst.getName() + " ... ");
67                             System.out.flush();
68                             mw.inst.install(dict);
69                             System.out.println("OK");
70                         }
71                         break;
72                     case POST:
73                         if (mw.flag != ModuleInstaller.CONFIGURE) {
74                             System.out.print("Postfix " + mw.inst.getName() + " ... ");
75                             System.out.flush();
76                             mw.inst.post(dict);
77                             System.out.println("OK");
78                         }
79                         break;
80                     case CONFIGURE:
81                         System.out.print("Configure " + mw.inst.getName() + " ... ");
82                         System.out.flush();
83                         mw.inst.configure(dict);
84                         System.out.println("OK");
85                         break;
86                     }
87                 }
88                 catch (InstallationException ie) {
89                     switch (ie.getSeverity()) {
90                     case InstallationException.OK:
91                         System.err.println(ie.getMessage());
92                         break;
93                     case InstallationException.WARNING:
94                         System.err.println("WARNING: " + ie.getMessage());
95                         break;
96                     case InstallationException.FAILED:
97                         System.err.println("ERROR: " + ie.getMessage());
98                         mi.remove();
99                         break;
100                     case InstallationException.FATAL:
101                         System.err.println("FATAL: " + ie.getMessage());
102                         throw ie;
103                     }
104                 }
105             }
106         }
107     }
108     
109     
110     private void setupMods() {
111         modlist = new ArrayList(MODULES.length);
112
113         for (int mc = 0; mc < MODULES.length; mc++) {
114             try {
115                 ModuleInstaller modinst = (ModuleInstaller)MODULES[mc].newInstance();
116                 
117                 modlist.add(new ModWrapper(-1, modinst));
118             }
119             catch (Exception JavaDoc e) {
120                 System.err.println("Brrx. System is broken! (" + e + ")");
121             }
122         }
123     }
124 }
125
126
127
128
129 class ModWrapper {
130     int flag = 0;
131     ModuleInstaller inst = null;
132
133     ModWrapper(int _fl, ModuleInstaller _mi) {
134         flag = _fl;
135         inst = _mi;
136     }
137 }
138
Popular Tags