1 16 package org.apache.cocoon.servlet; 17 18 import java.io.File ; 19 import java.io.IOException ; 20 import java.net.URL ; 21 import java.net.URLClassLoader ; 22 import java.net.URLStreamHandlerFactory ; 23 24 33 34 public class ParanoidClassLoader extends URLClassLoader { 35 36 39 public ParanoidClassLoader() { 40 this(null, null, null); 41 } 42 43 46 public ParanoidClassLoader(final ClassLoader parent) { 47 this(new URL [0], parent, null); 48 } 49 50 53 public ParanoidClassLoader(final URL [] urls) { 54 this(urls, null, null); 55 } 56 57 61 public ParanoidClassLoader(final URL [] urls, final ClassLoader parent) { 62 this(urls, parent, null); 63 } 64 65 69 public ParanoidClassLoader(final URL [] urls, final ClassLoader parent, final URLStreamHandlerFactory factory) { 70 super(urls, parent, factory); 71 } 72 73 77 public static final URLClassLoader newInstance(final URL [] urls) { 78 return new ParanoidClassLoader(urls); 79 } 80 81 85 public static final URLClassLoader newInstance(final URL [] urls, final ClassLoader parent) { 86 return new ParanoidClassLoader(urls, parent); 87 } 88 89 101 public final Class loadClass(String name, boolean resolve) throws ClassNotFoundException { 102 Class clazz = findLoadedClass(name); 104 105 if (clazz == null) { 106 107 try { 108 clazz = findClass(name); 109 } catch (ClassNotFoundException cnfe) { 111 ClassLoader parent = getParent(); 112 if (parent != null) { 113 clazz = parent.loadClass(name); 115 } else { 116 throw cnfe; 118 } 119 } 120 } 121 122 if (resolve) { 123 resolveClass(clazz); 124 } 125 126 return clazz; 127 } 128 129 138 public final URL getResource(final String name) { 139 140 URL resource = findResource(name); 141 ClassLoader parent = this.getParent(); 142 if (resource == null && parent != null) { 143 resource = parent.getResource(name); 144 } 145 146 return resource; 147 } 148 149 156 public final void addDirectory(File file) throws IOException { 157 this.addURL(file.getCanonicalFile().toURL()); 158 } 159 160 163 164 public void addURL(URL url) { 165 super.addURL(url); 166 } 167 } | Popular Tags |