rt/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/impl/JVMBridge.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 18 Apr 2013 23:09:30 +0200
branchfx
changeset 1016 6dc2c6c752df
parent 845 859804c78010
permissions -rw-r--r--
Can execute 'dual' tests: bck2brwsr can use regular launcher, javaquery.api can use FX Web View one
jaroslav@845
     1
/**
jaroslav@845
     2
 * Back 2 Browser Bytecode Translator
jaroslav@845
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@845
     4
 *
jaroslav@845
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@845
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@845
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@845
     8
 *
jaroslav@845
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@845
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@845
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@845
    12
 * GNU General Public License for more details.
jaroslav@845
    13
 *
jaroslav@845
    14
 * You should have received a copy of the GNU General Public License
jaroslav@845
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@845
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@845
    17
 */
jaroslav@845
    18
package org.apidesign.bck2brwsr.launcher.impl;
jaroslav@845
    19
jaroslav@1004
    20
import java.util.TooManyListenersException;
jaroslav@1004
    21
import javafx.beans.value.ChangeListener;
jaroslav@1004
    22
jaroslav@845
    23
/**
jaroslav@845
    24
 *
jaroslav@845
    25
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@845
    26
 */
jaroslav@845
    27
public final class JVMBridge {
jaroslav@845
    28
    private static ClassLoader[] ldrs;
jaroslav@1004
    29
    private static ChangeListener<Void> onBck2BrwsrLoad;
jaroslav@845
    30
        
jaroslav@845
    31
    public static void registerClassLoaders(ClassLoader[] loaders) {
jaroslav@845
    32
        ldrs = loaders.clone();
jaroslav@845
    33
    }
jaroslav@845
    34
    
jaroslav@1004
    35
    public static void addBck2BrwsrLoad(ChangeListener<Void> l) throws TooManyListenersException {
jaroslav@1004
    36
        if (onBck2BrwsrLoad != null) {
jaroslav@1004
    37
            throw new TooManyListenersException();
jaroslav@1004
    38
        }
jaroslav@1004
    39
        onBck2BrwsrLoad = l;
jaroslav@1004
    40
    }
jaroslav@1004
    41
jaroslav@1004
    42
    public static void onBck2BrwsrLoad() {
jaroslav@1004
    43
        ChangeListener<Void> l = onBck2BrwsrLoad;
jaroslav@1004
    44
        if (l != null) {
jaroslav@1004
    45
            l.changed(null, null, null);
jaroslav@1004
    46
        }
jaroslav@1004
    47
    }
jaroslav@1004
    48
    
jaroslav@845
    49
    public Class<?> loadClass(String name) throws ClassNotFoundException {
jaroslav@845
    50
        System.err.println("trying to load " + name);
jaroslav@845
    51
        ClassNotFoundException ex = null;
jaroslav@845
    52
        if (ldrs != null) for (ClassLoader l : ldrs) {
jaroslav@845
    53
            try {
jaroslav@845
    54
                return Class.forName(name, true, l);
jaroslav@845
    55
            } catch (ClassNotFoundException ex2) {
jaroslav@845
    56
                ex = ex2;
jaroslav@845
    57
            }
jaroslav@845
    58
        }
jaroslav@845
    59
        if (ex == null) {
jaroslav@845
    60
            ex = new ClassNotFoundException("No loaders");
jaroslav@845
    61
        }
jaroslav@845
    62
        throw ex;
jaroslav@845
    63
    }
jaroslav@845
    64
}