PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/projects/jpf-1.5.1/source-boot/org/java/plugin/boot/Boot.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 765 lines | 464 code | 51 blank | 250 comment | 87 complexity | 112024c1717a7f597396058ae89b2ebd MD5 | raw file
  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. import java.io.File;
  21. import java.io.FileInputStream;
  22. import java.io.FileNotFoundException;
  23. import java.io.FileOutputStream;
  24. import java.io.IOException;
  25. import java.io.InputStream;
  26. import java.io.OutputStreamWriter;
  27. import java.io.Writer;
  28. import java.net.InetAddress;
  29. import java.net.MalformedURLException;
  30. import java.net.URL;
  31. import java.util.Locale;
  32. import org.apache.commons.logging.LogFactory;
  33. import org.java.plugin.PluginManager;
  34. import org.java.plugin.util.ExtendedProperties;
  35. import org.java.plugin.util.IoUtil;
  36. import org.java.plugin.util.ResourceManager;
  37. /**
  38. * Main class to get JPF based application running in different modes.
  39. * Application mode may be specified as <code>jpf.boot.mode</code> configuration
  40. * parameter or System property (via <code>-Djpf.boot.mode=</code> command line
  41. * argument). Supported values are:
  42. * <dl>
  43. * <dt>start</dt>
  44. * <dd>Runs application in "background" ("service") mode.</dd>
  45. * <dt>stop</dt>
  46. * <dd>Stops application, running in "background" mode.</dd>
  47. * <dt>restart</dt>
  48. * <dd>Restarts application, running in "background" mode. If it is not
  49. * started, the action is the same as just starting application.</dd>
  50. * <dt>shell</dt>
  51. * <dd>Runs application in "shell" (or "interactive") mode. It is possible to
  52. * control "service" style application from command line. Note, that
  53. * already running application will be stopped first.</dd>
  54. * <dt>load</dt>
  55. * <dd>Only loads application but not starts it as in other modes. This mode
  56. * is useful when doing application unit testing or when you only need to
  57. * get initialized and ready to be started JPF environment.</dd>
  58. * </dl>
  59. * The "shell" mode is default. Application will be started in this mode if no
  60. * <code>jpf.boot.mode</code> configuration parameter can be found.
  61. * <p>
  62. * Application configuration is expected to be in Java properties format file.
  63. * File look-up procedure is the following:
  64. * </p>
  65. * <ul>
  66. * <li>Check <code>jpf.boot.config</code> System property, if present, load
  67. * configuration from that location</li>
  68. * <li>Look for <code>boot.properties</code> file in the current folder.</li>
  69. * <li>Look for <code>boot.properties</code> resource in classpath (using
  70. * <code>Boot.class.getClassLoader().getResource("boot.properties")</code>
  71. * and <code>Boot.class.getResource("boot.properties")</code> methods).</li>
  72. * </ul>
  73. * <p>
  74. * If configuration could not be found, a warning will be printed to console.
  75. * It is generally not an error to not use configuration file, you may provide
  76. * JPF configuration parameters as System properties. They are always used as
  77. * defaults for configuration properties.
  78. * </p>
  79. * <p>
  80. * Note that configuration properties will be loaded using
  81. * {@link org.java.plugin.util.ExtendedProperties specially extended}
  82. * version of {@link java.util.Properties} class, which supports parameters
  83. * substitution. If there is no <code>applicationRoot</code> property available
  84. * in the given configuration, the current folder will be published as default
  85. * value.
  86. * </p>
  87. * <p>
  88. * Standard configuration parameters are (all are optional when application is
  89. * running in "shell" mode):
  90. * <dl>
  91. * <dt>jpf.boot.mode</dt>
  92. * <dd>Application boot mode. Always available as System property also.
  93. * Default value is <code>shell</code>.</dd>
  94. * <dt>org.java.plugin.boot.appInitializer</dt>
  95. * <dd>Application initializer class, for details see
  96. * {@link org.java.plugin.boot.ApplicationInitializer}. Default is
  97. * {@link org.java.plugin.boot.DefaultApplicationInitializer}.</dd>
  98. * <dt>org.java.plugin.boot.errorHandler</dt>
  99. * <dd>Error handler class, for details see
  100. * {@link org.java.plugin.boot.BootErrorHandler}. Default is
  101. * {@link org.java.plugin.boot.BootErrorHandlerConsole} for "service" style
  102. * applications and {@link org.java.plugin.boot.BootErrorHandlerGui} for
  103. * "interactive" applications.</dd>
  104. * <dt>org.java.plugin.boot.controlHost</dt>
  105. * <dd>Host to be used by background control service, no default values.</dd>
  106. * <dt>org.java.plugin.boot.controlPort</dt>
  107. * <dd>Port number to be used by background control service, no default
  108. * values.</dd>
  109. * <dt>org.java.plugin.boot.splashHandler</dt>
  110. * <dd>Splash screen handler class, for details see
  111. * {@link org.java.plugin.boot.SplashHandler}. Default is simple splash
  112. * handler that can only display an image.</dd>
  113. * <dt>org.java.plugin.boot.splashImage</dt>
  114. * <dd>Path to an image file to be shown as splash screen. This may be any
  115. * valid URL. If no file and no handler given, the splash screen will not
  116. * be shown.</dd>
  117. * <dt>org.java.plugin.boot.splashLeaveVisible</dt>
  118. * <dd>If set to <code>true</code>, the Boot class will not hide splash screen
  119. * at the end of boot procedure but delegate this function to application
  120. * code. Default value is <code>false</code>.</dd>
  121. * <dt>org.java.plugin.boot.splashDisposeOnHide</dt>
  122. * <dd>If set to <code>false</code>, the Boot class will not dispose splash
  123. * screen handler when hiding it. This allows you to reuse handler and show
  124. * splash screen back after it was hidden. Default value is
  125. * <code>true</code>.</dd>
  126. * </dl>
  127. *
  128. * @version $Id: Boot.java,v 1.19 2007/02/11 18:12:54 ddimon Exp $
  129. */
  130. public final class Boot {
  131. /**
  132. * Name of the file, where to put boot error details.
  133. */
  134. public static final String BOOT_ERROR_FILE_NAME = "jpf-boot-error.txt"; //$NON-NLS-1$
  135. /**
  136. * Boot configuration file location System property name.
  137. */
  138. public static final String PROP_BOOT_CONFIG = "jpf.boot.config"; //$NON-NLS-1$
  139. /**
  140. * Boot mode System property name.
  141. */
  142. public static final String PROP_BOOT_MODE = "jpf.boot.mode"; //$NON-NLS-1$
  143. /**
  144. * "shell" mode boot command value.
  145. */
  146. public static final String BOOT_MODE_SHELL = "shell"; //$NON-NLS-1$
  147. /**
  148. * "start" mode boot command value.
  149. */
  150. public static final String BOOT_MODE_START = "start"; //$NON-NLS-1$
  151. /**
  152. * "stop" mode boot command value.
  153. */
  154. public static final String BOOT_MODE_STOP = "stop"; //$NON-NLS-1$
  155. /**
  156. * "restart" mode boot command value.
  157. */
  158. public static final String BOOT_MODE_RESTART = "restart"; //$NON-NLS-1$
  159. /**
  160. * "load" mode boot command value.
  161. */
  162. public static final String BOOT_MODE_LOAD = "load"; //$NON-NLS-1$
  163. // This is for ResourceManager to look up resources.
  164. static final String PACKAGE_NAME = "org.java.plugin.boot"; //$NON-NLS-1$
  165. // Application bootstrap configuration parameter names goes here
  166. private static final String PARAM_CONTROL_HOST =
  167. "org.java.plugin.boot.controlHost"; //$NON-NLS-1$
  168. private static final String PARAM_CONTROL_PORT =
  169. "org.java.plugin.boot.controlPort"; //$NON-NLS-1$
  170. private static final String PARAM_ERROR_HANDLER =
  171. "org.java.plugin.boot.errorHandler"; //$NON-NLS-1$
  172. private static final String PARAM_APP_INITIALIZER =
  173. "org.java.plugin.boot.appInitializer"; //$NON-NLS-1$
  174. private static final String PARAM_SPLASH_HANDLER =
  175. "org.java.plugin.boot.splashHandler"; //$NON-NLS-1$
  176. private static final String PARAM_SPLASH_IMAGE =
  177. "org.java.plugin.boot.splashImage"; //$NON-NLS-1$
  178. private static final String PARAM_SPLASH_LEAVE_VISIBLE =
  179. "org.java.plugin.boot.splashLeaveVisible"; //$NON-NLS-1$
  180. private static final String PARAM_SPLASH_DISPOSE_ON_HIDE =
  181. "org.java.plugin.boot.splashDisposeOnHide"; //$NON-NLS-1$
  182. private static final String PARAM_SPLASH_CONFIG_PREFIX =
  183. "org.java.plugin.boot.splash."; //$NON-NLS-1$
  184. static SplashHandler splashHandler = null;
  185. /**
  186. * Call this method to start/stop application.
  187. * @param args command line arguments, not interpreted by this method but
  188. * passed to
  189. * {@link ApplicationPlugin#initApplication(ExtendedProperties, String[])}
  190. * method
  191. */
  192. public static void main(final String[] args) {
  193. clearBootLog();
  194. // Load start-up configuration
  195. ExtendedProperties props = new ExtendedProperties(
  196. System.getProperties());
  197. try {
  198. InputStream strm = lookupConfig();
  199. try {
  200. props.load(strm);
  201. } finally {
  202. strm.close();
  203. }
  204. } catch (IOException ioe) {
  205. ioe.printStackTrace();
  206. }
  207. String mode = props.getProperty(PROP_BOOT_MODE);
  208. if (mode != null) {
  209. mode = mode.trim().toLowerCase(Locale.ENGLISH);
  210. } else {
  211. // set SHELL mode by default
  212. mode = BOOT_MODE_SHELL;
  213. }
  214. props.setProperty(PROP_BOOT_MODE, mode);
  215. // Make sure that boot mode is always available as System property:
  216. System.setProperty(PROP_BOOT_MODE, mode);
  217. boolean useControlService = props.containsKey(PARAM_CONTROL_HOST)
  218. && props.containsKey(PARAM_CONTROL_PORT);
  219. BootErrorHandler errorHandler = getErrorHandlerInstance(
  220. props.getProperty(PARAM_ERROR_HANDLER), useControlService);
  221. try {
  222. if (props.getProperty("applicationRoot") == null) { //$NON-NLS-1$
  223. // Publish current folder as configuration parameter
  224. // to get it available as ${applicationRoot} variable
  225. // in extended properties syntax.
  226. String applicationRoot = new File(".").getCanonicalPath(); //$NON-NLS-1$
  227. props.put("applicationRoot", applicationRoot); //$NON-NLS-1$
  228. }
  229. boot(props, useControlService, mode, errorHandler, args);
  230. } catch (Throwable t) {
  231. if (splashHandler != null) {
  232. splashHandler.setVisible(false);
  233. splashHandler = null;
  234. }
  235. bootLog(t);
  236. errorHandler.handleFatalError(ResourceManager.getMessage(
  237. Boot.PACKAGE_NAME, "bootFailed"), t); //$NON-NLS-1$
  238. System.exit(1);
  239. }
  240. }
  241. /**
  242. * Boots application according to given configuration data.
  243. * @param config boot configuration data
  244. * @param useControlService if <code>true</code>, the control service will
  245. * started to allow handling application instance
  246. * from another process
  247. * @param mode application run mode
  248. * @param errorHandler boot errors handler instance
  249. * @param args command line arguments, not interpreted by this method but
  250. * passed to
  251. * {@link ApplicationPlugin#initApplication(ExtendedProperties, String[])}
  252. * method
  253. * @return initialized application instance or <code>null</code>
  254. * @throws Exception if any un-handled error has occurred
  255. */
  256. public static Application boot(final ExtendedProperties config,
  257. final boolean useControlService, final String mode,
  258. final BootErrorHandler errorHandler, final String[] args)
  259. throws Exception {
  260. InetAddress controlHost = useControlService ? InetAddress.getByName(
  261. config.getProperty(PARAM_CONTROL_HOST)) : null;
  262. int controlPort = useControlService ? Integer.parseInt(
  263. config.getProperty(PARAM_CONTROL_PORT), 10) : 0;
  264. // handle given command
  265. if (useControlService && BOOT_MODE_STOP.equals(mode)) {
  266. if (!ControlThread.stopRunningApplication(controlHost,
  267. controlPort)) {
  268. System.out.println("application not running"); //$NON-NLS-1$
  269. } else {
  270. System.out.println("application stopped"); //$NON-NLS-1$
  271. }
  272. return null;
  273. }
  274. if (useControlService && BOOT_MODE_START.equals(mode)) {
  275. if (ControlThread.isApplicationRunning(controlHost,
  276. controlPort)) {
  277. errorHandler.handleFatalError(
  278. "Application already running."); //$NON-NLS-1$
  279. return null;
  280. }
  281. Application application =
  282. initApplication(errorHandler, config, args);
  283. if (!(application instanceof ServiceApplication)) {
  284. errorHandler.handleFatalError(
  285. "Application is not a service."); //$NON-NLS-1$
  286. return null;
  287. }
  288. ControlThread controlThread = new ControlThread(controlHost,
  289. controlPort, (ServiceApplication) application);
  290. application.startApplication();
  291. controlThread.start();
  292. System.out.println(
  293. "application started in BACKGROUND mode"); //$NON-NLS-1$
  294. return application;
  295. }
  296. if (useControlService && BOOT_MODE_RESTART.equals(mode)) {
  297. if (ControlThread.stopRunningApplication(controlHost,
  298. controlPort)) {
  299. System.out.println("another instance of application stopped"); //$NON-NLS-1$
  300. }
  301. Application application =
  302. initApplication(errorHandler, config, args);
  303. if (!(application instanceof ServiceApplication)) {
  304. errorHandler.handleFatalError(
  305. "Application is not a service."); //$NON-NLS-1$
  306. return null;
  307. }
  308. ControlThread controlThread = new ControlThread(controlHost,
  309. controlPort, (ServiceApplication) application);
  310. application.startApplication();
  311. controlThread.start();
  312. System.out.println(
  313. "application started in BACKGROUND mode"); //$NON-NLS-1$
  314. return application;
  315. }
  316. // SHELL or LOAD or an unknown modes
  317. if (useControlService
  318. && ControlThread.stopRunningApplication(controlHost,
  319. controlPort)) {
  320. System.out.println("another instance of application stopped"); //$NON-NLS-1$
  321. }
  322. if (!BOOT_MODE_LOAD.equals(mode)) {
  323. initSplashHandler(config);
  324. if (splashHandler != null) {
  325. splashHandler.setVisible(true);
  326. }
  327. }
  328. Application application =
  329. initApplication(errorHandler, config, args);
  330. if (!BOOT_MODE_LOAD.equals(mode)) {
  331. application.startApplication();
  332. if ((splashHandler != null)
  333. && !"true".equalsIgnoreCase(config.getProperty( //$NON-NLS-1$
  334. PARAM_SPLASH_LEAVE_VISIBLE, "false"))) { //$NON-NLS-1$
  335. splashHandler.setVisible(false);
  336. }
  337. if ((application instanceof ServiceApplication)
  338. && BOOT_MODE_SHELL.equals(mode)) {
  339. System.out.println("application started in SHELL mode"); //$NON-NLS-1$
  340. runShell();
  341. stopApplication(application);
  342. }
  343. }
  344. return application;
  345. }
  346. /**
  347. * Stops the application, shuts down plug-in manager and disposes log
  348. * service. Call this method before exiting interactive application. For
  349. * service applications this method will be called automatically by control
  350. * service or from shell.
  351. * @param application application instance being stopped
  352. * @throws Exception if any error has occurred during application stopping
  353. */
  354. public static void stopApplication(final Application application)
  355. throws Exception {
  356. if (application instanceof ServiceApplication) {
  357. ((ServiceApplication) application).stopApplication();
  358. }
  359. PluginManager pluginManager = PluginManager.lookup(application);
  360. if (pluginManager != null) {
  361. pluginManager.shutdown();
  362. }
  363. LogFactory.getLog(Boot.class).info("logging system finalized"); //$NON-NLS-1$
  364. LogFactory.getLog(Boot.class).info("---------------------------------"); //$NON-NLS-1$
  365. LogFactory.releaseAll();
  366. }
  367. /**
  368. * Returns current instance of splash screen handler if it is available or
  369. * <code>null</code>.
  370. * @return instance of splash handler or <code>null</code> if no active
  371. * instance available
  372. */
  373. public static SplashHandler getSplashHandler() {
  374. return splashHandler;
  375. }
  376. /**
  377. * @param handler the new splash handler instance to set or
  378. * <code>null</code> to dispose current handler directly
  379. */
  380. public static void setSplashHandler(final SplashHandler handler) {
  381. if ((handler == null) && (splashHandler != null)) {
  382. splashHandler.setVisible(false);
  383. }
  384. splashHandler = handler;
  385. }
  386. private static InputStream lookupConfig() throws IOException {
  387. String property = System.getProperty(PROP_BOOT_CONFIG);
  388. if (property != null) {
  389. return IoUtil.getResourceInputStream(str2url(property));
  390. }
  391. File file = new File("boot.properties"); //$NON-NLS-1$
  392. if (file.isFile()) {
  393. return new FileInputStream(file);
  394. }
  395. URL url = Boot.class.getClassLoader().getResource("boot.properties"); //$NON-NLS-1$
  396. if (url != null) {
  397. return IoUtil.getResourceInputStream(url);
  398. }
  399. url = Boot.class.getResource("boot.properties"); //$NON-NLS-1$
  400. if (url != null) {
  401. return IoUtil.getResourceInputStream(url);
  402. }
  403. throw new IOException("configuration file boot.properties not found"); //$NON-NLS-1$
  404. }
  405. private static URL str2url(final String str) throws MalformedURLException {
  406. int p = str.indexOf("!/"); //$NON-NLS-1$
  407. if (p == -1) {
  408. try {
  409. return new URL(str);
  410. } catch (MalformedURLException mue) {
  411. return IoUtil.file2url(new File(str));
  412. }
  413. }
  414. if (str.startsWith("jar:")) { //$NON-NLS-1$
  415. return new URL(str);
  416. }
  417. File file = new File(str.substring(0, p));
  418. if (file.isFile()) {
  419. return new URL("jar:" + IoUtil.file2url(file) + str.substring(p)); //$NON-NLS-1$
  420. }
  421. return new URL("jar:" + str); //$NON-NLS-1$
  422. }
  423. private static BootErrorHandler getErrorHandlerInstance(
  424. final String handler, final boolean isServiceApp) {
  425. if (handler != null) {
  426. try {
  427. return (BootErrorHandler) Class.forName(handler).newInstance();
  428. } catch (InstantiationException ie) {
  429. System.err.println("failed instantiating error handler " //$NON-NLS-1$
  430. + handler);
  431. ie.printStackTrace();
  432. } catch (IllegalAccessException iae) {
  433. System.err.println("failed instantiating error handler " //$NON-NLS-1$
  434. + handler);
  435. iae.printStackTrace();
  436. } catch (ClassNotFoundException cnfe) {
  437. System.err.println("failed instantiating error handler " //$NON-NLS-1$
  438. + handler);
  439. cnfe.printStackTrace();
  440. }
  441. }
  442. return isServiceApp ? new BootErrorHandlerConsole()
  443. : (BootErrorHandler) new BootErrorHandlerGui();
  444. }
  445. private static void initSplashHandler(final ExtendedProperties config)
  446. throws Exception {
  447. String handlerClass = config.getProperty(PARAM_SPLASH_HANDLER);
  448. String splashImage = config.getProperty(PARAM_SPLASH_IMAGE);
  449. URL url = null;
  450. if ((splashImage != null) && (splashImage.length() > 0)) {
  451. try {
  452. url = new URL(splashImage);
  453. } catch (MalformedURLException mue) {
  454. // ignore
  455. }
  456. if (url == null) {
  457. File splashFile = new File(splashImage);
  458. if (splashFile.isFile()) {
  459. url = IoUtil.file2url(splashFile);
  460. } else {
  461. throw new FileNotFoundException("splash image file " //$NON-NLS-1$
  462. + splashFile + " not found"); //$NON-NLS-1$
  463. }
  464. }
  465. }
  466. boolean disposeOnHide = !"false".equalsIgnoreCase( //$NON-NLS-1$
  467. config.getProperty(PARAM_SPLASH_DISPOSE_ON_HIDE, "true")); //$NON-NLS-1$
  468. if (handlerClass != null) {
  469. splashHandler = new SplashHandlerWrapper(disposeOnHide,
  470. (SplashHandler) Class.forName(handlerClass).newInstance());
  471. }
  472. if ((splashHandler == null) && (url != null)) {
  473. splashHandler = new SplashHandlerWrapper(disposeOnHide,
  474. new SimpleSplashHandler());
  475. }
  476. if (splashHandler != null) {
  477. if (url != null) {
  478. splashHandler.setImage(url);
  479. }
  480. splashHandler.configure(
  481. config.getSubset(PARAM_SPLASH_CONFIG_PREFIX));
  482. }
  483. }
  484. private static Application initApplication(
  485. final BootErrorHandler errorHandler,
  486. final ExtendedProperties props, final String[] args)
  487. throws Exception {
  488. ApplicationInitializer appInitializer = null;
  489. String className = props.getProperty(PARAM_APP_INITIALIZER);
  490. if (className != null) {
  491. try {
  492. appInitializer = (ApplicationInitializer) Class.forName(
  493. className).newInstance();
  494. } catch (InstantiationException ie) {
  495. System.err.println(
  496. "failed instantiating application initializer " //$NON-NLS-1$
  497. + className);
  498. ie.printStackTrace();
  499. } catch (IllegalAccessException iae) {
  500. System.err.println(
  501. "failed instantiating application initializer " //$NON-NLS-1$
  502. + className);
  503. iae.printStackTrace();
  504. } catch (ClassNotFoundException cnfe) {
  505. System.err.println(
  506. "failed instantiating application initializer " //$NON-NLS-1$
  507. + className);
  508. cnfe.printStackTrace();
  509. }
  510. }
  511. if (appInitializer == null) {
  512. appInitializer = new DefaultApplicationInitializer();
  513. }
  514. appInitializer.configure(props);
  515. Application result = appInitializer.initApplication(errorHandler, args);
  516. if (result == null) {
  517. throw new Exception(ResourceManager.getMessage(
  518. Boot.PACKAGE_NAME, "bootAppInitFailed")); //$NON-NLS-1$
  519. }
  520. return result;
  521. }
  522. private static void runShell() {
  523. System.out.println("Press 'q' key to exit."); //$NON-NLS-1$
  524. do {
  525. int c;
  526. try {
  527. c = System.in.read();
  528. } catch (IOException ioe) {
  529. break;
  530. }
  531. if (('q' == (char) c) || ('Q' == (char) c)) {
  532. break;
  533. }
  534. } while (true);
  535. }
  536. private static void clearBootLog() {
  537. File file = new File(BOOT_ERROR_FILE_NAME);
  538. if (file.isFile()) {
  539. file.delete();
  540. }
  541. }
  542. private static void bootLog(final Throwable t) {
  543. try {
  544. Writer writer = new OutputStreamWriter(
  545. new FileOutputStream(BOOT_ERROR_FILE_NAME, false),
  546. "UTF-8"); //$NON-NLS-1$
  547. try {
  548. writer.write("JPF Application boot failed."); //$NON-NLS-1$
  549. writer.write(System.getProperty("line.separator")); //$NON-NLS-1$
  550. writer.write(ErrorDialog.getErrorDetails(t));
  551. } finally {
  552. writer.close();
  553. }
  554. } catch (Throwable t2) {
  555. throw new Error("boot failed", t); //$NON-NLS-1$
  556. }
  557. }
  558. private Boot() {
  559. // no-op
  560. }
  561. }
  562. final class SimpleSplashHandler implements SplashHandler {
  563. private float progress;
  564. private String text;
  565. private URL image;
  566. private boolean isVisible;
  567. /**
  568. * @see org.java.plugin.boot.SplashHandler#configure(
  569. * org.java.plugin.util.ExtendedProperties)
  570. */
  571. public void configure(final ExtendedProperties config) {
  572. // no-op
  573. }
  574. /**
  575. * @see org.java.plugin.boot.SplashHandler#getProgress()
  576. */
  577. public float getProgress() {
  578. return progress;
  579. }
  580. /**
  581. * @see org.java.plugin.boot.SplashHandler#setProgress(float)
  582. */
  583. public void setProgress(final float value) {
  584. if ((value < 0) || (value > 1)) {
  585. throw new IllegalArgumentException(
  586. "invalid progress value " + value); //$NON-NLS-1$
  587. }
  588. progress = value;
  589. }
  590. /**
  591. * @see org.java.plugin.boot.SplashHandler#getText()
  592. */
  593. public String getText() {
  594. return text;
  595. }
  596. /**
  597. * @see org.java.plugin.boot.SplashHandler#setText(java.lang.String)
  598. */
  599. public void setText(final String value) {
  600. text = value;
  601. }
  602. /**
  603. * @see org.java.plugin.boot.SplashHandler#getImage()
  604. */
  605. public URL getImage() {
  606. return image;
  607. }
  608. /**
  609. * @see org.java.plugin.boot.SplashHandler#setImage(java.net.URL)
  610. */
  611. public void setImage(final URL value) {
  612. image = value;
  613. }
  614. /**
  615. * @see org.java.plugin.boot.SplashHandler#isVisible()
  616. */
  617. public boolean isVisible() {
  618. return isVisible;
  619. }
  620. /**
  621. * @see org.java.plugin.boot.SplashHandler#setVisible(boolean)
  622. */
  623. public void setVisible(final boolean value) {
  624. if (isVisible == value) {
  625. return;
  626. }
  627. if (value) {
  628. SplashWindow.splash(image);
  629. isVisible = true;
  630. return;
  631. }
  632. SplashWindow.disposeSplash();
  633. isVisible = false;
  634. }
  635. /**
  636. * @see org.java.plugin.boot.SplashHandler#getImplementation()
  637. */
  638. public Object getImplementation() {
  639. return this;
  640. }
  641. }
  642. final class SplashHandlerWrapper implements SplashHandler {
  643. private final SplashHandler delegate;
  644. private final boolean isDisposeOnHide;
  645. SplashHandlerWrapper(final boolean disposeOnHide,
  646. final SplashHandler other) {
  647. isDisposeOnHide = disposeOnHide;
  648. delegate = other;
  649. }
  650. /**
  651. * @see org.java.plugin.boot.SplashHandler#configure(
  652. * org.java.plugin.util.ExtendedProperties)
  653. */
  654. public void configure(final ExtendedProperties config) {
  655. delegate.configure(config);
  656. }
  657. /**
  658. * @see org.java.plugin.boot.SplashHandler#getProgress()
  659. */
  660. public float getProgress() {
  661. return delegate.getProgress();
  662. }
  663. /**
  664. * @see org.java.plugin.boot.SplashHandler#setProgress(float)
  665. */
  666. public void setProgress(float value) {
  667. delegate.setProgress(value);
  668. }
  669. /**
  670. * @see org.java.plugin.boot.SplashHandler#getText()
  671. */
  672. public String getText() {
  673. return delegate.getText();
  674. }
  675. /**
  676. * @see org.java.plugin.boot.SplashHandler#setText(java.lang.String)
  677. */
  678. public void setText(String value) {
  679. delegate.setText(value);
  680. }
  681. /**
  682. * @see org.java.plugin.boot.SplashHandler#getImage()
  683. */
  684. public URL getImage() {
  685. return delegate.getImage();
  686. }
  687. /**
  688. * @see org.java.plugin.boot.SplashHandler#setImage(java.net.URL)
  689. */
  690. public void setImage(URL value) {
  691. delegate.setImage(value);
  692. }
  693. /**
  694. * @see org.java.plugin.boot.SplashHandler#isVisible()
  695. */
  696. public boolean isVisible() {
  697. return delegate.isVisible();
  698. }
  699. /**
  700. * @see org.java.plugin.boot.SplashHandler#setVisible(boolean)
  701. */
  702. public void setVisible(boolean value) {
  703. delegate.setVisible(value);
  704. if (isDisposeOnHide && !delegate.isVisible()) {
  705. Boot.splashHandler = null;
  706. }
  707. }
  708. /**
  709. * @see org.java.plugin.boot.SplashHandler#getImplementation()
  710. */
  711. public Object getImplementation() {
  712. return delegate.getImplementation();
  713. }
  714. }