jaroslav@123
|
1 |
/**
|
jaroslav@123
|
2 |
* HTML via Java(tm) Language Bindings
|
jaroslav@123
|
3 |
* Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@123
|
4 |
*
|
jaroslav@123
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@123
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@123
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@123
|
8 |
*
|
jaroslav@123
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@123
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@123
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@123
|
12 |
* GNU General Public License for more details. apidesign.org
|
jaroslav@123
|
13 |
* designates this particular file as subject to the
|
jaroslav@123
|
14 |
* "Classpath" exception as provided by apidesign.org
|
jaroslav@123
|
15 |
* in the License file that accompanied this code.
|
jaroslav@123
|
16 |
*
|
jaroslav@123
|
17 |
* You should have received a copy of the GNU General Public License
|
jaroslav@123
|
18 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@123
|
19 |
* If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
|
jaroslav@123
|
20 |
*/
|
jaroslav@123
|
21 |
package org.apidesign.html.boot.impl;
|
jaroslav@123
|
22 |
|
jaroslav@123
|
23 |
import java.net.URL;
|
jaroslav@123
|
24 |
import java.util.ArrayList;
|
jaroslav@123
|
25 |
import java.util.Collections;
|
jaroslav@123
|
26 |
import java.util.Enumeration;
|
jaroslav@123
|
27 |
import java.util.List;
|
jaroslav@123
|
28 |
import org.apidesign.html.boot.spi.Fn;
|
jaroslav@123
|
29 |
|
jaroslav@123
|
30 |
/**
|
jaroslav@123
|
31 |
*
|
jaroslav@123
|
32 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@123
|
33 |
*/
|
jaroslav@123
|
34 |
public final class FnUtils {
|
jaroslav@123
|
35 |
|
jaroslav@123
|
36 |
private FnUtils() {
|
jaroslav@123
|
37 |
}
|
jaroslav@123
|
38 |
|
jaroslav@123
|
39 |
public static Fn define(Class<?> caller, String code, String... names) {
|
jaroslav@123
|
40 |
JsClassLoader cl = (JsClassLoader)caller.getClassLoader();
|
jaroslav@123
|
41 |
return cl.defineFn(code, names);
|
jaroslav@123
|
42 |
}
|
jaroslav@123
|
43 |
|
jaroslav@127
|
44 |
public static ClassLoader newLoader(final Fn.Finder f, final Fn.Presenter d, ClassLoader parent) {
|
jaroslav@123
|
45 |
return new JsClassLoader(parent) {
|
jaroslav@123
|
46 |
@Override
|
jaroslav@123
|
47 |
protected URL findResource(String name) {
|
jaroslav@123
|
48 |
List<URL> l = res(name, true);
|
jaroslav@123
|
49 |
return l.isEmpty() ? null : l.get(0);
|
jaroslav@123
|
50 |
}
|
jaroslav@123
|
51 |
|
jaroslav@123
|
52 |
@Override
|
jaroslav@123
|
53 |
protected Enumeration<URL> findResources(String name) {
|
jaroslav@123
|
54 |
return Collections.enumeration(res(name, false));
|
jaroslav@123
|
55 |
}
|
jaroslav@123
|
56 |
|
jaroslav@123
|
57 |
private List<URL> res(String name, boolean oneIsEnough) {
|
jaroslav@123
|
58 |
List<URL> l = new ArrayList<URL>();
|
jaroslav@123
|
59 |
f.findResources(name, l, oneIsEnough);
|
jaroslav@123
|
60 |
return l;
|
jaroslav@123
|
61 |
}
|
jaroslav@123
|
62 |
|
jaroslav@123
|
63 |
@Override
|
jaroslav@123
|
64 |
protected Fn defineFn(String code, String... names) {
|
jaroslav@123
|
65 |
return d.defineFn(code, names);
|
jaroslav@123
|
66 |
}
|
jaroslav@123
|
67 |
};
|
jaroslav@123
|
68 |
}
|
jaroslav@123
|
69 |
|
jaroslav@123
|
70 |
}
|