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