|
Revision 3290, 2.2 KB
(checked in by chf, 11 months ago)
|
|
preliminary native code wrapping
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | package com.sun.fortress.compiler.nativeInterface; |
|---|
| 19 | |
|---|
| 20 | import java.io.FileOutputStream; |
|---|
| 21 | import java.io.FileInputStream; |
|---|
| 22 | import com.sun.fortress.repository.ProjectProperties; |
|---|
| 23 | |
|---|
| 24 | public class MyClassLoader extends ClassLoader { |
|---|
| 25 | |
|---|
| 26 | String repository = ProjectProperties.NATIVE_WRAPPER_CACHE_DIR; |
|---|
| 27 | |
|---|
| 28 | public MyClassLoader() { |
|---|
| 29 | |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | public MyClassLoader(ClassLoader parent) { |
|---|
| 33 | super(parent); |
|---|
| 34 | |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | public Class defineClass(String name, byte[] b) { |
|---|
| 38 | return defineClass(name, b, 0, b.length); |
|---|
| 39 | } |
|---|
| 40 | public static String mangle(String s ) { |
|---|
| 41 | return s; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | @SuppressWarnings("unchecked") |
|---|
| 45 | public Class findClass(String name) { |
|---|
| 46 | String n = mangle(name); |
|---|
| 47 | |
|---|
| 48 | byte[] b; |
|---|
| 49 | Class result = null; |
|---|
| 50 | try { |
|---|
| 51 | FileInputStream in = new FileInputStream( repository + n + ".class"); |
|---|
| 52 | int l = in.available(); |
|---|
| 53 | b = new byte[l]; |
|---|
| 54 | in.read(b); |
|---|
| 55 | result = defineClass(name, b, 0, l); |
|---|
| 56 | } catch (Throwable t) { |
|---|
| 57 | throw new RuntimeException(t); |
|---|
| 58 | } |
|---|
| 59 | return result; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | public void writeClass(String name, byte[] bytes) { |
|---|
| 63 | String n = mangle(name); |
|---|
| 64 | try { |
|---|
| 65 | FileOutputStream out = new FileOutputStream(repository + n + ".class"); |
|---|
| 66 | out.write(bytes); |
|---|
| 67 | } catch (Throwable t) { |
|---|
| 68 | throw new RuntimeException(t); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | } |
|---|