From ec4b13bc7443abf86f6d36c285b4675b693c1b03 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Sat, 28 Jul 2012 12:23:57 +0200 Subject: [PATCH] Some modifications for quality reasons. --- .../session/CurrentAnalysisEditorBean.java | 39 ++++++++++++++---- .../java/kieker/webgui/common/FSManager.java | 41 ++++++++++++++++--- 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentAnalysisEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentAnalysisEditorBean.java index b14a5b11..17e405a2 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentAnalysisEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentAnalysisEditorBean.java @@ -875,16 +875,13 @@ public final class CurrentAnalysisEditorBean { } /** - * This method removes the given plugin from the project. If it is also the currently selected plugin, it will be deselected. + * Uses the given plugin to remove the corresponding connections (to other plugins or repositories) from the current project. * * @param plugin - * The plugin to be removed from the project. + * The plugin whose connections have to be removed. */ - public void removePlugin(final MIPlugin plugin) { + private void removeCorrespondingConnections(final MIPlugin plugin) { synchronized (this) { - this.project.getPlugins().remove(plugin); - - // Remove the corresponding connections final List<ConnectionFilterToFilter> ffDelList = new ArrayList<ConnectionFilterToFilter>(); for (final ConnectionFilterToFilter conn : this.filter2filterConnections) { if ((conn.getSource() == plugin) || (conn.getDestination() == plugin)) { @@ -892,6 +889,7 @@ public final class CurrentAnalysisEditorBean { } } this.filter2filterConnections.removeAll(ffDelList); + // Remove them from the project as well for (final ConnectionFilterToFilter conn : ffDelList) { if (conn.getDestination() == plugin) { @@ -906,17 +904,44 @@ public final class CurrentAnalysisEditorBean { } } this.filter2repositoryConnections.removeAll(fRDelList); - this.pluginMap.remove(plugin); + } + } + /** + * Uses the given plugin to remove the corresponding ports from the current project. + * + * @param plugin + * The plugin whose ports have to be removed. + */ + private void removeCorrespondingPorts(final MIPlugin plugin) { + synchronized (this) { // Remove the ports from the registry for (final MIPort mPort : plugin.getOutputPorts()) { this.portMap.remove(mPort); } + // Remove the ports from the project if (plugin instanceof MIFilter) { for (final MIPort mPort : ((MIFilter) plugin).getInputPorts()) { this.portMap.remove(mPort); } } + } + } + + /** + * This method removes the given plugin from the project. If it is also the currently selected plugin, it will be deselected. + * + * @param plugin + * The plugin to be removed from the project. + */ + public void removePlugin(final MIPlugin plugin) { + synchronized (this) { + this.project.getPlugins().remove(plugin); + this.pluginMap.remove(plugin); + + this.removeCorrespondingConnections(plugin); + this.removeCorrespondingPorts(plugin); + if (this.selectedPlugin == plugin) { this.selectedPlugin = null; // NOPMD } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/FSManager.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/FSManager.java index b6f866e8..2ac8d3f1 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/FSManager.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/FSManager.java @@ -556,12 +556,8 @@ public final class FSManager { // NOCS (Class Data Abstraction Coupling, Class F } // Now assemble the URL class loader - return AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() { - @Override - public URLClassLoader run() { - return new URLClassLoader(libs.toArray(new URL[libs.size()]), AnalysisController.class.getClassLoader()); - } - }); + final PrivilegedClassLoaderAction action = new PrivilegedClassLoaderAction(libs); + return AccessController.doPrivileged(action); } } @@ -612,4 +608,37 @@ public final class FSManager { // NOCS (Class Data Abstraction Coupling, Class F } } + /** + * This helper class is responsible for creating a classloader as a privileged action. This is recommended due to the java security manager. + * + * @author Nils Christian Ehmke + * @version 1.0 + */ + private static class PrivilegedClassLoaderAction implements PrivilegedAction<URLClassLoader> { + /** + * The list of libraries used to create the class loader. + */ + final List<URL> libs; + + /** + * Creates a new instance of this class using the given parameters. + * + * @param libs + * The list of libraries used to create the class loader. + */ + public PrivilegedClassLoaderAction(final List<URL> libs) { + this.libs = libs; + } + + /** + * Runs the action. + * + * @return The class loader. + */ + @Override + public URLClassLoader run() { + return new URLClassLoader(this.libs.toArray(new URL[this.libs.size()]), AnalysisController.class.getClassLoader()); + } + } + } -- GitLab