root/trunk/ProjectFortress/src/com/sun/fortress/compiler/nativeInterface/MyClassLoader.java @ 3290

Revision 3290, 2.2 KB (checked in by chf, 11 months ago)

preliminary native code wrapping

Line 
1/*******************************************************************************
2  Copyright 2009 Sun Microsystems, Inc.,
3  4150 Network Circle, Santa Clara, California 95054, U.S.A.
4  All rights reserved.
5
6  U.S. Government Rights - Commercial software.
7  Government users are subject to the Sun Microsystems, Inc. standard
8  license agreement and applicable provisions of the FAR and its supplements.
9
10  Use is subject to license terms.
11
12  This distribution may include materials developed by third parties.
13
14  Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15  trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16******************************************************************************/
17
18package com.sun.fortress.compiler.nativeInterface;
19
20import java.io.FileOutputStream;
21import java.io.FileInputStream;
22import com.sun.fortress.repository.ProjectProperties;
23
24public class MyClassLoader extends ClassLoader {
25   
26    String repository = ProjectProperties.NATIVE_WRAPPER_CACHE_DIR;
27
28    public MyClassLoader() {
29        // TODO Auto-generated constructor stub
30    }
31
32    public MyClassLoader(ClassLoader parent) {
33        super(parent);
34        // TODO Auto-generated constructor stub
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}
Note: See TracBrowser for help on using the browser.