KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > installer > AutomatedInstallData


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package com.izforge.izpack.installer;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Properties JavaDoc;
27 import java.util.zip.ZipOutputStream JavaDoc;
28
29 import net.n3.nanoxml.XMLElement;
30
31 import com.izforge.izpack.Info;
32 import com.izforge.izpack.LocaleDatabase;
33
34 /**
35  * Encloses information about the install process. This implementation is not thread safe.
36  *
37  * @author Julien Ponge <julien@izforge.com>
38  * @author Johannes Lehtinen <johannes.lehtinen@iki.fi>
39  */

40 public class AutomatedInstallData
41 {
42
43     // --- Static members -------------------------------------------------
44

45     /**
46      * Names of the custom actions types with which they are stored in the installer jar file. These
47      * names are also used to identify the type of custom action in the customData map. Slashes as
48      * first char are needed to use the names as "file" name in the installer jar.
49      */

50     // Attention !! Do not change the existent names and the order.
51
// Add a / as first char at new types. Add new type handling in
52
// Unpacker.
53
static final String JavaDoc[] CUSTOM_ACTION_TYPES = new String JavaDoc[] { "/installerListeners",
54             "/uninstallerListeners", "/uninstallerLibs", "/uninstallerJars"};
55
56     public static final int INSTALLER_LISTENER_INDEX = 0;
57
58     public static final int UNINSTALLER_LISTENER_INDEX = 1;
59
60     public static final int UNINSTALLER_LIBS_INDEX = 2;
61
62     public static final int UNINSTALLER_JARS_INDEX = 3;
63
64     // --- Instance members -----------------------------------------------
65

66     /** The language code. */
67     public String JavaDoc localeISO3;
68
69     /** The language pack. */
70     public LocaleDatabase langpack;
71
72     /** The uninstaller jar stream. */
73     public ZipOutputStream JavaDoc uninstallOutJar;
74
75     /** The inforamtions. */
76     public Info info;
77
78     /** The complete list of packs. */
79     public List JavaDoc allPacks;
80
81     /** The available packs. */
82     public List JavaDoc availablePacks;
83
84     /** The selected packs. */
85     public List JavaDoc selectedPacks;
86
87     /** The panels list. */
88     public List JavaDoc panels;
89
90     /** The panels order. */
91     public List JavaDoc panelsOrder;
92
93     /** The current panel. */
94     public int curPanelNumber;
95
96     /** Can we close the installer ? */
97     public boolean canClose = false;
98
99     /** Did the installation succeed ? */
100     public boolean installSuccess = true;
101
102     /** The xmlData for automated installers. */
103     public XMLElement xmlData;
104
105     /** Custom data. */
106     public Map JavaDoc customData;
107
108     /**
109      * Maps the variable names to their values
110      */

111     protected Properties JavaDoc variables;
112
113     /** The attributes used by the panels */
114     protected Map JavaDoc attributes;
115     
116     /** This class should be a singleton. Therefore
117      * the one possible object will be stored in this
118      * static member.
119      */

120     private static AutomatedInstallData self = null;
121     
122     /**
123      * Returns the one possible object of this class.
124      * @return the one possible object of this class
125      */

126     public static AutomatedInstallData getInstance()
127     {
128         return( self);
129     }
130
131     /** Constructs a new instance of this class.
132      * Only one should be possible, at a scound call a RuntimeException
133      * will be raised. */

134     public AutomatedInstallData()
135     {
136         availablePacks = new ArrayList JavaDoc();
137         selectedPacks = new ArrayList JavaDoc();
138         panels = new ArrayList JavaDoc();
139         panelsOrder = new ArrayList JavaDoc();
140         xmlData = new XMLElement("AutomatedInstallation");
141         variables = new Properties JavaDoc();
142         attributes = new HashMap JavaDoc();
143         customData = new HashMap JavaDoc();
144         if( self != null )
145             throw new RuntimeException JavaDoc("Panic!! second call of the InstallData Ctor!!");
146         self = this;
147     }
148
149     /**
150      * Returns the map of variable values. Modifying this will directly affect the current value of
151      * variables.
152      *
153      * @return the map of variable values
154      */

155     public Properties JavaDoc getVariables()
156     {
157         return variables;
158     }
159
160     /**
161      * Sets a variable to the specified value. This is short hand for
162      * <code>getVariables().setProperty(var, val)</code>.
163      *
164      * @param var the name of the variable
165      * @param val the new value of the variable
166      * @see #getVariable
167      */

168     public void setVariable(String JavaDoc var, String JavaDoc val)
169     {
170         variables.setProperty(var, val);
171     }
172
173     /**
174      * Returns the current value of the specified variable. This is short hand for
175      * <code>getVariables().getProperty(var)</code>.
176      *
177      * @param var the name of the variable
178      * @return the value of the variable or null if not set
179      * @see #setVariable
180      */

181     public String JavaDoc getVariable(String JavaDoc var)
182     {
183         return variables.getProperty(var);
184     }
185
186     /**
187      * Sets the install path.
188      *
189      * @param path the new install path
190      * @see #getInstallPath
191      */

192     public void setInstallPath(String JavaDoc path)
193     {
194         setVariable(ScriptParser.INSTALL_PATH, path);
195     }
196
197     /**
198      * Returns the install path.
199      *
200      * @return the current install path or null if none set yet
201      * @see #setInstallPath
202      */

203     public String JavaDoc getInstallPath()
204     {
205         return getVariable(ScriptParser.INSTALL_PATH);
206     }
207
208     /**
209      * Returns the value of the named attribute.
210      *
211      * @param attr the name of the attribute
212      * @return the value of the attribute or null if not set
213      * @see #setAttribute
214      */

215     public Object JavaDoc getAttribute(String JavaDoc attr)
216     {
217         return attributes.get(attr);
218     }
219
220     /**
221      * Sets a named attribute. The panels and other IzPack components can attach custom attributes
222      * to InstallData to communicate with each other. For example, a set of co-operating custom
223      * panels do not need to implement a common data storage but can use InstallData singleton. The
224      * name of the attribute should include the package and class name to prevent name space
225      * collisions.
226      *
227      * @param attr the name of the attribute to set
228      * @param val the value of the attribute or null to unset the attribute
229      * @see #getAttribute
230      */

231     public void setAttribute(String JavaDoc attr, Object JavaDoc val)
232     {
233         if (val == null)
234             attributes.remove(attr);
235         else
236             attributes.put(attr, val);
237
238     }
239 }
240
Popular Tags