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