Protected Member Functions | |
Class | findClass (String className) throws ClassNotFoundException |
URL | findResource (String name) |
Package Functions | |
DriverClassLoader (ClassLoader parent, File pPath) |
Definition at line 57 of file DriverClassLoader.java.
|
Creates a new
Definition at line 69 of file DriverClassLoader.java. 00070 { 00071 super(parent); 00072 path = pPath; 00073 if (path == null) 00074 path = new File(""); 00075 00076 }
|
|
finds the specified class
Definition at line 83 of file DriverClassLoader.java. 00084 { 00085 00086 FileInputStream fis = null; 00087 00088 try 00089 { 00090 byte[] classBytes = null; 00091 00092 // first we try to locate a class file. 00093 String pathName = className.replace('.', File.separatorChar); 00094 File file = new File(path.getAbsolutePath(), pathName + ".class"); 00095 if (file.exists()) 00096 { 00097 // we have found a class file and read it 00098 fis = new FileInputStream(file); 00099 classBytes = new byte[fis.available()]; 00100 fis.read(classBytes); 00101 } 00102 else 00103 { 00104 // no class file exists we have to check jar files 00105 classBytes = findClassInJarFile(path, className); 00106 } 00107 00108 // we convert the bytes into the specified class 00109 Class clazz = defineClass(null, classBytes, 0, classBytes.length); 00110 return clazz; 00111 } 00112 catch (Exception e) 00113 { 00114 // We could not find the class, so indicate the problem with an exception 00115 throw new ClassNotFoundException(className, e); 00116 } 00117 finally 00118 { 00119 if (null != fis) 00120 { 00121 try 00122 { 00123 fis.close(); 00124 } 00125 catch (Exception e) 00126 { 00127 } 00128 } 00129 } 00130 }
|
|
Definition at line 207 of file DriverClassLoader.java. 00208 { 00209 00210 // we try to locate the resource unjarred 00211 if (path.isDirectory()) 00212 { 00213 File searchResource = new File(path, name); 00214 if (searchResource.exists()) 00215 { 00216 try 00217 { 00218 return searchResource.toURL(); 00219 } 00220 catch (MalformedURLException mfe) 00221 { 00222 } 00223 } 00224 } 00225 else if (path.isFile()) 00226 { 00227 // try getting the resource from the file 00228 try 00229 { 00230 new JarFile(path); 00231 // convert the jar entry into URL format 00232 return new URL("jar:" + path.toURL() + "!/" + name); 00233 } 00234 catch (Exception e) 00235 { 00236 // we couldn't find resource in file 00237 return null; 00238 } 00239 } 00240 00241 //now we are checking the jar files 00242 try 00243 { 00244 // find all jar files in the directory 00245 String[] jarFiles = path.list(new FilenameFilter() 00246 { 00247 public boolean accept(File dir, String name) 00248 { 00249 return name.endsWith(".jar"); 00250 } 00251 }); 00252 // loop over jar files 00253 for (int i = 0; i < jarFiles.length; i++) 00254 { 00255 File file = new File(path, jarFiles[i]); 00256 JarFile jarFile = new JarFile(file); 00257 00258 // we see whether the jar file contains the resource we are looking for 00259 if (jarFile.getJarEntry(name) != null) 00260 { 00261 // convert the jar entry into URL format 00262 return new URL("jar:" + file.toURL() + "!/" + name); 00263 } 00264 } 00265 } 00266 catch (Exception e) 00267 { 00268 e.printStackTrace(); 00269 } 00270 return null; 00271 }
|