in boot/src/main/java/net/java/html/boot/BrowserBuilder.java [221:361]
public void showAndWait() {
if (resource == null) {
throw new NullPointerException("Need to specify resource via loadPage method");
}
final Class<?> myCls;
if (clazz != null) {
myCls = clazz;
} else if (onLoad != null) {
myCls = onLoad.getClass();
} else {
throw new NullPointerException("loadClass, neither loadFinished was called!");
}
IOException mal[] = { null };
URL url = findLocalizedResourceURL(resource, locale, mal, myCls);
if (url == null) {
final IOException ex = new IOException("Cannot find page " + resource + " to display");
class InvalidHandler extends URLStreamHandler {
@Override
protected URLConnection openConnection(URL u) throws IOException {
throw ex;
}
}
try {
url = new URL("resource", null, -1, resource, new InvalidHandler());
} catch (MalformedURLException malformed) {
throw new IllegalStateException(malformed);
}
}
Fn.Presenter dfnr = null;
for (Object o : context) {
if (o instanceof Fn.Presenter) {
dfnr = (Fn.Presenter)o;
break;
}
}
if (dfnr == null && loader != null) for (Fn.Presenter o : ServiceLoader.load(Fn.Presenter.class, loader)) {
dfnr = o;
break;
}
if (dfnr == null) for (Fn.Presenter o : ServiceLoader.load(Fn.Presenter.class)) {
dfnr = o;
break;
}
if (dfnr == null) {
throw new IllegalStateException("Can't find any Fn.Presenter");
}
final ClassLoader activeLoader;
if (loader != null) {
final URL res = FnContext.isJavaScriptCapable(loader);
if (res != null) {
throw new IllegalStateException("Loader " + loader +
" cannot resolve @JavaScriptBody, because of " + res
);
}
activeLoader = loader;
} else {
final URL res = FnContext.isJavaScriptCapable(myCls.getClassLoader());
if (res == null) {
activeLoader = myCls.getClassLoader();
} else {
FImpl impl = new FImpl(myCls.getClassLoader());
activeLoader = FnContext.newLoader(res, impl, dfnr, myCls.getClassLoader().getParent());
if (activeLoader == null) {
throw new IllegalStateException("Cannot find asm-5.0.jar classes!");
}
}
}
final Fn.Presenter dP = dfnr;
class OnPageLoad implements Runnable {
@Override
public void run() {
try {
final Fn.Presenter aP = Fn.activePresenter();
final Fn.Presenter currentP = aP != null ? aP : dP;
Thread.currentThread().setContextClassLoader(activeLoader);
final Class<?> newClazz = onLoad != null ?
myCls :
Class.forName(myCls.getName(), true, activeLoader);
Contexts.Builder cb = Contexts.newBuilder(context);
if (!Contexts.fillInByProviders(newClazz, cb)) {
LOG.log(Level.WARNING, "Using empty technology for {0}", newClazz);
}
if (currentP instanceof Executor) {
cb.register(Executor.class, (Executor)currentP, 1000);
}
cb.register(Fn.Presenter.class, currentP, 1000);
BrwsrCtx c = cb.build();
class CallInitMethod implements Runnable {
@Override
public void run() {
Throwable firstError = null;
if (onLoad != null) {
try (var ctx = Fn.activate(currentP)) {
onLoad.run();
} catch (Throwable ex) {
firstError = ex;
}
}
INIT: if (methodName != null) {
if (methodArgs.length == 0) {
try (var ctx = Fn.activate(currentP)) {
Method m = newClazz.getMethod(methodName);
m.invoke(null);
firstError = null;
break INIT;
} catch (Throwable ex) {
firstError = ex;
}
}
try (var ctx = Fn.activate(currentP)) {
Method m = newClazz.getMethod(methodName, String[].class);
m.invoke(m, (Object) methodArgs);
firstError = null;
} catch (Throwable ex) {
LOG.log(Level.SEVERE, "Can't call " + methodName + " with args " + Arrays.toString(methodArgs), ex);
}
}
if (firstError != null) {
LOG.log(Level.SEVERE, "Can't initialize the view", firstError);
}
}
}
c.execute(new CallInitMethod());
} catch (ClassNotFoundException ex) {
LOG.log(Level.SEVERE, "Can't load " + myCls.getName(), ex);
}
}
}
dfnr.displayPage(url, new OnPageLoad());
}