1 17 package org.apache.geronimo.tomcat; 18 19 import java.net.URL ; 20 import java.net.URLClassLoader ; 21 22 25 public class TomcatClassLoader extends URLClassLoader { 26 private final boolean contextPriorityClassLoader; 27 private final ClassLoader parent; 28 private final ClassLoader resourceClassLoader; 29 30 public TomcatClassLoader(URL [] urls, URL resourceURL, ClassLoader parent, boolean contextPriorityClassLoader) { 31 super(urls, parent); 32 33 if (parent == null) { 34 throw new IllegalArgumentException ("Parent class loader is null"); 35 } 36 URL [] resourceURLS; 37 if (resourceURL != null) { 38 resourceURLS = new URL [urls.length + 1]; 39 System.arraycopy(urls, 0, resourceURLS, 0, urls.length); 40 resourceURLS[resourceURLS.length - 1] = resourceURL; 41 } else { 42 resourceURLS = urls; 43 } 44 resourceClassLoader = new ResourceClassLoader(resourceURLS, parent); 45 46 this.parent = parent; 48 this.contextPriorityClassLoader = contextPriorityClassLoader; 49 } 50 51 public Class loadClass(String name) throws ClassNotFoundException { 52 if (!contextPriorityClassLoader || 53 name.startsWith("java.") || 54 name.startsWith("javax.") || 55 name.startsWith("org.apache.geronimo.") || 56 name.startsWith("org.apache.jasper.") || 57 name.startsWith("org.apache.tomcat.") || 58 name.startsWith("org.apache.naming.") || 59 name.startsWith("org.apache.catalina.") || 60 name.startsWith("org.xml.") || 61 name.startsWith("org.w3c.")) { 62 return super.loadClass(name); 63 } 64 65 Class clazz = findLoadedClass(name); 67 if (clazz != null) { 68 return clazz; 69 } 70 71 try { 73 clazz = findClass(name); 74 } catch (ClassNotFoundException ignored) { 75 } 76 if (clazz != null) { 77 return clazz; 78 } 79 80 return parent.loadClass(name); 82 } 83 84 public URL getResource(String name) { 85 return resourceClassLoader.getResource(name); 86 } 87 88 private class ResourceClassLoader extends URLClassLoader { 89 90 public ResourceClassLoader(URL [] urls, ClassLoader classLoader) { 91 super(urls, classLoader); 92 } 93 94 public URL getResource(String name) { 95 if (!contextPriorityClassLoader || 96 name.startsWith("java/") || 97 name.startsWith("javax/") || 98 name.startsWith("org/apache/geronimo/") || 99 name.startsWith("org/apache/jasper") || 100 name.startsWith("org/apache/tomcat") || 101 name.startsWith("org/apache/naming") || 102 name.startsWith("org/apache/catalina") || 103 name.startsWith("org/xml/") || 104 name.startsWith("org/w3c/")) { 105 return super.getResource(name); 106 } 107 108 URL url = findResource(name); 110 if (url != null) { 111 return url; 112 } 113 114 return parent.getResource(name); 116 } 117 } 118 } 119 | Popular Tags |