KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > boot > Boot


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2007 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/

19 package org.java.plugin.boot;
20
21 import java.io.File JavaDoc;
22 import java.io.FileInputStream JavaDoc;
23 import java.io.FileNotFoundException JavaDoc;
24 import java.io.FileOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.OutputStreamWriter JavaDoc;
28 import java.io.Writer JavaDoc;
29 import java.net.InetAddress JavaDoc;
30 import java.net.MalformedURLException JavaDoc;
31 import java.net.URL JavaDoc;
32 import java.util.Locale JavaDoc;
33
34 import org.apache.commons.logging.LogFactory;
35 import org.java.plugin.PluginManager;
36 import org.java.plugin.util.ExtendedProperties;
37 import org.java.plugin.util.IoUtil;
38 import org.java.plugin.util.ResourceManager;
39
40 /**
41  * Main class to get JPF based application running in different modes.
42  * Application mode may be specified as <code>jpf.boot.mode</code> configuration
43  * parameter or System property (via <code>-Djpf.boot.mode=</code> command line
44  * argument). Supported values are:
45  * <dl>
46  * <dt>start</dt>
47  * <dd>Runs application in "background" ("service") mode.</dd>
48  * <dt>stop</dt>
49  * <dd>Stops application, running in "background" mode.</dd>
50  * <dt>restart</dt>
51  * <dd>Restarts application, running in "background" mode. If it is not
52  * started, the action is the same as just starting application.</dd>
53  * <dt>shell</dt>
54  * <dd>Runs application in "shell" (or "interactive") mode. It is possible to
55  * control "service" style application from command line. Note, that
56  * already running application will be stopped first.</dd>
57  * <dt>load</dt>
58  * <dd>Only loads application but not starts it as in other modes. This mode
59  * is useful when doing application unit testing or when you only need to
60  * get initialized and ready to be started JPF environment.</dd>
61  * </dl>
62  * The "shell" mode is default. Application will be started in this mode if no
63  * <code>jpf.boot.mode</code> configuration parameter can be found.
64  * <p>
65  * Application configuration is expected to be in Java properties format file.
66  * File look-up procedure is the following:
67  * </p>
68  * <ul>
69  * <li>Check <code>jpf.boot.config</code> System property, if present, load
70  * configuration from that file location</li>
71  * <li>Look for <code>boot.properties</code> file in the current folder.</li>
72  * <li>Look for <code>boot.properties</code> resource in classpath (using
73  * <code>Boot.class.getClassLoader().getResource("boot.properties")</code>
74  * and <code>Boot.class.getResource("boot.properties")</code> methods).</li>
75  * </ul>
76  * <p>
77  * If configuration could not be found, a warning will be printed to console.
78  * It is generally not an error to not use configuration file, you may provide
79  * JPF configuration parameters as System properties. They are always used as
80  * defaults for configuration properties.
81  * </p>
82  * <p>
83  * Note that configuration properties will be loaded using
84  * {@link org.java.plugin.util.ExtendedProperties specially extended}
85  * version of {@link java.util.Properties} class, which supports parameters
86  * substitution. If there is no <code>applicationRoot</code> property available
87  * in the given configuration, the current folder will be published as default
88  * value.
89  * </p>
90  * <p>
91  * Standard configuration parameters are (all are optional when application is
92  * running in "shell" mode):
93  * <dl>
94  * <dt>jpf.boot.mode</dt>
95  * <dd>Application boot mode. Always available as System property also.
96  * Default value is <code>shell</code>.</dd>
97  * <dt>org.java.plugin.boot.appInitializer</dt>
98  * <dd>Application initializer class, for details see
99  * {@link org.java.plugin.boot.ApplicationInitializer}. Default is
100  * {@link org.java.plugin.boot.DefaultApplicationInitializer}.</dd>
101  * <dt>org.java.plugin.boot.errorHandler</dt>
102  * <dd>Error handler class, for details see
103  * {@link org.java.plugin.boot.BootErrorHandler}. Default is
104  * {@link org.java.plugin.boot.BootErrorHandlerConsole} for "service" style
105  * applications and {@link org.java.plugin.boot.BootErrorHandlerGui} for
106  * "interactive" applications.</dd>
107  * <dt>org.java.plugin.boot.controlHost</dt>
108  * <dd>Host to be used by background control service, no default values.</dd>
109  * <dt>org.java.plugin.boot.controlPort</dt>
110  * <dd>Port number to be used by background control service, no default
111  * values.</dd>
112  * <dt>org.java.plugin.boot.splashHandler</dt>
113  * <dd>Splash screen handler class, for details see
114  * {@link org.java.plugin.boot.SplashHandler}. Default is simple splash
115  * handler that can only display an image.</dd>
116  * <dt>org.java.plugin.boot.splashImage</dt>
117  * <dd>Path to an image file to be shown as splash screen. This may be any
118  * valid URL. If no file and no handler given, the splash screen will not
119  * be shown.</dd>
120  * <dt>org.java.plugin.boot.splashLeaveVisible</dt>
121  * <dd>If set to <code>true</code>, the Boot class will not hide splash screen
122  * at the end of boot procedure but delegate this function to application
123  * code. Default value is <code>false</code>.</dd>
124  * <dt>org.java.plugin.boot.splashDisposeOnHide</dt>
125  * <dd>If set to <code>false</code>, the Boot class will not dispose splash
126  * screen handler when hiding it. This allows you to reuse handler and show
127  * splash screen back after it was hidden. Default value is
128  * <code>true</code>.</dd>
129  * </dl>
130  *
131  * @version $Id: Boot.java,v 1.18 2007/01/04 17:10:36 ddimon Exp $
132  */

133 public final class Boot {
134     /**
135      * Name of the file, where to put boot error details.
136      */

137     public static final String JavaDoc BOOT_ERROR_FILE_NAME = "jpf-boot-error.txt"; //$NON-NLS-1$
138

139     /**
140      * Boot configuration file location System property name.
141      */

142     public static final String JavaDoc PROP_BOOT_CONFIG = "jpf.boot.config"; //$NON-NLS-1$
143

144     /**
145      * Boot mode System property name.
146      */

147     public static final String JavaDoc PROP_BOOT_MODE = "jpf.boot.mode"; //$NON-NLS-1$
148

149     /**
150      * "shell" mode boot command value.
151      */

152     public static final String JavaDoc BOOT_MODE_SHELL = "shell"; //$NON-NLS-1$
153

154     /**
155      * "start" mode boot command value.
156      */

157     public static final String JavaDoc BOOT_MODE_START = "start"; //$NON-NLS-1$
158

159     /**
160      * "stop" mode boot command value.
161      */

162     public static final String JavaDoc BOOT_MODE_STOP = "stop"; //$NON-NLS-1$
163

164     /**
165      * "restart" mode boot command value.
166      */

167     public static final String JavaDoc BOOT_MODE_RESTART = "restart"; //$NON-NLS-1$
168

169     /**
170      * "load" mode boot command value.
171      */

172     public static final String JavaDoc BOOT_MODE_LOAD = "load"; //$NON-NLS-1$
173

174     // This is for ResourceManager to look up resources.
175
static final String JavaDoc PACKAGE_NAME = "org.java.plugin.boot"; //$NON-NLS-1$
176

177     // Application bootstrap configuration parameter names goes here
178
private static final String JavaDoc PARAM_CONTROL_HOST =
179         "org.java.plugin.boot.controlHost"; //$NON-NLS-1$
180
private static final String JavaDoc PARAM_CONTROL_PORT =
181         "org.java.plugin.boot.controlPort"; //$NON-NLS-1$
182
private static final String JavaDoc PARAM_ERROR_HANDLER =
183         "org.java.plugin.boot.errorHandler"; //$NON-NLS-1$
184
private static final String JavaDoc PARAM_APP_INITIALIZER =
185         "org.java.plugin.boot.appInitializer"; //$NON-NLS-1$
186
private static final String JavaDoc PARAM_SPLASH_HANDLER =
187         "org.java.plugin.boot.splashHandler"; //$NON-NLS-1$
188
private static final String JavaDoc PARAM_SPLASH_IMAGE =
189         "org.java.plugin.boot.splashImage"; //$NON-NLS-1$
190
private static final String JavaDoc PARAM_SPLASH_LEAVE_VISIBLE =
191         "org.java.plugin.boot.splashLeaveVisible"; //$NON-NLS-1$
192
private static final String JavaDoc PARAM_SPLASH_DISPOSE_ON_HIDE =
193         "org.java.plugin.boot.splashDisposeOnHide"; //$NON-NLS-1$
194
private static final String JavaDoc PARAM_SPLASH_CONFIG_PREFIX =
195         "org.java.plugin.boot.splash."; //$NON-NLS-1$
196

197     static SplashHandler splashHandler = null;
198     
199     /**
200      * Call this method to start/stop application.
201      * @param args command line arguments, not interpreted by this method but
202      * passed to
203      * {@link ApplicationPlugin#initApplication(ExtendedProperties, String[])}
204      * method
205      */

206     public static void main(final String JavaDoc[] args) {
207         clearBootLog();
208         // Load start-up configuration
209
ExtendedProperties props = new ExtendedProperties(
210                 System.getProperties());
211         try {
212             InputStream JavaDoc strm = lookupConfig();
213             try {
214                 props.load(strm);
215             } finally {
216                 strm.close();
217             }
218         } catch (IOException JavaDoc ioe) {
219             ioe.printStackTrace();
220         }
221         String JavaDoc mode = props.getProperty(PROP_BOOT_MODE);
222         if (mode != null) {
223             mode = mode.trim().toLowerCase(Locale.ENGLISH);
224         } else {
225             // set SHELL mode by default
226
mode = BOOT_MODE_SHELL;
227         }
228         props.setProperty(PROP_BOOT_MODE, mode);
229         // Make sure that boot mode is always available as System property:
230
System.setProperty(PROP_BOOT_MODE, mode);
231         boolean useControlService = props.containsKey(PARAM_CONTROL_HOST)
232             && props.containsKey(PARAM_CONTROL_PORT);
233         BootErrorHandler errorHandler = getErrorHandlerInstance(
234                 props.getProperty(PARAM_ERROR_HANDLER), useControlService);
235         try {
236             if (props.getProperty("applicationRoot") == null) { //$NON-NLS-1$
237
// Publish current folder as configuration parameter
238
// to get it available as ${applicationRoot} variable
239
// in extended properties syntax.
240
String JavaDoc applicationRoot = new File JavaDoc(".").getCanonicalPath(); //$NON-NLS-1$
241
props.put("applicationRoot", applicationRoot); //$NON-NLS-1$
242
}
243             boot(props, useControlService, mode, errorHandler, args);
244         } catch (Throwable JavaDoc t) {
245             if (splashHandler != null) {
246                 splashHandler.setVisible(false);
247                 splashHandler = null;
248             }
249             bootLog(t);
250             errorHandler.handleFatalError(ResourceManager.getMessage(
251                     Boot.PACKAGE_NAME, "bootFailed"), t); //$NON-NLS-1$
252
System.exit(1);
253         }
254     }
255     
256     /**
257      * Boots application according to given configuration data.
258      * @param config boot configuration data
259      * @param useControlService if <code>true</code>, the control service will
260      * started to allow handling application instance
261      * from another process
262      * @param mode application run mode
263      * @param errorHandler boot errors handler instance
264      * @param args command line arguments, not interpreted by this method but
265      * passed to
266      * {@link ApplicationPlugin#initApplication(ExtendedProperties, String[])}
267      * method
268      * @return initialized application instance or <code>null</code>
269      * @throws Exception if any un-handled error has occurred
270      */

271     public static Application boot(final ExtendedProperties config,
272             final boolean useControlService, final String JavaDoc mode,
273             final BootErrorHandler errorHandler, final String JavaDoc[] args)
274             throws Exception JavaDoc {
275         InetAddress JavaDoc controlHost = useControlService ? InetAddress.getByName(
276                 config.getProperty(PARAM_CONTROL_HOST)) : null;
277         int controlPort = useControlService ? Integer.parseInt(
278                 config.getProperty(PARAM_CONTROL_PORT), 10) : 0;
279         // handle given command
280
if (useControlService && BOOT_MODE_STOP.equals(mode)) {
281             if (!ControlThread.stopRunningApplication(controlHost,
282                     controlPort)) {
283                 System.out.println("application not running"); //$NON-NLS-1$
284
} else {
285                 System.out.println("application stopped"); //$NON-NLS-1$
286
}
287             return null;
288         }
289         if (useControlService && BOOT_MODE_START.equals(mode)) {
290             if (ControlThread.isApplicationRunning(controlHost,
291                     controlPort)) {
292                 errorHandler.handleFatalError(
293                         "Application already running."); //$NON-NLS-1$
294
return null;
295             }
296             Application application =
297                 initApplication(errorHandler, config, args);
298             if (!(application instanceof ServiceApplication)) {
299                 errorHandler.handleFatalError(
300                         "Application is not a service."); //$NON-NLS-1$
301
return null;
302             }
303             ControlThread controlThread = new ControlThread(controlHost,
304                     controlPort, (ServiceApplication) application);
305             application.startApplication();
306             controlThread.start();
307             System.out.println(
308                     "application started in BACKGROUND mode"); //$NON-NLS-1$
309
return application;
310         }
311         if (useControlService && BOOT_MODE_RESTART.equals(mode)) {
312             if (ControlThread.stopRunningApplication(controlHost,
313                     controlPort)) {
314                 System.out.println("another instance of application stopped"); //$NON-NLS-1$
315
}
316             Application application =
317                 initApplication(errorHandler, config, args);
318             if (!(application instanceof ServiceApplication)) {
319                 errorHandler.handleFatalError(
320                         "Application is not a service."); //$NON-NLS-1$
321
return null;
322             }
323             ControlThread controlThread = new ControlThread(controlHost,
324                     controlPort, (ServiceApplication) application);
325             application.startApplication();
326             controlThread.start();
327             System.out.println(
328                     "application started in BACKGROUND mode"); //$NON-NLS-1$
329
return application;
330         }
331         // SHELL or LOAD or an unknown modes
332
if (useControlService
333                 && ControlThread.stopRunningApplication(controlHost,
334                         controlPort)) {
335             System.out.println("another instance of application stopped"); //$NON-NLS-1$
336
}
337         if (!BOOT_MODE_LOAD.equals(mode)) {
338             initSplashHandler(config);
339             if (splashHandler != null) {
340                 splashHandler.setVisible(true);
341             }
342         }
343         Application application =
344             initApplication(errorHandler, config, args);
345         if (!BOOT_MODE_LOAD.equals(mode)) {
346             application.startApplication();
347             if ((splashHandler != null)
348                     && !"true".equalsIgnoreCase(config.getProperty( //$NON-NLS-1$
349
PARAM_SPLASH_LEAVE_VISIBLE, "false"))) { //$NON-NLS-1$
350
splashHandler.setVisible(false);
351             }
352             if ((application instanceof ServiceApplication)
353                     && BOOT_MODE_SHELL.equals(mode)) {
354                 System.out.println("application started in SHELL mode"); //$NON-NLS-1$
355
runShell();
356                 stopApplication(application);
357             }
358         }
359         return application;
360     }
361     
362     /**
363      * Stops the application, shuts down plug-in manager and disposes log
364      * service. Call this method before exiting interactive application. For
365      * service applications this method will be called automatically by control
366      * service or from shell.
367      * @param application application instance being stopped
368      * @throws Exception if any error has occurred during application stopping
369      */

370     public static void stopApplication(final Application application)
371             throws Exception JavaDoc {
372         if (application instanceof ServiceApplication) {
373             ((ServiceApplication) application).stopApplication();
374         }
375         PluginManager pluginManager = PluginManager.lookup(application);
376         if (pluginManager != null) {
377             pluginManager.shutdown();
378         }
379         LogFactory.getLog(Boot.class).info("logging system finalized"); //$NON-NLS-1$
380
LogFactory.getLog(Boot.class).info("---------------------------------"); //$NON-NLS-1$
381
LogFactory.releaseAll();
382     }
383     
384     /**
385      * Returns current instance of splash screen handler if it is available or
386      * <code>null</code>.
387      * @return instance of splash handler or <code>null</code> if no active
388      * instance available
389      */

390     public static SplashHandler getSplashHandler() {
391         return splashHandler;
392     }
393     
394     /**
395      * @param handler the new splash handler instance to set or
396      * <code>null</code> to dispose current handler directly
397      */

398     public static void setSplashHandler(final SplashHandler handler) {
399         if ((handler == null) && (splashHandler != null)) {
400             splashHandler.setVisible(false);
401         }
402         splashHandler = handler;
403     }
404     
405     private static InputStream JavaDoc lookupConfig() throws IOException JavaDoc {
406         String JavaDoc property = System.getProperty(PROP_BOOT_CONFIG);
407         if (property != null) {
408             return new FileInputStream JavaDoc(property);
409         }
410         File JavaDoc file = new File JavaDoc("boot.properties"); //$NON-NLS-1$
411
if (file.isFile()) {
412             return new FileInputStream JavaDoc(file);
413         }
414         URL JavaDoc url = Boot.class.getClassLoader().getResource("boot.properties"); //$NON-NLS-1$
415
if (url != null) {
416             return IoUtil.getResourceInputStream(url);
417         }
418         url = Boot.class.getResource("boot.properties"); //$NON-NLS-1$
419
if (url != null) {
420             return IoUtil.getResourceInputStream(url);
421         }
422         throw new IOException JavaDoc("configuration file boot.properties not found"); //$NON-NLS-1$
423
}
424
425     private static BootErrorHandler getErrorHandlerInstance(
426             final String JavaDoc handler, final boolean isServiceApp) {
427         if (handler != null) {
428             try {
429                 return (BootErrorHandler) Class.forName(handler).newInstance();
430             } catch (InstantiationException JavaDoc ie) {
431                 System.err.println("failed instantiating error handler " //$NON-NLS-1$
432
+ handler);
433                 ie.printStackTrace();
434             } catch (IllegalAccessException JavaDoc iae) {
435                 System.err.println("failed instantiating error handler " //$NON-NLS-1$
436
+ handler);
437                 iae.printStackTrace();
438             } catch (ClassNotFoundException JavaDoc cnfe) {
439                 System.err.println("failed instantiating error handler " //$NON-NLS-1$
440
+ handler);
441                 cnfe.printStackTrace();
442             }
443         }
444         return isServiceApp ? new BootErrorHandlerConsole()
445                 : (BootErrorHandler) new BootErrorHandlerGui();
446     }
447
448     private static void initSplashHandler(final ExtendedProperties config)
449             throws Exception JavaDoc {
450         String JavaDoc handlerClass = config.getProperty(PARAM_SPLASH_HANDLER);
451         String JavaDoc splashImage = config.getProperty(PARAM_SPLASH_IMAGE);
452         URL JavaDoc url = null;
453         if ((splashImage != null) && (splashImage.length() > 0)) {
454             try {
455                 url = new URL JavaDoc(splashImage);
456             } catch (MalformedURLException JavaDoc mue) {
457                 // ignore
458
}
459             if (url == null) {
460                 File JavaDoc splashFile = new File JavaDoc(splashImage);
461                 if (splashFile.isFile()) {
462                     url = IoUtil.file2url(splashFile);
463                 } else {
464                     throw new FileNotFoundException JavaDoc("splash image file " //$NON-NLS-1$
465
+ splashFile + " not found"); //$NON-NLS-1$
466
}
467             }
468         }
469         boolean disposeOnHide = !"false".equalsIgnoreCase( //$NON-NLS-1$
470
config.getProperty(PARAM_SPLASH_DISPOSE_ON_HIDE, "true")); //$NON-NLS-1$
471
if (handlerClass != null) {
472             splashHandler = new SplashHandlerWrapper(disposeOnHide,
473                     (SplashHandler) Class.forName(handlerClass).newInstance());
474         }
475         if ((splashHandler == null) && (url != null)) {
476             splashHandler = new SplashHandlerWrapper(disposeOnHide,
477                     new SimpleSplashHandler());
478         }
479         if (splashHandler != null) {
480             if (url != null) {
481                 splashHandler.setImage(url);
482             }
483             splashHandler.configure(
484                     config.getSubset(PARAM_SPLASH_CONFIG_PREFIX));
485         }
486     }
487     
488     private static Application initApplication(
489             final BootErrorHandler errorHandler,
490             final ExtendedProperties props, final String JavaDoc[] args)
491             throws Exception JavaDoc {
492         ApplicationInitializer appInitializer = null;
493         String JavaDoc className = props.getProperty(PARAM_APP_INITIALIZER);
494         if (className != null) {
495             try {
496                 appInitializer = (ApplicationInitializer) Class.forName(
497                         className).newInstance();
498             } catch (InstantiationException JavaDoc ie) {
499                 System.err.println(
500                         "failed instantiating application initializer " //$NON-NLS-1$
501
+ className);
502                 ie.printStackTrace();
503             } catch (IllegalAccessException JavaDoc iae) {
504                 System.err.println(
505                         "failed instantiating application initializer " //$NON-NLS-1$
506
+ className);
507                 iae.printStackTrace();
508             } catch (ClassNotFoundException JavaDoc cnfe) {
509                 System.err.println(
510                         "failed instantiating application initializer " //$NON-NLS-1$
511
+ className);
512                 cnfe.printStackTrace();
513             }
514         }
515         if (appInitializer == null) {
516             appInitializer = new DefaultApplicationInitializer();
517         }
518         appInitializer.configure(props);
519         Application result = appInitializer.initApplication(errorHandler, args);
520         if (result == null) {
521             throw new Exception JavaDoc(ResourceManager.getMessage(
522                     Boot.PACKAGE_NAME, "bootAppInitFailed")); //$NON-NLS-1$
523
}
524         return result;
525     }
526     
527     private static void runShell() {
528         System.out.println("Press 'q' key to exit."); //$NON-NLS-1$
529
do {
530             int c;
531             try {
532                 c = System.in.read();
533             } catch (IOException JavaDoc ioe) {
534                 break;
535             }
536             if (('q' == (char) c) || ('Q' == (char) c)) {
537                 break;
538             }
539         } while (true);
540     }
541     
542     private static void clearBootLog() {
543         File JavaDoc file = new File JavaDoc(BOOT_ERROR_FILE_NAME);
544         if (file.isFile()) {
545             file.delete();
546         }
547     }
548     
549     private static void bootLog(final Throwable JavaDoc t) {
550         try {
551             Writer JavaDoc writer = new OutputStreamWriter JavaDoc(
552                     new FileOutputStream JavaDoc(BOOT_ERROR_FILE_NAME, false),
553                     "UTF-8"); //$NON-NLS-1$
554
try {
555                 writer.write("JPF Application boot failed."); //$NON-NLS-1$
556
writer.write(System.getProperty("line.separator")); //$NON-NLS-1$
557
writer.write(ErrorDialog.getErrorDetails(t));
558             } finally {
559                 writer.close();
560             }
561         } catch (Throwable JavaDoc t2) {
562             throw new Error JavaDoc("boot failed", t); //$NON-NLS-1$
563
}
564     }
565     
566     private Boot() {
567         // no-op
568
}
569 }
570
571 final class SimpleSplashHandler implements SplashHandler {
572     private float progress;
573     private String JavaDoc text;
574     private URL JavaDoc image;
575     private boolean isVisible;
576
577     /**
578      * @see org.java.plugin.boot.SplashHandler#configure(
579      * org.java.plugin.util.ExtendedProperties)
580      */

581     public void configure(final ExtendedProperties config) {
582         // no-op
583
}
584     
585     /**
586      * @see org.java.plugin.boot.SplashHandler#getProgress()
587      */

588     public float getProgress() {
589         return progress;
590     }
591
592     /**
593      * @see org.java.plugin.boot.SplashHandler#setProgress(float)
594      */

595     public void setProgress(final float value) {
596         if ((value < 0) || (value > 1)) {
597             throw new IllegalArgumentException JavaDoc(
598                     "invalid progress value " + value); //$NON-NLS-1$
599
}
600         progress = value;
601     }
602
603     /**
604      * @see org.java.plugin.boot.SplashHandler#getText()
605      */

606     public String JavaDoc getText() {
607         return text;
608     }
609
610     /**
611      * @see org.java.plugin.boot.SplashHandler#setText(java.lang.String)
612      */

613     public void setText(final String JavaDoc value) {
614         text = value;
615     }
616
617     /**
618      * @see org.java.plugin.boot.SplashHandler#getImage()
619      */

620     public URL JavaDoc getImage() {
621         return image;
622     }
623
624     /**
625      * @see org.java.plugin.boot.SplashHandler#setImage(java.net.URL)
626      */

627     public void setImage(final URL JavaDoc value) {
628         image = value;
629     }
630
631     /**
632      * @see org.java.plugin.boot.SplashHandler#isVisible()
633      */

634     public boolean isVisible() {
635         return isVisible;
636     }
637
638     /**
639      * @see org.java.plugin.boot.SplashHandler#setVisible(boolean)
640      */

641     public void setVisible(final boolean value) {
642         if (isVisible == value) {
643             return;
644         }
645         if (value) {
646             SplashWindow.splash(image);
647             isVisible = true;
648             return;
649         }
650         SplashWindow.disposeSplash();
651         isVisible = false;
652     }
653
654     /**
655      * @see org.java.plugin.boot.SplashHandler#getImplementation()
656      */

657     public Object JavaDoc getImplementation() {
658         return this;
659     }
660 }
661
662 final class SplashHandlerWrapper implements SplashHandler {
663     private final SplashHandler delegate;
664     private final boolean isDisposeOnHide;
665
666     SplashHandlerWrapper(final boolean disposeOnHide,
667             final SplashHandler other) {
668         isDisposeOnHide = disposeOnHide;
669         delegate = other;
670     }
671     
672     /**
673      * @see org.java.plugin.boot.SplashHandler#configure(
674      * org.java.plugin.util.ExtendedProperties)
675      */

676     public void configure(final ExtendedProperties config) {
677         delegate.configure(config);
678     }
679
680     /**
681      * @see org.java.plugin.boot.SplashHandler#getProgress()
682      */

683     public float getProgress() {
684         return delegate.getProgress();
685     }
686
687     /**
688      * @see org.java.plugin.boot.SplashHandler#setProgress(float)
689      */

690     public void setProgress(float value) {
691         delegate.setProgress(value);
692     }
693
694     /**
695      * @see org.java.plugin.boot.SplashHandler#getText()
696      */

697     public String JavaDoc getText() {
698         return delegate.getText();
699     }
700
701     /**
702      * @see org.java.plugin.boot.SplashHandler#setText(java.lang.String)
703      */

704     public void setText(String JavaDoc value) {
705         delegate.setText(value);
706     }
707
708     /**
709      * @see org.java.plugin.boot.SplashHandler#getImage()
710      */

711     public URL JavaDoc getImage() {
712         return delegate.getImage();
713     }
714
715     /**
716      * @see org.java.plugin.boot.SplashHandler#setImage(java.net.URL)
717      */

718     public void setImage(URL JavaDoc value) {
719         delegate.setImage(value);
720     }
721
722     /**
723      * @see org.java.plugin.boot.SplashHandler#isVisible()
724      */

725     public boolean isVisible() {
726         return delegate.isVisible();
727     }
728
729     /**
730      * @see org.java.plugin.boot.SplashHandler#setVisible(boolean)
731      */

732     public void setVisible(boolean value) {
733         delegate.setVisible(value);
734         if (isDisposeOnHide && !delegate.isVisible()) {
735             Boot.splashHandler = null;
736         }
737     }
738
739     /**
740      * @see org.java.plugin.boot.SplashHandler#getImplementation()
741      */

742     public Object JavaDoc getImplementation() {
743         return delegate.getImplementation();
744     }
745     
746 }
Popular Tags