jaroslav@1041: /** jaroslav@1041: * Back 2 Browser Bytecode Translator jaroslav@1041: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1041: * jaroslav@1041: * This program is free software: you can redistribute it and/or modify jaroslav@1041: * it under the terms of the GNU General Public License as published by jaroslav@1041: * the Free Software Foundation, version 2 of the License. jaroslav@1041: * jaroslav@1041: * This program is distributed in the hope that it will be useful, jaroslav@1041: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1041: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1041: * GNU General Public License for more details. jaroslav@1041: * jaroslav@1041: * You should have received a copy of the GNU General Public License jaroslav@1041: * along with this program. Look for COPYING file in the top folder. jaroslav@1041: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1041: */ jaroslav@1041: package org.apidesign.bck2brwsr.launcher.fximpl; jaroslav@1041: jaroslav@1041: import java.util.TooManyListenersException; jaroslav@1041: import javafx.beans.value.ChangeListener; jaroslav@1041: jaroslav@1041: /** jaroslav@1041: * jaroslav@1041: * @author Jaroslav Tulach jaroslav@1041: */ jaroslav@1041: public final class JVMBridge { jaroslav@1041: private static ClassLoader[] ldrs; jaroslav@1041: private static ChangeListener onBck2BrwsrLoad; jaroslav@1041: jaroslav@1041: public static void registerClassLoaders(ClassLoader[] loaders) { jaroslav@1041: ldrs = loaders.clone(); jaroslav@1041: } jaroslav@1041: jaroslav@1041: public static void addBck2BrwsrLoad(ChangeListener l) throws TooManyListenersException { jaroslav@1041: if (onBck2BrwsrLoad != null) { jaroslav@1041: throw new TooManyListenersException(); jaroslav@1041: } jaroslav@1041: onBck2BrwsrLoad = l; jaroslav@1041: } jaroslav@1041: jaroslav@1041: public static void onBck2BrwsrLoad() { jaroslav@1041: ChangeListener l = onBck2BrwsrLoad; jaroslav@1041: if (l != null) { jaroslav@1041: l.changed(null, null, null); jaroslav@1041: } jaroslav@1041: } jaroslav@1041: jaroslav@1041: public Class loadClass(String name) throws ClassNotFoundException { jaroslav@1041: System.err.println("trying to load " + name); jaroslav@1041: ClassNotFoundException ex = null; jaroslav@1041: if (ldrs != null) for (ClassLoader l : ldrs) { jaroslav@1041: try { jaroslav@1041: return Class.forName(name, true, l); jaroslav@1041: } catch (ClassNotFoundException ex2) { jaroslav@1041: ex = ex2; jaroslav@1041: } jaroslav@1041: } jaroslav@1041: if (ex == null) { jaroslav@1041: ex = new ClassNotFoundException("No loaders"); jaroslav@1041: } jaroslav@1041: throw ex; jaroslav@1041: } jaroslav@1041: }