001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: package com.izforge.izpack.installer;
021:
022: import java.util.ArrayList;
023: import java.util.HashMap;
024: import java.util.List;
025: import java.util.Locale;
026: import java.util.Map;
027: import java.util.Properties;
028: import java.util.zip.ZipOutputStream;
029:
030: import net.n3.nanoxml.XMLElement;
031:
032: import com.izforge.izpack.Info;
033: import com.izforge.izpack.LocaleDatabase;
034: import com.izforge.izpack.Pack;
035:
036: /**
037: * Encloses information about the install process. This implementation is not thread safe.
038: *
039: * @author Julien Ponge <julien@izforge.com>
040: * @author Johannes Lehtinen <johannes.lehtinen@iki.fi>
041: */
042: public class AutomatedInstallData {
043:
044: // --- Static members -------------------------------------------------
045: public static final String MODIFY_INSTALLATION = "modify.izpack.install";
046: public static final String INSTALLATION_INFORMATION = ".installationinformation";
047:
048: /**
049: * Names of the custom actions types with which they are stored in the installer jar file. These
050: * names are also used to identify the type of custom action in the customData map. Slashes as
051: * first char are needed to use the names as "file" name in the installer jar.
052: */
053: // Attention !! Do not change the existent names and the order.
054: // Add a / as first char at new types. Add new type handling in
055: // Unpacker.
056: static final String[] CUSTOM_ACTION_TYPES = new String[] {
057: "/installerListeners", "/uninstallerListeners",
058: "/uninstallerLibs", "/uninstallerJars" };
059:
060: public static final int INSTALLER_LISTENER_INDEX = 0;
061:
062: public static final int UNINSTALLER_LISTENER_INDEX = 1;
063:
064: public static final int UNINSTALLER_LIBS_INDEX = 2;
065:
066: public static final int UNINSTALLER_JARS_INDEX = 3;
067:
068: // --- Instance members -----------------------------------------------
069:
070: /** The language code. */
071: public String localeISO3;
072:
073: /** The used locale. */
074: public Locale locale;
075:
076: /** The language pack. */
077: public LocaleDatabase langpack;
078:
079: /** The uninstaller jar stream. */
080: public ZipOutputStream uninstallOutJar;
081:
082: /** The inforamtions. */
083: public Info info;
084:
085: /** The complete list of packs. */
086: public List<Pack> allPacks;
087:
088: /** The available packs. */
089: public List availablePacks;
090:
091: /** The selected packs. */
092: public List selectedPacks;
093:
094: /** The panels list. */
095: public List<IzPanel> panels;
096:
097: /** The panels order. */
098: public List panelsOrder;
099:
100: /** The current panel. */
101: public int curPanelNumber;
102:
103: /** Can we close the installer ? */
104: public boolean canClose = false;
105:
106: /** Did the installation succeed ? */
107: public boolean installSuccess = true;
108:
109: /** The xmlData for automated installers. */
110: public XMLElement xmlData;
111:
112: /** Custom data. */
113: public Map<String, List> customData;
114:
115: /**
116: * Maps the variable names to their values
117: */
118: protected Properties variables;
119:
120: /** The attributes used by the panels */
121: protected Map<String, Object> attributes;
122:
123: /** This class should be a singleton. Therefore
124: * the one possible object will be stored in this
125: * static member.
126: */
127: private static AutomatedInstallData self = null;
128:
129: /**
130: * Returns the one possible object of this class.
131: * @return the one possible object of this class
132: */
133: public static AutomatedInstallData getInstance() {
134: return (self);
135: }
136:
137: /** Constructs a new instance of this class.
138: * Only one should be possible, at a scound call a RuntimeException
139: * will be raised. */
140: public AutomatedInstallData() {
141: availablePacks = new ArrayList();
142: selectedPacks = new ArrayList();
143: panels = new ArrayList<IzPanel>();
144: panelsOrder = new ArrayList();
145: xmlData = new XMLElement("AutomatedInstallation");
146: variables = new Properties();
147: attributes = new HashMap<String, Object>();
148: customData = new HashMap<String, List>();
149: if (self != null)
150: throw new RuntimeException(
151: "Panic!! second call of the InstallData Ctor!!");
152: self = this ;
153: }
154:
155: /**
156: * Returns the map of variable values. Modifying this will directly affect the current value of
157: * variables.
158: *
159: * @return the map of variable values
160: */
161: public Properties getVariables() {
162: return variables;
163: }
164:
165: /**
166: * Sets a variable to the specified value. This is short hand for
167: * <code>getVariables().setProperty(var, val)</code>.
168: *
169: * @param var the name of the variable
170: * @param val the new value of the variable
171: * @see #getVariable
172: */
173: public void setVariable(String var, String val) {
174: variables.setProperty(var, val);
175: }
176:
177: /**
178: * Returns the current value of the specified variable. This is short hand for
179: * <code>getVariables().getProperty(var)</code>.
180: *
181: * @param var the name of the variable
182: * @return the value of the variable or null if not set
183: * @see #setVariable
184: */
185: public String getVariable(String var) {
186: return variables.getProperty(var);
187: }
188:
189: /**
190: * Sets the install path.
191: *
192: * @param path the new install path
193: * @see #getInstallPath
194: */
195: public void setInstallPath(String path) {
196: setVariable(ScriptParser.INSTALL_PATH, path);
197: }
198:
199: /**
200: * Returns the install path.
201: *
202: * @return the current install path or null if none set yet
203: * @see #setInstallPath
204: */
205: public String getInstallPath() {
206: return getVariable(ScriptParser.INSTALL_PATH);
207: }
208:
209: /**
210: * Returns the value of the named attribute.
211: *
212: * @param attr the name of the attribute
213: * @return the value of the attribute or null if not set
214: * @see #setAttribute
215: */
216: public Object getAttribute(String attr) {
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 attr, Object val) {
232: if (val == null)
233: attributes.remove(attr);
234: else
235: attributes.put(attr, val);
236:
237: }
238: }
|