Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame^] | 1 | package aQute.libg.classloaders; |
| 2 | |
| 3 | import java.lang.reflect.*; |
| 4 | import java.net.*; |
| 5 | |
| 6 | public class URLClassLoaderWrapper { |
| 7 | final URLClassLoader loader; |
| 8 | final Method addURL; |
| 9 | |
| 10 | public URLClassLoaderWrapper(ClassLoader loader) throws Exception { |
| 11 | this.loader = (URLClassLoader) loader; |
| 12 | addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); |
| 13 | addURL.setAccessible(true); |
| 14 | } |
| 15 | |
| 16 | public void addURL(URL url) throws Exception { |
| 17 | try { |
| 18 | addURL.invoke(loader, url); |
| 19 | } catch( InvocationTargetException ite) { |
| 20 | throw (Exception) ite.getTargetException(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | public Class<?> loadClass(String name) throws Exception { |
| 25 | return loader.loadClass(name); |
| 26 | } |
| 27 | } |