KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > launch4j > config > Config


1 /*
2     Launch4j (http://launch4j.sourceforge.net/)
3     Cross-platform Java application wrapper for creating Windows native executables.
4
5     Copyright (C) 2004, 2006 Grzegorz Kowal
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */

21
22 /*
23  * Created on Apr 21, 2005
24  */

25 package net.sf.launch4j.config;
26
27 import java.io.File JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.List JavaDoc;
30
31 import net.sf.launch4j.binding.IValidatable;
32 import net.sf.launch4j.binding.Validator;
33
34 /**
35  * @author Copyright (C) 2005 Grzegorz Kowal
36  */

37 public class Config implements IValidatable {
38
39     // 1.x config properties_____________________________________________________________
40
public static final String JavaDoc HEADER = "header";
41     public static final String JavaDoc JAR = "jar";
42     public static final String JavaDoc OUTFILE = "outfile";
43     public static final String JavaDoc ERR_TITLE = "errTitle";
44     public static final String JavaDoc JAR_ARGS = "jarArgs";
45     public static final String JavaDoc CHDIR = "chdir";
46     public static final String JavaDoc CUSTOM_PROC_NAME = "customProcName";
47     public static final String JavaDoc STAY_ALIVE = "stayAlive";
48     public static final String JavaDoc ICON = "icon";
49
50     // __________________________________________________________________________________
51
public static final String JavaDoc DOWNLOAD_URL = "http://java.com/download";
52
53     public static final String JavaDoc GUI_HEADER = "gui";
54     public static final String JavaDoc CONSOLE_HEADER = "console";
55
56     private static final String JavaDoc[] HEADER_TYPES = new String JavaDoc[] { GUI_HEADER,
57                                                                     CONSOLE_HEADER };
58
59     private static final String JavaDoc[] PRIORITY_CLASS_NAMES = new String JavaDoc[] { "normal",
60                                                                         "idle",
61                                                                         "high" };
62
63     private static final int[] PRIORITY_CLASSES = new int[] { 0x00000020,
64                                                             0x00000040,
65                                                             0x00000080 };
66
67     private boolean dontWrapJar;
68     private String JavaDoc headerType = GUI_HEADER;
69     private List JavaDoc headerObjects;
70     private List JavaDoc libs;
71     private File JavaDoc jar;
72     private File JavaDoc outfile;
73
74     // Runtime header configuration
75
private String JavaDoc errTitle;
76     private String JavaDoc cmdLine;
77     private String JavaDoc chdir;
78     private String JavaDoc priority;
79     private String JavaDoc downloadUrl;
80     private String JavaDoc supportUrl;
81     private boolean customProcName;
82     private boolean stayAlive;
83     private File JavaDoc icon;
84     private List JavaDoc variables;
85     private ClassPath classPath;
86     private Jre jre;
87     private Splash splash;
88     private VersionInfo versionInfo;
89     private Msg messages;
90
91     public void checkInvariants() {
92         Validator.checkTrue(outfile != null && outfile.getPath().endsWith(".exe"),
93                 "outfile", Messages.getString("Config.specify.output.exe"));
94         if (dontWrapJar) {
95             if (jar != null && !jar.getPath().equals("")) {
96                 Validator.checkRelativeWinPath(jar.getPath(), "jar",
97                         Messages.getString("Config.application.jar.path"));
98             } else {
99                 Validator.checkTrue(classPath != null, "classPath",
100                         Messages.getString("ClassPath.or.jar"));
101             }
102         } else {
103             Validator.checkFile(jar, "jar",
104                     Messages.getString("Config.application.jar"));
105         }
106         if (!Validator.isEmpty(chdir)) {
107             Validator.checkRelativeWinPath(chdir, "chdir",
108                     Messages.getString("Config.chdir.relative"));
109             Validator.checkFalse(chdir.toLowerCase().equals("true")
110                     || chdir.toLowerCase().equals("false"),
111                     "chdir", Messages.getString("Config.chdir.path"));
112         }
113         Validator.checkOptFile(icon, "icon", Messages.getString("Config.icon"));
114         Validator.checkOptString(cmdLine, Validator.MAX_BIG_STR, "jarArgs",
115                 Messages.getString("Config.jar.arguments"));
116         Validator.checkOptString(errTitle, Validator.MAX_STR, "errTitle",
117                 Messages.getString("Config.error.title"));
118         Validator.checkOptString(downloadUrl, 256,
119                 "downloadUrl", Messages.getString("Config.download.url"));
120         Validator.checkOptString(supportUrl, 256,
121                 "supportUrl", Messages.getString("Config.support.url"));
122         Validator.checkIn(getHeaderType(), HEADER_TYPES, "headerType",
123                 Messages.getString("Config.header.type"));
124         Validator.checkFalse(getHeaderType().equals(CONSOLE_HEADER) && splash != null,
125                 "headerType",
126                 Messages.getString("Config.splash.not.impl.by.console.hdr"));
127         Validator.checkOptStrings(variables,
128                 Validator.MAX_ARGS,
129                 Validator.MAX_ARGS,
130                 "[^=%\t]+=[^=\t]+",
131                 "variables",
132                 Messages.getString("Config.variables"),
133                 Messages.getString("Config.variables.err"));
134         Validator.checkIn(getPriority(), PRIORITY_CLASS_NAMES, "priority",
135                 Messages.getString("Config.priority"));
136         jre.checkInvariants();
137     }
138     
139     public void validate() {
140         checkInvariants();
141         if (classPath != null) {
142             classPath.checkInvariants();
143         }
144         if (splash != null) {
145             splash.checkInvariants();
146         }
147         if (versionInfo != null) {
148             versionInfo.checkInvariants();
149         }
150     }
151
152     /** Change current directory to EXE location. */
153     public String JavaDoc getChdir() {
154         return chdir;
155     }
156
157     public void setChdir(String JavaDoc chdir) {
158         this.chdir = chdir;
159     }
160
161     /** Constant command line arguments passed to the application. */
162     public String JavaDoc getCmdLine() {
163         return cmdLine;
164     }
165
166     public void setCmdLine(String JavaDoc cmdLine) {
167         this.cmdLine = cmdLine;
168     }
169
170     /** Optional, error message box title. */
171     public String JavaDoc getErrTitle() {
172         return errTitle;
173     }
174
175     public void setErrTitle(String JavaDoc errTitle) {
176         this.errTitle = errTitle;
177     }
178
179     /** launch4j header file. */
180     public String JavaDoc getHeaderType() {
181         return headerType.toLowerCase();
182     }
183
184     public void setHeaderType(String JavaDoc headerType) {
185         this.headerType = headerType;
186     }
187
188     /** launch4j header file index - used by GUI. */
189     public int getHeaderTypeIndex() {
190         int x = Arrays.asList(HEADER_TYPES).indexOf(getHeaderType());
191         return x != -1 ? x : 0;
192     }
193
194     public void setHeaderTypeIndex(int headerTypeIndex) {
195         headerType = HEADER_TYPES[headerTypeIndex];
196     }
197
198     public boolean isCustomHeaderObjects() {
199         return headerObjects != null && !headerObjects.isEmpty();
200     }
201
202     public List JavaDoc getHeaderObjects() {
203         return isCustomHeaderObjects() ? headerObjects
204                 : getHeaderType().equals(GUI_HEADER)
205                         ? LdDefaults.GUI_HEADER_OBJECTS
206                         : LdDefaults.CONSOLE_HEADER_OBJECTS;
207     }
208
209     public void setHeaderObjects(List JavaDoc headerObjects) {
210         this.headerObjects = headerObjects;
211     }
212
213     public boolean isCustomLibs() {
214         return libs != null && !libs.isEmpty();
215     }
216
217     public List JavaDoc getLibs() {
218         return isCustomLibs() ? libs : LdDefaults.LIBS;
219     }
220
221     public void setLibs(List JavaDoc libs) {
222         this.libs = libs;
223     }
224
225     /** ICO file. */
226     public File JavaDoc getIcon() {
227         return icon;
228     }
229
230     public void setIcon(File JavaDoc icon) {
231         this.icon = icon;
232     }
233
234     /** Jar to wrap. */
235     public File JavaDoc getJar() {
236         return jar;
237     }
238
239     public void setJar(File JavaDoc jar) {
240         this.jar = jar;
241     }
242
243     public List JavaDoc getVariables() {
244         return variables;
245     }
246
247     public void setVariables(List JavaDoc variables) {
248         this.variables = variables;
249     }
250
251     public ClassPath getClassPath() {
252         return classPath;
253     }
254     
255     public void setClassPath(ClassPath classpath) {
256         this.classPath = classpath;
257     }
258
259     /** JRE configuration */
260     public Jre getJre() {
261         return jre;
262     }
263
264     public void setJre(Jre jre) {
265         this.jre = jre;
266     }
267
268     /** Output EXE file. */
269     public File JavaDoc getOutfile() {
270         return outfile;
271     }
272
273     public void setOutfile(File JavaDoc outfile) {
274         this.outfile = outfile;
275     }
276
277     /** Custom process name as the output EXE file name. */
278     public boolean isCustomProcName() {
279         return customProcName;
280     }
281
282     public void setCustomProcName(boolean customProcName) {
283         this.customProcName = customProcName;
284     }
285
286     /** Splash screen configuration. */
287     public Splash getSplash() {
288         return splash;
289     }
290
291     public void setSplash(Splash splash) {
292         this.splash = splash;
293     }
294
295     /** Stay alive after launching the application. */
296     public boolean isStayAlive() {
297         return stayAlive;
298     }
299
300     public void setStayAlive(boolean stayAlive) {
301         this.stayAlive = stayAlive;
302     }
303     
304     public VersionInfo getVersionInfo() {
305         return versionInfo;
306     }
307
308     public void setVersionInfo(VersionInfo versionInfo) {
309         this.versionInfo = versionInfo;
310     }
311
312     public boolean isDontWrapJar() {
313         return dontWrapJar;
314     }
315
316     public void setDontWrapJar(boolean dontWrapJar) {
317         this.dontWrapJar = dontWrapJar;
318     }
319
320     public int getPriorityIndex() {
321         int x = Arrays.asList(PRIORITY_CLASS_NAMES).indexOf(getPriority());
322         return x != -1 ? x : 0;
323     }
324     
325     public void setPriorityIndex(int x) {
326         priority = PRIORITY_CLASS_NAMES[x];
327     }
328
329     public String JavaDoc getPriority() {
330         return Validator.isEmpty(priority) ? PRIORITY_CLASS_NAMES[0] : priority;
331     }
332
333     public void setPriority(String JavaDoc priority) {
334         this.priority = priority;
335     }
336     
337     public int getPriorityClass() {
338         return PRIORITY_CLASSES[getPriorityIndex()];
339     }
340     
341     public String JavaDoc getDownloadUrl() {
342         return Validator.isEmpty(downloadUrl) ? DOWNLOAD_URL : downloadUrl;
343     }
344
345     public void setDownloadUrl(String JavaDoc downloadUrl) {
346         this.downloadUrl = downloadUrl;
347     }
348
349     public String JavaDoc getSupportUrl() {
350         return supportUrl;
351     }
352
353     public void setSupportUrl(String JavaDoc supportUrl) {
354         this.supportUrl = supportUrl;
355     }
356
357     public Msg getMessages() {
358         return messages;
359     }
360
361     public void setMessages(Msg messages) {
362         this.messages = messages;
363     }
364 }
365
Popular Tags