KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > launcher > LaunchCommand


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.launcher;
18
19 import java.io.File JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22
23 /**
24  * A class that represents the holds the various argument types that are used
25  * in a Java command. In addition, it holds many of the flags that are used
26  * by the {@link LaunchTask} class when executing a JVM process.
27  *
28  * @author Patrick Luby
29  */

30 public class LaunchCommand {
31
32     //------------------------------------------------------------------ Fields
33

34     /**
35      * Cached appendOutput flag.
36      */

37     private boolean appendOutput = false;
38
39     /**
40      * Cached classpath.
41      */

42     private String JavaDoc classpath = null;
43
44     /**
45      * Cached debug flag.
46      */

47     private boolean debug = false;
48
49     /**
50      * Cached displayMinimizedWindow flag.
51      */

52     private boolean displayMinimizedWindow = false;
53
54     /**
55      * Cached disposeMinimizedWindow flag.
56      */

57     private boolean disposeMinimizedWindow = true;
58
59     /**
60      * Cached failOnError flag.
61      */

62     private boolean failOnError = true;
63
64     /**
65      * Cached main class name.
66      */

67     private String JavaDoc mainClassName = null;
68
69     /**
70      * Cached minimizedWindowIcon.
71      */

72     private File JavaDoc minimizedWindowIcon = null;
73
74     /**
75      * Cached minimizedWindowTitle.
76      */

77     private String JavaDoc minimizedWindowTitle = null;
78
79     /**
80      * Cached output file.
81      */

82     private File JavaDoc outputFile = null;
83
84     /**
85      * Cached print flag.
86      */

87     private boolean print = false;
88
89     /**
90      * Cached requireTools flag.
91      */

92     private boolean requireTools = false;
93
94     /**
95      * Cached redirect flag.
96      */

97     private boolean redirect = false;
98
99     /**
100      * Cached arg elements
101      */

102     private ArrayList JavaDoc args = null;
103
104     /**
105      * Cached jvmarg elements
106      */

107     private ArrayList JavaDoc jvmArgs = null;
108
109     /**
110      * Cached sysproperty elements
111      */

112     private HashMap JavaDoc sysProperties = null;
113
114     /**
115      * Cached useSystemIn flag.
116      */

117     private boolean useSystemIn = true;
118
119     /**
120      * Cached waitForChild flag.
121      */

122     private boolean waitForChild = true;
123
124     //----------------------------------------------------------------- Methods
125

126     /**
127      * Get the class name.
128      *
129      * @return the class to execute <code>main(String[])</code>
130      */

131     public String JavaDoc getClassname() {
132
133         return mainClassName;
134
135     }
136
137     /**
138      * Get the classpath.
139      *
140      * @return the classpath
141      */

142     public String JavaDoc getClasspath() {
143
144         return classpath;
145
146     }
147
148     /**
149      * Get the debug flag.
150      *
151      * @return the debug flag
152      */

153     public boolean getDebug() {
154
155         return debug;
156
157     }
158
159     /**
160      * Get the displayMinimizedWindow flag.
161      *
162      * @return the displayMinimizedWindow flag
163      */

164     public boolean getDisplayminimizedwindow() {
165
166         return displayMinimizedWindow;
167
168     }
169
170     /**
171      * Get the disposeMinimizedWindow flag.
172      *
173      * @return the disposeMinimizedWindow flag
174      */

175     public boolean getDisposeminimizedwindow() {
176
177         return disposeMinimizedWindow;
178
179     }
180
181     /**
182      * Get the failOnError flag.
183      *
184      * @return the failOnError flag
185      */

186     public boolean getFailonerror() {
187
188         return failOnError;
189
190     }
191
192     /**
193      * Get the title for the minimized window that will be displayed in the
194      * Windows taskbar.
195      *
196      * @return the title to set for any minimized window that is displayed
197      * in the Windows taskbar
198      */

199     public String JavaDoc getMinimizedwindowtitle() {
200
201         return minimizedWindowTitle;
202
203     }
204
205     /**
206      * Get the icon file for the minimized window that will be displayed in the
207      * Windows taskbar.
208      *
209      * @return the icon file to use for any minimized window that is displayed
210      * in the Windows taskbar
211      */

212     public File JavaDoc getMinimizedwindowicon() {
213
214         return minimizedWindowIcon;
215
216     }
217
218     /**
219      * Get the file that the child JVM's System.out and System.err will be
220      * redirected to.
221      *
222      * @return the File to redirect System.out and System.err to
223      */

224     public File JavaDoc getOutput() {
225
226         return outputFile;
227
228     }
229
230     /**
231      * Get the appendOutput flag.
232      *
233      * @return the appendOutput flag
234      */

235     public boolean getAppendoutput() {
236
237         return appendOutput;
238
239     }
240
241     /**
242      * Get the redirect flag.
243      *
244      * @return the redirect flag
245      */

246     public boolean getRedirectoutput() {
247
248         return redirect;
249
250     }
251
252     /**
253      * Get the list of nested arg elements.
254      *
255      * @return the list of {@link String} objects
256      */

257     public ArrayList JavaDoc getArgs() {
258
259         return args;
260
261     }
262
263     /**
264      * Get the list of nested jvmarg elements.
265      *
266      * @return the list of {@link String} objects
267      */

268     public ArrayList JavaDoc getJvmargs() {
269
270         return jvmArgs;
271
272     }
273
274     /**
275      * Get the print flag.
276      *
277      * @return the print flag
278      */

279     public boolean getPrint() {
280
281         return print;
282
283     }
284
285     /**
286      * Get the requireTools flag.
287      *
288      * @return the requireTools flag
289      */

290     public boolean getRequiretools() {
291
292         return requireTools;
293
294     }
295
296     /**
297      * Get the list of nested sysproperty elements.
298      *
299      * @return the {@link String} objects
300      */

301     public HashMap JavaDoc getSysproperties() {
302
303         return sysProperties;
304
305     }
306
307     /**
308      * Get the useSystemIn flag.
309      *
310      * @return the useSystemIn flag
311      */

312     public boolean getUsesystemin() {
313
314         return useSystemIn;
315
316     }
317
318     /**
319      * Get the waitForChild flag.
320      *
321      * @return the waitForChild flag
322      */

323     public boolean getWaitforchild() {
324
325         return waitForChild;
326
327     }
328
329     /**
330      * Set the print flag.
331      *
332      * @param print the print flag
333      */

334     public void setPrint(boolean print) {
335
336         this.print = print;
337
338     }
339
340     /**
341      * Set the requireTools flag.
342      *
343      * @param requireTools the requireTools flag
344      */

345     public void setRequiretools(boolean requireTools) {
346
347         this.requireTools = requireTools;
348
349     }
350
351     /**
352      * Set the useSystemIn flag. Setting this flag to false will cause this
353      * task to not read System.in. This will cause the child JVM to never
354      * receive any bytes when it reads System.in. Setting this flag to false
355      * is useful in some Unix environments where processes cannot be put in
356      * the background when they read System.in.
357      *
358      * @param useSystemIn the useSystemIn flag
359      */

360     public void setUsesystemin(boolean useSystemIn) {
361
362         this.useSystemIn = useSystemIn;
363
364     }
365
366     /**
367      * Set the waitForChild flag. Setting this flag to true will cause this
368      * task to wait for the child JVM to finish executing before the task
369      * completes. Setting this flag to false will cause this task to complete
370      * immediately after it starts the execution of the child JVM. Setting it
371      * false emulates the "&" background operator in most Unix shells and is
372      * most of set to false when launching server or GUI applications.
373      *
374      * @param waitForChild the waitForChild flag
375      */

376     public void setWaitforchild(boolean waitForChild) {
377
378         this.waitForChild = waitForChild;
379
380     }
381
382     /**
383      * Set the class name.
384      *
385      * @param mainClassName the class to execute <code>main(String[])</code>
386      */

387     public void setClassname(String JavaDoc mainClassName) {
388
389         this.mainClassName = mainClassName;
390
391     }
392
393     /**
394      * Set the classpath.
395      *
396      * @param classpath the classpath
397      */

398     public void setClasspath(String JavaDoc classpath) {
399
400         this.classpath = classpath;
401
402     }
403
404     /**
405      * Set the debug flag.
406      *
407      * @param debug the debug flag
408      */

409     public void setDebug(boolean debug) {
410
411         this.debug = debug;
412
413     }
414
415     /**
416      * Set the displayMinimizedWindow flag. Note that this flag has no effect
417      * on non-Windows platforms. On Windows platform, setting this flag to true
418      * will cause a minimized window to be displayed in the Windows task bar
419      * while the child process is executing. This flag is usually set to true
420      * for server applications that also have their "waitForChild" attribute
421      * set to false via the {@link #setWaitforchild(boolean)} method.
422      *
423      * @param displayMinimizedWindow true if a minimized window should be
424      * displayed in the Windows task bar while the child process is executing
425      */

426     public void setDisplayminimizedwindow(boolean displayMinimizedWindow) {
427
428         this.displayMinimizedWindow = displayMinimizedWindow;
429
430     }
431
432     /**
433      * Set the disposeMinimizedWindow flag. Note that this flag has no effect
434      * on non-Windows platforms. On Windows platform, setting this flag to true
435      * will cause any minimized window that is display by setting the
436      * "displayMinimizedWindow" attribute to true via the
437      * {@link #setDisplayminimizedwindow(boolean)} to be automatically
438      * disposed of when the child JVM's <code>main(String[])</code> returns.
439      * This flag is normally used for applications that don't explicitly call
440      * {@link System#exit(int)}. If an application does not explicitly call
441      * {@link System#exit(int)}, an minimized windows need to be disposed of
442      * for the child JVM to exit.
443      *
444      * @param disposeMinimizedWindow true if a minimized window in the Windows
445      * taskbar should be automatically disposed of after the child JVM's
446      * <code>main(String[])</code> returns
447      */

448     public void setDisposeminimizedwindow(boolean disposeMinimizedWindow) {
449
450         this.disposeMinimizedWindow = disposeMinimizedWindow;
451
452     }
453
454     /**
455      * Set the failOnError flag.
456      *
457      * @param failOnError the failOnError flag
458      */

459     public void setFailonerror(boolean failOnError) {
460
461         this.failOnError = failOnError;
462
463     }
464
465     /**
466      * Set the title for the minimized window that will be displayed in the
467      * Windows taskbar. Note that this property has no effect on non-Windows
468      * platforms.
469      *
470      * @param minimizedWindowTitle the title to set for any minimized window
471      * that is displayed in the Windows taskbar
472      */

473     public void setMinimizedwindowtitle(String JavaDoc minimizedWindowTitle) {
474
475         this.minimizedWindowTitle = minimizedWindowTitle;
476
477     }
478
479     /**
480      * Set the icon file for the minimized window that will be displayed in the
481      * Windows taskbar. Note that this property has no effect on non-Windows
482      * platforms.
483      *
484      * @param minimizedWindowIcon the icon file to use for any minimized window
485      * that is displayed in the Windows taskbar
486      */

487     public void setMinimizedwindowicon(File JavaDoc minimizedWindowIcon) {
488
489         this.minimizedWindowIcon = minimizedWindowIcon;
490
491     }
492
493     /**
494      * Set the file that the child JVM's System.out and System.err will be
495      * redirected to. Output will only be redirected if the redirect flag
496      * is set to true via the {@link #setRedirectoutput(boolean)} method.
497      *
498      * @param outputFile a File to redirect System.out and System.err to
499      */

500     public void setOutput(File JavaDoc outputFile) {
501
502         this.outputFile = outputFile;
503
504     }
505
506     /**
507      * Set the appendOutput flag. Setting this flag to true will cause the child
508      * JVM to append System.out and System.err to the file specified by the
509      * {@link #setOutput(File)} method. Setting this flag to false will cause
510      * the child to overwrite the file.
511      *
512      * @param appendOutput true if output should be appended to the output file
513      */

514     public void setAppendoutput(boolean appendOutput) {
515
516         this.appendOutput = appendOutput;
517
518     }
519
520     /**
521      * Set the list of nested arg elements.
522      *
523      * @param args a list of {@link String} objects
524      */

525     public void setArgs(ArrayList JavaDoc args) {
526
527         this.args = args;
528
529     }
530
531     /**
532      * Set the list of nested jvmarg elements.
533      *
534      * @param jvmArgs a list of {@link String} objects
535      */

536     public void setJvmargs(ArrayList JavaDoc jvmArgs) {
537
538         this.jvmArgs = jvmArgs;
539
540     }
541
542     /**
543      * Set the list of nested sysproperty elements.
544      *
545      * @param sysProperties a map of {@link String} objects
546      */

547     public void setSysproperties(HashMap JavaDoc sysProperties) {
548
549         this.sysProperties = sysProperties;
550
551     }
552
553     /**
554      * Set the redirect flag. Setting this flag to true will cause the child
555      * JVM's System.out and System.err to be redirected to file set using the
556      * {@link #setOutput(File)} method. Setting this flag to false will
557      * cause no redirection.
558      *
559      * @param redirect true if System.out and System.err should be redirected
560      */

561     public void setRedirectoutput(boolean redirect) {
562
563         this.redirect = redirect;
564
565     }
566
567 }
568
Popular Tags