/Users/lyon/j4p/src/net/compute/DelegatingLoader.java

1    package net.compute; 
2     
3    import java.io.File; 
4    import java.io.IOException; 
5     
6    /** 
7     * Created by 
8     * User: lyon 
9     * Date: Aug 19, 2003 
10    * Time: 9:42:36 AM 
11    * 
12    */ 
13    
14   /** A classloader that delegates some loads to the system loader, 
15    * and serves other requests by reading in from a given directory. 
16    */ 
17   public class DelegatingLoader extends LocalClassLoader { 
18       public DelegatingLoader(String dir) { 
19           super(dir); 
20       } 
21       public static Class getClassFromFile(File f){ 
22           DelegatingLoader dl = new DelegatingLoader(""); 
23           try { 
24              return dl.loadClassFromFile(f,true); 
25           } catch (IOException e) { 
26               e.printStackTrace(); 
27           } 
28           return null; 
29       } 
30    
31       public synchronized Class loadClass(String name, boolean resolve) 
32               throws ClassNotFoundException { 
33           Class c; 
34           try { 
35               if (name.equals("RR") || name.startsWith("java.")|| 
36                       name.startsWith("javax.") ||(findSystemClass(name) != null)){ 
37                   System.out.println("[Loaded " + name + " from system]"); 
38                   return this.findSystemClass(name); 
39               } else 
40                   return this.loadClassFromFile(name, resolve); 
41           } catch (Exception d) { 
42               System.out.println("Exception " + d.toString() + " while loading " + name + " in DelegatingLoader."); 
43               throw new ClassNotFoundException(); 
44           } 
45       } 
46   } 
47    
48