diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginClassLoader.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginClassLoader.java index f6e2d820a6841fc6108c5055e36202af24152832..7b818b81e16829643fbb8af58d561697ef0f27a4 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginClassLoader.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/PluginClassLoader.java @@ -25,6 +25,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -52,15 +53,17 @@ public final class PluginClassLoader extends ClassLoader { * The singleton instance of this class. */ private static PluginClassLoader instance; - /** - * This list contains a class loader for each url added to this class loader. - */ - private final Map<String, URLClassLoader> classLoaders = new HashMap<String, URLClassLoader>(); + + private final List<URL> list = new ArrayList<URL>(); + + private URLClassLoader classLoader = null; + /** * The default constructor of this class. During the creation all available libraries will be added to the class loader. */ private PluginClassLoader() { + classLoader = AnalysisController.class.getClassLoader(); /* Make sure that all libs are loaded. */ final List<MIDependency> libs = FileManager.getInstance().loadAllDependencies(); for (final MIDependency lib : libs) { @@ -79,15 +82,9 @@ public final class PluginClassLoader extends ClassLoader { * The URL of the dependency to be added. */ public void addURL(final URL url) { - /* Create the new class loader within a privileged block. */ - final URLClassLoader newClassLoader = (URLClassLoader) AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Object run() { - return new URLClassLoader(new URL[] { url }, AnalysisController.class.getClassLoader()); - } - }); - - this.classLoaders.put(url.toString(), newClassLoader); + list.add(url); + + classLoader = new URLClassLoader(list.toArray(new URL[list.size()]), AnalysisController.class.getClassLoader()); } /** @@ -97,7 +94,9 @@ public final class PluginClassLoader extends ClassLoader { * The URL of the dependency to be added. */ public void removeURL(final URL url) { - // TODO Implement + list.remove(url); + + classLoader = new URLClassLoader(list.toArray(new URL[list.size()]), AnalysisController.class.getClassLoader()); } /** @@ -131,25 +130,6 @@ public final class PluginClassLoader extends ClassLoader { */ @Override public Class<?> loadClass(final String name) throws ClassNotFoundException { - try { - return ClassLoader.getSystemClassLoader().loadClass(name); - } catch (final ClassNotFoundException ex) { - /* Ignore exception. */ - } - synchronized (this) { - /* Run through all available class loaders and try to find the correct class. */ - final Iterator<URLClassLoader> classLoaderIter = this.classLoaders.values().iterator(); - while (classLoaderIter.hasNext()) { - final URLClassLoader currClassLoader = classLoaderIter.next(); - /* If no exception is thrown, we found the correct class and return it. Otherwise we continue the search. */ - try { - return currClassLoader.loadClass(name); - } catch (final ClassNotFoundException ex) { - // Ignore error - } - } - } - /* We were not able to found any class and throw an exception. */ - throw new ClassNotFoundException(); + return classLoader.loadClass(name); } }