📄 boot.java
字号:
}
PluginManager pluginManager = PluginManager.lookup(application);
if (pluginManager != null) {
pluginManager.shutdown();
}
LogFactory.getLog(Boot.class).info("logging system finalized"); //$NON-NLS-1$
LogFactory.getLog(Boot.class).info("---------------------------------"); //$NON-NLS-1$
LogFactory.releaseAll();
}
/**
* Returns current instance of splash screen handler if it is available or
* <code>null</code>.
* @return instance of splash handler or <code>null</code> if no active
* instance available
*/
public static SplashHandler getSplashHandler() {
return splashHandler;
}
/**
* @param handler the new splash handler instance to set or
* <code>null</code> to dispose current handler directly
*/
public static void setSplashHandler(final SplashHandler handler) {
if ((handler == null) && (splashHandler != null)) {
splashHandler.setVisible(false);
}
splashHandler = handler;
}
private static InputStream lookupConfig() throws IOException {
String property = System.getProperty(PROP_BOOT_CONFIG);
if (property != null) {
return new FileInputStream(property);
}
File file = new File("boot.properties"); //$NON-NLS-1$
if (file.isFile()) {
return new FileInputStream(file);
}
URL url = Boot.class.getClassLoader().getResource("boot.properties"); //$NON-NLS-1$
if (url != null) {
return IoUtil.getResourceInputStream(url);
}
url = Boot.class.getResource("boot.properties"); //$NON-NLS-1$
if (url != null) {
return IoUtil.getResourceInputStream(url);
}
throw new IOException("configuration file boot.properties not found"); //$NON-NLS-1$
}
private static BootErrorHandler getErrorHandlerInstance(
final String handler, final boolean isServiceApp) {
if (handler != null) {
try {
return (BootErrorHandler) Class.forName(handler).newInstance();
} catch (InstantiationException ie) {
System.err.println("failed instantiating error handler " //$NON-NLS-1$
+ handler);
ie.printStackTrace();
} catch (IllegalAccessException iae) {
System.err.println("failed instantiating error handler " //$NON-NLS-1$
+ handler);
iae.printStackTrace();
} catch (ClassNotFoundException cnfe) {
System.err.println("failed instantiating error handler " //$NON-NLS-1$
+ handler);
cnfe.printStackTrace();
}
}
return isServiceApp ? new BootErrorHandlerConsole()
: (BootErrorHandler) new BootErrorHandlerGui();
}
private static void initSplashHandler(final ExtendedProperties config)
throws Exception {
String handlerClass = config.getProperty(PARAM_SPLASH_HANDLER);
String splashImage = config.getProperty(PARAM_SPLASH_IMAGE);
URL url = null;
if ((splashImage != null) && (splashImage.length() > 0)) {
try {
url = new URL(splashImage);
} catch (MalformedURLException mue) {
// ignore
}
if (url == null) {
File splashFile = new File(splashImage);
if (splashFile.isFile()) {
url = IoUtil.file2url(splashFile);
} else {
throw new FileNotFoundException("splash image file " //$NON-NLS-1$
+ splashFile + " not found"); //$NON-NLS-1$
}
}
}
boolean disposeOnHide = !"false".equalsIgnoreCase( //$NON-NLS-1$
config.getProperty(PARAM_SPLASH_DISPOSE_ON_HIDE, "true")); //$NON-NLS-1$
if (handlerClass != null) {
splashHandler = new SplashHandlerWrapper(disposeOnHide,
(SplashHandler) Class.forName(handlerClass).newInstance());
}
if ((splashHandler == null) && (url != null)) {
splashHandler = new SplashHandlerWrapper(disposeOnHide,
new SimpleSplashHandler());
}
if (splashHandler != null) {
if (url != null) {
splashHandler.setImage(url);
}
splashHandler.configure(
config.getSubset(PARAM_SPLASH_CONFIG_PREFIX));
}
}
private static Application initApplication(
final BootErrorHandler errorHandler,
final ExtendedProperties props, final String[] args)
throws Exception {
ApplicationInitializer appInitializer = null;
String className = props.getProperty(PARAM_APP_INITIALIZER);
if (className != null) {
try {
appInitializer = (ApplicationInitializer) Class.forName(
className).newInstance();
} catch (InstantiationException ie) {
System.err.println(
"failed instantiating application initializer " //$NON-NLS-1$
+ className);
ie.printStackTrace();
} catch (IllegalAccessException iae) {
System.err.println(
"failed instantiating application initializer " //$NON-NLS-1$
+ className);
iae.printStackTrace();
} catch (ClassNotFoundException cnfe) {
System.err.println(
"failed instantiating application initializer " //$NON-NLS-1$
+ className);
cnfe.printStackTrace();
}
}
if (appInitializer == null) {
appInitializer = new DefaultApplicationInitializer();
}
appInitializer.configure(props);
Application result = appInitializer.initApplication(errorHandler, args);
if (result == null) {
throw new Exception(ResourceManager.getMessage(
Boot.PACKAGE_NAME, "bootAppInitFailed")); //$NON-NLS-1$
}
return result;
}
private static void runShell() {
System.out.println("Press 'q' key to exit."); //$NON-NLS-1$
do {
int c;
try {
c = System.in.read();
} catch (IOException ioe) {
break;
}
if (('q' == (char) c) || ('Q' == (char) c)) {
break;
}
} while (true);
}
private static void clearBootLog() {
File file = new File(BOOT_ERROR_FILE_NAME);
if (file.isFile()) {
file.delete();
}
}
private static void bootLog(final Throwable t) {
try {
Writer writer = new OutputStreamWriter(
new FileOutputStream(BOOT_ERROR_FILE_NAME, false),
"UTF-8"); //$NON-NLS-1$
try {
writer.write("JPF Application boot failed."); //$NON-NLS-1$
writer.write(System.getProperty("line.separator")); //$NON-NLS-1$
writer.write(ErrorDialog.getErrorDetails(t));
} finally {
writer.close();
}
} catch (Throwable t2) {
throw new Error("boot failed", t); //$NON-NLS-1$
}
}
private Boot() {
// no-op
}
}
final class SimpleSplashHandler implements SplashHandler {
private float progress;
private String text;
private URL image;
private boolean isVisible;
/**
* @see org.java.plugin.boot.SplashHandler#configure(
* org.java.plugin.util.ExtendedProperties)
*/
public void configure(final ExtendedProperties config) {
// no-op
}
/**
* @see org.java.plugin.boot.SplashHandler#getProgress()
*/
public float getProgress() {
return progress;
}
/**
* @see org.java.plugin.boot.SplashHandler#setProgress(float)
*/
public void setProgress(final float value) {
if ((value < 0) || (value > 1)) {
throw new IllegalArgumentException(
"invalid progress value " + value); //$NON-NLS-1$
}
progress = value;
}
/**
* @see org.java.plugin.boot.SplashHandler#getText()
*/
public String getText() {
return text;
}
/**
* @see org.java.plugin.boot.SplashHandler#setText(java.lang.String)
*/
public void setText(final String value) {
text = value;
}
/**
* @see org.java.plugin.boot.SplashHandler#getImage()
*/
public URL getImage() {
return image;
}
/**
* @see org.java.plugin.boot.SplashHandler#setImage(java.net.URL)
*/
public void setImage(final URL value) {
image = value;
}
/**
* @see org.java.plugin.boot.SplashHandler#isVisible()
*/
public boolean isVisible() {
return isVisible;
}
/**
* @see org.java.plugin.boot.SplashHandler#setVisible(boolean)
*/
public void setVisible(final boolean value) {
if (isVisible == value) {
return;
}
if (value) {
SplashWindow.splash(image);
isVisible = true;
return;
}
SplashWindow.disposeSplash();
isVisible = false;
}
/**
* @see org.java.plugin.boot.SplashHandler#getImplementation()
*/
public Object getImplementation() {
return this;
}
}
final class SplashHandlerWrapper implements SplashHandler {
private final SplashHandler delegate;
private final boolean isDisposeOnHide;
SplashHandlerWrapper(final boolean disposeOnHide,
final SplashHandler other) {
isDisposeOnHide = disposeOnHide;
delegate = other;
}
/**
* @see org.java.plugin.boot.SplashHandler#configure(
* org.java.plugin.util.ExtendedProperties)
*/
public void configure(final ExtendedProperties config) {
delegate.configure(config);
}
/**
* @see org.java.plugin.boot.SplashHandler#getProgress()
*/
public float getProgress() {
return delegate.getProgress();
}
/**
* @see org.java.plugin.boot.SplashHandler#setProgress(float)
*/
public void setProgress(float value) {
delegate.setProgress(value);
}
/**
* @see org.java.plugin.boot.SplashHandler#getText()
*/
public String getText() {
return delegate.getText();
}
/**
* @see org.java.plugin.boot.SplashHandler#setText(java.lang.String)
*/
public void setText(String value) {
delegate.setText(value);
}
/**
* @see org.java.plugin.boot.SplashHandler#getImage()
*/
public URL getImage() {
return delegate.getImage();
}
/**
* @see org.java.plugin.boot.SplashHandler#setImage(java.net.URL)
*/
public void setImage(URL value) {
delegate.setImage(value);
}
/**
* @see org.java.plugin.boot.SplashHandler#isVisible()
*/
public boolean isVisible() {
return delegate.isVisible();
}
/**
* @see org.java.plugin.boot.SplashHandler#setVisible(boolean)
*/
public void setVisible(boolean value) {
delegate.setVisible(value);
if (isDisposeOnHide && !delegate.isVisible()) {
Boot.splashHandler = null;
}
}
/**
* @see org.java.plugin.boot.SplashHandler#getImplementation()
*/
public Object getImplementation() {
return delegate.getImplementation();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -