Don't really initialize the classes. Just pretend they will be initialized so bck2brwsr includes them in transitive closure
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import java.io.IOException;
22 import java.util.zip.ZipEntry;
23 import java.util.zip.ZipInputStream;
24 import org.apidesign.bck2brwsr.core.JavaScriptBody;
26 /** Conversion from classpath to load function.
28 * @author Jaroslav Tulach <jtulach@netbeans.org>
34 public static void init() {
37 public static byte[] loadFromCp(Object[] classpath, String res) {
38 for (int i = 0; i < classpath.length; i++) {
39 Object c = classpath[i];
40 if (c instanceof String) {
42 c = classpath[i] = toZip((String)c);
43 } catch (IOException ex) {
47 if (c instanceof Zips) {
48 Object checkRes = ((Zips)c).findRes(res);
49 if (checkRes instanceof byte[]) {
50 return (byte[])checkRes;
57 @JavaScriptBody(args = { "res" }, body = "var r = this[res]; return r ? r : null;")
58 private native byte[] findRes(String res);
60 @JavaScriptBody(args = { "res", "arr" }, body = "this[res] = arr;")
61 private native void putRes(String res, byte[] arr);
63 private static Zips toZip(String path) throws IOException {
64 URL u = new URL(path);
65 ZipInputStream zip = new ZipInputStream(u.openStream());
68 ZipEntry entry = zip.getNextEntry();
72 byte[] arr = new byte[4096];
75 int len = zip.read(arr, offset, arr.length - offset);
80 if (offset == arr.length) {
81 enlargeArray(arr, arr.length + 4096);
84 sliceArray(arr, offset);
85 z.putRes(entry.getName(), arr);
90 @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(0);")
91 private static native void enlargeArray(byte[] arr, int len);
93 @JavaScriptBody(args = { "arr", "len" }, body = "arr.splice(len, arr.length - len);")
94 private static native void sliceArray(byte[] arr, int len);