class loader question.

Rui Zhu <[email protected]> Wed, 1 Sep 2004 15:47:00 +0200
Newsgroups gmane.comp.java.jel.general
Message-ID <[email protected]>
--+QahgC5+KEYLbs62
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

recently I'm playing with JEL, and find it quite nice.  One problem
occurred that it seems to me ImageLoader has hard coded the delegate to
class loader of itself.  Most time it works fine, but in my case, I've
custom loader which therefore not known to JEL, so that the dynamically
generated 'dump' class can't find/load resolver class (set global
classpath is not good way in this case).  To make me clear I've attached
a patch (against jel-0.9.11). Opinion?

cheers rui

--+QahgC5+KEYLbs62
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ImageLoader.java.diff"

--- ImageLoader.java.orig	2003-10-15 16:08:40.000000000 +0200
+++ ImageLoader.java	2004-08-25 17:24:28.000000000 +0200
@@ -25,13 +25,18 @@
   String name;
   byte[] bytes;
   Class c;
-  ClassLoader parent;
+  ClassLoader[] parent;
   
   private ImageLoader(String name, byte[] bytes) {
     this.name=name;
     this.bytes=bytes;
     this.c=null;
-    this.parent=this.getClass().getClassLoader();
+    //this.parent=this.getClass().getClassLoader();
+    this.parent = new ClassLoader[3];
+    this.parent[0] = Thread.currentThread().getContextClassLoader();
+    this.parent[1] = this.getClass().getClassLoader();
+    this.parent[2] = ClassLoader.getSystemClassLoader();
+    //System.err.println("context: " + parent[0] + "; self: " + parent[1] + "; sys: " + parent[2]);
   };
   
 
@@ -126,9 +131,19 @@
   protected synchronized Class loadClass(String name, boolean resolve) throws
   java.lang.ClassNotFoundException  {
     if (!name.equals(this.name)) {
-      if (parent!=null) 
-        return parent.loadClass(name);
-      else
+      if (parent!=null) {
+        Class cls = null;
+        for (int i=0; i<parent.length; i++) {
+          try {
+	    cls = parent[i].loadClass(name);
+	    break;
+	  } catch (ClassNotFoundException e) {
+	  }
+	}
+	if (cls == null)
+	  throw new ClassNotFoundException();
+	return cls;
+      } else
         return findSystemClass(name);
     } else {
       if(c==null) {

--+QahgC5+KEYLbs62
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Help-jel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-jel

--+QahgC5+KEYLbs62--