Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / installer / AutomatedInstallData.java @ 15280

History | View | Annotate | Download (7.91 KB)

1
/*
2
 *  $Id: AutomatedInstallData.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
3
 *  IzPack
4
 *  Copyright (C) 2001-2004 Julien Ponge
5
 *
6
 *  File :               AutomatedInstallData.java
7
 *  Description :        Installer internal data.
8
 *  Author's email :     julien@izforge.com
9
 *  Author's Website :   http://www.izforge.com
10
 *
11
 *  This program is free software; you can redistribute it and/or
12
 *  modify it under the terms of the GNU General Public License
13
 *  as published by the Free Software Foundation; either version 2
14
 *  of the License, or any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
 */
25
package com.izforge.izpack.installer;
26

    
27
import java.util.ArrayList;
28
import java.util.HashMap;
29
import java.util.List;
30
import java.util.Map;
31
import java.util.Properties;
32
import java.util.zip.ZipOutputStream;
33

    
34
import net.n3.nanoxml.XMLElement;
35

    
36
import com.izforge.izpack.Info;
37
import com.izforge.izpack.LocaleDatabase;
38

    
39
/**
40
 *  Encloses information about the install process.
41
 *  This implementation is not thread safe.
42
 *
43
 * @author     Julien Ponge <julien@izforge.com>
44
 * @author     Johannes Lehtinen <johannes.lehtinen@iki.fi>
45
 */
46
public class AutomatedInstallData
47
{
48
  //--- Static members -------------------------------------------------
49

    
50
  /** Names of the custom actions types with which they are stored in the
51
   * installer jar file. These names are also used to identify the type of
52
   * custom action in the customData map. Slashes as first char 
53
   * are needed to use the names as "file" name in the installer jar.
54
   */
55
  // Attention !! Do not change the existent names and the order.
56
  // Add a / as first char at new types. Add new type handling in
57
  // Unpacker.
58
  static final String [] CUSTOM_ACTION_TYPES = new String[] 
59
          {"/installerListeners","/uninstallerListeners", 
60
          "/uninstallerLibs", "/uninstallerJars" };
61
          
62
  public static final int INSTALLER_LISTENER_INDEX = 0;
63
  public static final int UNINSTALLER_LISTENER_INDEX = 1;
64
  public static final int UNINSTALLER_LIBS_INDEX = 2;
65
  public static final int UNINSTALLER_JARS_INDEX = 3;
66
  
67
  /**
68
   *  A Properties based implementation for VariableValueMap
69
   * interface.<p>
70
   *
71
   * TODO: this can be removed as once the deprecated VariableValueMap is gone
72
   * (IzPack v1.7?).
73
   *
74
   * @author     Johannes Lehtinen <johannes.lehtinen@iki.fi>
75
   */
76
  private final static class VariableValueMapImpl extends Properties
77
    implements VariableValueMap
78
  {
79

    
80
    public String getVariable(String var)
81
    {
82
      return getProperty(var);
83
    }
84

    
85
    public void setVariable(String var, String val)
86
    {
87
      if (var != null && val != null)
88
      {
89
        setProperty(var, val);
90
      }
91
    }
92
  }
93

    
94
  //--- Instance members -----------------------------------------------
95

    
96
  /**  The language code. */
97
  public String localeISO3;
98

    
99
  /**  The language pack. */
100
  public LocaleDatabase langpack;
101

    
102
  /**  The uninstaller jar stream. */
103
  public ZipOutputStream uninstallOutJar;
104

    
105
  /**  The inforamtions. */
106
  public Info info;
107

    
108
  /**  The complete list of packs. */
109
  public List allPacks;
110

    
111
  /**  The available packs. */
112
  public List availablePacks;
113

    
114
  /**  The selected packs. */
115
  public List selectedPacks;
116

    
117
  /**  The panels list. */
118
  public List panels;
119

    
120
  /**  The panels order. */
121
  public List panelsOrder;
122

    
123
  /**  The current panel. */
124
  public int curPanelNumber;
125

    
126
  /**  Can we close the installer ? */
127
  public boolean canClose = false;
128

    
129
  /**  Did the installation succeed ? */
130
  public boolean installSuccess = true;
131

    
132
  /**  The xmlData for automated installers. */
133
  public XMLElement xmlData;
134
  
135
  /** Custom  data. */
136
  public Map customData;
137

    
138
  /**
139
   * Maps the variable names to their values
140
   * @deprecated this will change to a simple Properties object as once the
141
   * deprecated VariableValueMap is gone (IzPack v1.7?).
142
   */
143
  protected VariableValueMapImpl variableValueMap;
144
  // TODO: protected Properties variables;
145

    
146
  /**  The attributes used by the panels */
147
  protected Map attributes;
148

    
149
  /**  Constructs a new instance of this class.  */
150
  public AutomatedInstallData()
151
  {
152
    availablePacks = new ArrayList();
153
    selectedPacks = new ArrayList();
154
    panels = new ArrayList();
155
    panelsOrder = new ArrayList();
156
    xmlData = new XMLElement("AutomatedInstallation");
157
    variableValueMap = new VariableValueMapImpl();
158
    // TODO: variables = new Properties();
159
    attributes = new HashMap();
160
    customData = new HashMap();
161
  }
162

    
163
  /**
164
   *  Returns the map of variable values. Modifying this map will directly
165
   *  affect the current value of variables.
166
   *
167
   * @return    the map of variable values
168
   * @deprecated use {@link #getVariables}
169
   */
170
  public VariableValueMap getVariableValueMap()
171
  {
172
    return variableValueMap;
173
  }
174

    
175
  /**
176
   *  Returns the map of variable values. Modifying this will directly affect
177
   *  the current value of variables.
178
   *
179
   * @return    the map of variable values
180
   */
181
  public Properties getVariables()
182
  {
183
    return variableValueMap;
184
    // TODO: return variables;
185
  }
186

    
187
  /**
188
   *  Sets a variable to the specified value. This is short hand for
189
   *  <code>getVariables().setProperty(var, val)</code>.
190
   *
191
   * @param  var  the name of the variable
192
   * @param  val  the new value of the variable
193
   * @see         #getVariable
194
   */
195
  public void setVariable(String var, String val)
196
  {
197
    variableValueMap.setVariable(var, val);
198
    // TODO: variables.setProperty(var, val);
199
  }
200

    
201
  /**
202
   *  Returns the current value of the specified variable. This is short hand
203
   *  for <code>getVariables().getProperty(var)</code>.
204
   *
205
   * @param  var  the name of the variable
206
   * @return      the value of the variable or null if not set
207
   * @see         #setVariable
208
   */
209
  public String getVariable(String var)
210
  {
211
    return variableValueMap.getVariable(var);
212
    // TODO: return variables.getProperty(var);
213
  }
214

    
215
  /**
216
   *  Sets the install path.
217
   *
218
   * @param  path  the new install path
219
   * @see          #getInstallPath
220
   */
221
  public void setInstallPath(String path)
222
  {
223
    setVariable(ScriptParser.INSTALL_PATH, path);
224
  }
225

    
226
  /**
227
   *  Returns the install path.
228
   *
229
   * @return    the current install path or null if none set yet
230
   * @see       #setInstallPath
231
   */
232
  public String getInstallPath()
233
  {
234
    return getVariable(ScriptParser.INSTALL_PATH);
235
  }
236

    
237
  /**
238
   *  Returns the value of the named attribute.
239
   *
240
   * @param  attr  the name of the attribute
241
   * @return       the value of the attribute or null if not set
242
   * @see          #setAttribute
243
   */
244
  public Object getAttribute(String attr)
245
  {
246
    return attributes.get(attr);
247
  }
248

    
249
  /**
250
   *  Sets a named attribute. The panels and other IzPack components can attach
251
   *  custom attributes to InstallData to communicate with each other. For
252
   *  example, a set of co-operating custom panels do not need to implement a
253
   *  common data storage but can use InstallData singleton. The name of the
254
   *  attribute should include the package and class name to prevent name space
255
   *  collisions.
256
   *
257
   * @param  attr  the name of the attribute to set
258
   * @param  val   the value of the attribute or null to unset the attribute
259
   * @see          #getAttribute
260
   */
261
  public void setAttribute(String attr, Object val)
262
  {
263
    if (val == null)
264
      attributes.remove(attr);
265
    else
266
      attributes.put(attr, val);
267

    
268
  }
269
}