1 17 package org.apache.geronimo.jetty; 18 19 import java.net.URL ; 20 import java.net.URLClassLoader ; 21 22 25 public class JettyClassLoader extends URLClassLoader { 26 private final boolean contextPriorityClassLoader; 27 private final ClassLoader parent; 28 private final ClassLoader resourceClassLoader; 29 30 public JettyClassLoader(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.mortbay.") || 57 name.startsWith("org.xml.") || 58 name.startsWith("org.w3c.")) { 59 return super.loadClass(name); 60 } 61 62 Class clazz = findLoadedClass(name); 64 if (clazz != null) { 65 return clazz; 66 } 67 68 try { 70 clazz = findClass(name); 71 } catch (ClassNotFoundException ignored) { 72 } 73 if (clazz != null) { 74 return clazz; 75 } 76 77 return parent.loadClass(name); 79 } 80 81 public URL getResource(String name) { 82 return resourceClassLoader.getResource(name); 83 } 84 85 private class ResourceClassLoader extends URLClassLoader { 86 87 public ResourceClassLoader(URL [] urls, ClassLoader classLoader) { 88 super(urls, classLoader); 89 } 90 91 public URL getResource(String name) { 92 if (!contextPriorityClassLoader || 93 name.startsWith("java/") || 94 name.startsWith("javax/") || 95 name.startsWith("org/apache/geronimo/") || 96 name.startsWith("org/mortbay/") || 97 name.startsWith("org/xml/") || 98 name.startsWith("org/w3c/")) { 99 return super.getResource(name); 100 } 101 102 URL url = findResource(name); 104 if (url != null) { 105 return url; 106 } 107 108 return parent.getResource(name); 110 } 111 } 112 } 113 | Popular Tags |