From cc6888841d78204a4c70d3b00cc283c04bf9f6c3 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Mon, 30 Jul 2012 15:40:00 +0200 Subject: [PATCH] Some minor code modifications for quality reasons --- .../beans/application/ThemeSwitcherBean.java | 2 +- .../beans/session/CurrentThemeBean.java | 4 +- .../beans/view/CurrentAnalysisEditorBean.java | 6 +- .../webgui/beans/view/CurrentCockpitBean.java | 6 +- .../beans/view/CurrentCockpitEditorBean.java | 5 +- .../beans/view/CurrentControllerBean.java | 6 +- .../view/CurrentProjectOverviewBean.java | 9 ++- .../java/kieker/webgui/common/FSManager.java | 55 ++++++++++++++----- 8 files changed, 68 insertions(+), 25 deletions(-) diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ThemeSwitcherBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ThemeSwitcherBean.java index 965eb13d..fad4a1aa 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ThemeSwitcherBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ThemeSwitcherBean.java @@ -43,7 +43,7 @@ public final class ThemeSwitcherBean { /** * A map containing all available themes. */ - private final Map<String, String> themes = new TreeMap<String, String>(); + private final Map<String, String> themes = new TreeMap<String, String>(); // NOPMD (No concurrent access) /** * Default constructor. <b>Do not use this constructor. This bean is JSF managed.</b> diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentThemeBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentThemeBean.java index b6df74fe..a8664d8e 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentThemeBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentThemeBean.java @@ -78,7 +78,7 @@ public final class CurrentThemeBean implements Serializable { */ private void setDefaultTheme() { // Get the parameters within the current context. - final Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); + final Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); // NOPMD (No concurrent access) // Try to find the default theme within the parameters. if (params.containsKey(CurrentThemeBean.KEY_THEME)) { this.theme = params.get(CurrentThemeBean.KEY_THEME); @@ -93,7 +93,7 @@ public final class CurrentThemeBean implements Serializable { */ private void searchThemeInCookies() { // Try to find the cookie for the theme. - final Map<String, Object> cookies = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap(); + final Map<String, Object> cookies = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap(); // NOPMD (No concurrent access) if (cookies.containsKey(CurrentThemeBean.KEY_COOKIE_THEME)) { this.theme = ((Cookie) cookies.get(CurrentThemeBean.KEY_COOKIE_THEME)).getValue(); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBean.java index 88da8b88..f2a9478e 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorBean.java @@ -80,7 +80,10 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; /** - * This bean contains the project of the current (session) user for the analysis editor. + * The {@link CurrentAnalysisEditorBean} contains the necessary data behind an instance of the analysis editor. It provides various methods to manipulate the current + * project, as the analysis editor is the most important part of the whole application.<br> + * The class is a JSF managed bean with view scope to make sure that one user (even in one session) can open multiple projects at a time without causing any + * problems. * * @author Nils Christian Ehmke * @version 1.0 @@ -179,7 +182,6 @@ public final class CurrentAnalysisEditorBean { * * @param newName * The name of the project. - * @return The name of the page for the project work space, if the project has been accepted, '' if it is null. */ public void setProjectName(final String newName) { synchronized (this) { diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitBean.java index 9f6a5a67..d0e935f5 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitBean.java @@ -34,7 +34,10 @@ import kieker.webgui.common.ACManager; import kieker.webgui.common.Global; /** - * This bean contains the project of the current (session) user for the cockpit. + * The {@link CurrentCockpitBean} contains the necessary data behind an instance of the cockpit. It provides methods to read the state of the currently + * selected project.<br> + * The class is a JSF managed bean with view scope to make sure that one user (even in one session) can open multiple projects at a time without causing any + * problems. * * @author Nils Christian Ehmke * @version 1.0 @@ -79,7 +82,6 @@ public class CurrentCockpitBean { * * @param newName * The name of the project. - * @return The name of the page for the cockpit. */ public void setProjectName(final String newName) { synchronized (this) { diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitEditorBean.java index cd496fad..c8795ae7 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentCockpitEditorBean.java @@ -53,7 +53,9 @@ import org.primefaces.context.RequestContext; import org.primefaces.event.TabChangeEvent; /** - * This bean contains the project of the current (session) user for the cockpit editor. + * The {@link CurrentCockpitEditorBean} contains the necessary data behind an instance of the cockpit editor. + * The class is a JSF managed bean with view scope to make sure that one user (even in one session) can open multiple projects at a time without causing any + * problems. * * @author Nils Christian Ehmke * @version 1.0 @@ -109,7 +111,6 @@ public class CurrentCockpitEditorBean { * * @param newName * The name of the project. - * @return The name of the page for the analysis view work space. */ public void setProjectName(final String newName) { synchronized (this) { diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentControllerBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentControllerBean.java index 508549fa..6e54a55b 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentControllerBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentControllerBean.java @@ -42,7 +42,10 @@ import kieker.webgui.common.exception.ProjectAlreadyStartedException; import kieker.webgui.common.exception.ProjectStillRunningException; /** - * This bean contains the project of the current (session) user for the controller page. + * /** + * The {@link CurrentControllerBean} contains the necessary data behind an instance of the analysis controller. + * The class is a JSF managed bean with view scope to make sure that one user (even in one session) can open multiple projects at a time without causing any + * problems. * * @author Nils Christian Ehmke * @version 1.0 @@ -75,7 +78,6 @@ public class CurrentControllerBean { * * @param newName * The name of the project. - * @return The name of the page for the cockpit. */ public void setProjectName(final String newName) { synchronized (this) { diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentProjectOverviewBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentProjectOverviewBean.java index 4657efaa..3b66b882 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentProjectOverviewBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentProjectOverviewBean.java @@ -34,7 +34,9 @@ import kieker.webgui.beans.application.ProjectsBean; import org.primefaces.event.SelectEvent; /** - * This bean is used in the context of the project overview page. + * /** + * The {@link CurrentControllerBean} contains the necessary data behind an instance of the project overview.<br> + * The class is a JSF managed bean with view scope. * * @author Nils Christian Ehmke * @version 1.0 @@ -106,6 +108,11 @@ public class CurrentProjectOverviewBean { this.projects = bean.getProjects(); } + /** + * This method delivers the current instance of this bean, using the current faces context and the necessary el resolver. + * + * @return The current instance of {@link CurrentProjectOverviewBean}. + */ public static CurrentProjectOverviewBean getCurrentInstance() { // Get both the context and the resolver final FacesContext facesContext = FacesContext.getCurrentInstance(); 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 85b70ccc..3b50267b 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/FSManager.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/FSManager.java @@ -377,23 +377,52 @@ public final class FSManager { // NOCS (Class Data Abstraction Coupling, Class F * @param dst * The destination element. This should be a (non existing) file. * @throws IOException - * If something went wrong + * If something went wrong. In this case the method will try to close all streams nevertheless. */ private void copyFile(final File src, final File dst) throws IOException { + boolean result = true; // Open the files - final FileInputStream fileInputStream = new FileInputStream(src); - final FileOutputStream fileOutputStream = new FileOutputStream(dst); - final FileChannel inputChannel = fileInputStream.getChannel(); - final FileChannel outputChannel = fileOutputStream.getChannel(); - - // Copy the data - this.transfer(inputChannel, outputChannel, src.length()); - - // Close the streams - fileInputStream.close(); - fileOutputStream.close(); + FileInputStream fileInputStream = null; + FileOutputStream fileOutputStream = null; + + try { + fileInputStream = new FileInputStream(src); + fileOutputStream = new FileOutputStream(dst); + final FileChannel inputChannel = fileInputStream.getChannel(); + final FileChannel outputChannel = fileOutputStream.getChannel(); + + // Copy the data + this.transfer(inputChannel, outputChannel, src.length()); + + // This is just necessary to calm findbugs + result = dst.setLastModified(src.lastModified()); + + } catch (final IOException ex) { + FSManager.LOG.error("An IO error occured", ex); + result = false; + } finally { + // Try to close the streams + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (final IOException ex) { + FSManager.LOG.error("An IO error occured", ex); + result = false; + } + } + if (fileOutputStream != null) { + try { + fileOutputStream.close(); + } catch (final IOException ex) { + FSManager.LOG.error("An IO error occured", ex); + result = false; + } + } + } - dst.setLastModified(src.lastModified()); + if (!result) { + throw new IOException("An IO error occured"); + } } /** -- GitLab