1 33 34 package bsh.classpath; 35 36 import java.net.*; 37 import java.util.*; 38 import java.io.*; 39 import bsh.BshClassManager; 40 41 46 public class BshClassLoader extends URLClassLoader 47 { 48 BshClassManager classManager; 49 50 53 public BshClassLoader( BshClassManager classManager, URL [] bases ) { 54 super( bases ); 55 this.classManager = classManager; 56 } 57 58 61 public BshClassLoader( BshClassManager classManager, BshClassPath bcp ) { 62 this( classManager, bcp.getPathComponents() ); 63 } 64 65 69 protected BshClassLoader( BshClassManager classManager ) { 70 this( classManager, new URL [] { } ); 71 } 72 73 public void addURL( URL url ) { 75 super.addURL( url ); 76 } 77 78 86 public Class loadClass(String name, boolean resolve) 87 throws ClassNotFoundException 88 { 89 Class c = null; 90 91 95 c = findLoadedClass(name); 96 if ( c != null ) 97 return c; 98 99 if ( name.startsWith( ClassManagerImpl.BSH_PACKAGE ) ) 102 try { 103 return bsh.Interpreter.class.getClassLoader().loadClass( name ); 104 } catch ( ClassNotFoundException e ) {} 105 106 110 try { 111 c = findClass( name ); 112 } catch ( ClassNotFoundException e ) { } 113 114 if ( c == null ) 115 throw new ClassNotFoundException ("here in loaClass"); 116 117 if ( resolve ) 118 resolveClass( c ); 119 120 return c; 121 } 122 123 131 protected Class findClass( String name ) 133 throws ClassNotFoundException 134 { 135 ClassManagerImpl bcm = (ClassManagerImpl)getClassManager(); 139 140 143 ClassLoader cl = bcm.getLoaderForClass( name ); 147 148 Class c; 149 150 if ( cl != null && cl != this ) 152 try { 153 return cl.loadClass( name ); 154 } catch ( ClassNotFoundException e ) { 155 throw new ClassNotFoundException ( 156 "Designated loader could not find class: "+e ); 157 } 158 159 if ( getURLs().length > 0 ) 161 try { 162 return super.findClass(name); 163 } catch ( ClassNotFoundException e ) { 164 } 167 168 169 cl = bcm.getBaseLoader(); 171 172 if ( cl != null && cl != this ) 173 try { 174 return cl.loadClass( name ); 175 } catch ( ClassNotFoundException e ) { } 176 177 return bcm.plainClassForName( name ); 179 } 180 181 194 195 BshClassManager getClassManager() { return classManager; } 196 197 } 198 | Popular Tags |