1 11 12 package org.eclipse.osgi.framework.adaptor.core; 13 14 import java.io.IOException ; 15 import java.net.URL ; 16 import java.security.*; 17 import java.util.Enumeration ; 18 import org.eclipse.osgi.framework.adaptor.*; 19 import org.eclipse.osgi.framework.debug.Debug; 20 21 30 public abstract class AbstractClassLoader extends ClassLoader implements BundleClassLoader { 31 36 protected ClassLoaderDelegate delegate; 37 38 41 protected ProtectionDomain hostdomain; 42 43 46 protected String [] hostclasspath; 47 48 55 public AbstractClassLoader(ClassLoaderDelegate delegate, ProtectionDomain domain, String [] classpath, ClassLoader parent) { 56 super(parent); 57 this.delegate = delegate; 58 this.hostdomain = domain; 59 this.hostclasspath = classpath; 60 } 61 62 73 protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { 74 if (Debug.DEBUG && Debug.DEBUG_LOADER) 75 Debug.println("BundleClassLoader[" + delegate + "].loadClass(" + name + ")"); try { 77 Class clazz = delegate.findClass(name); 79 if (resolve) 81 resolveClass(clazz); 82 return (clazz); 83 } catch (Error e) { 84 if (Debug.DEBUG && Debug.DEBUG_LOADER) { 85 Debug.println("BundleClassLoader[" + delegate + "].loadClass(" + name + ") failed."); Debug.printStackTrace(e); 87 } 88 throw e; 89 } catch (ClassNotFoundException e) { 90 if (Debug.DEBUG && Debug.DEBUG_LOADER) { 93 Debug.println("BundleClassLoader[" + delegate + "].loadClass(" + name + ") failed."); Debug.printStackTrace(e); 95 } 96 throw e; 97 } 98 } 99 100 109 abstract protected Class findClass(String name) throws ClassNotFoundException ; 110 111 120 public URL getResource(String name) { 121 if (Debug.DEBUG && Debug.DEBUG_LOADER) { 122 Debug.println("BundleClassLoader[" + delegate + "].getResource(" + name + ")"); } 124 125 URL url = delegate.findResource(name); 126 if (url != null) 127 return (url); 128 129 if (Debug.DEBUG && Debug.DEBUG_LOADER) { 130 Debug.println("BundleClassLoader[" + delegate + "].getResource(" + name + ") failed."); } 132 133 return (null); 134 } 135 136 142 abstract protected URL findResource(String name); 143 144 151 protected Enumeration findResources(String name) throws IOException { 152 return (delegate.findResources(name)); 153 } 154 155 161 protected String findLibrary(String libname) { 162 return delegate.findLibrary(libname); 163 } 164 165 171 public URL findLocalResource(String resource) { 172 return findResource(resource); 173 } 174 175 182 public Class findLocalClass(String classname) throws ClassNotFoundException { 183 return findClass(classname); 184 } 185 186 192 abstract public Object findLocalObject(String path); 194 195 203 abstract public Enumeration findLocalObjects(String path); 204 205 208 public ClassLoaderDelegate getDelegate() { 209 return delegate; 210 } 211 212 215 public void close() { 216 } 218 219 } 220 | Popular Tags |