From da6d03c08d9557bb6e60b52ed797a28f0db5da2b Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Fri, 14 Sep 2012 15:45:04 +0200 Subject: [PATCH] Code quality --- .../beans/application/ProjectsBean.java | 8 +- .../kieker/webgui/beans/session/UserBean.java | 32 +++++--- .../beans/view/CurrentAnalysisEditorBean.java | 7 +- .../view/CurrentAnalysisEditorGraphBean.java | 2 +- .../webgui/beans/view/CurrentCockpitBean.java | 5 -- .../webgui/common/IProjectManagerFacade.java | 64 +++++++++++++++- .../kieker/webgui/common/util/ACManager.java | 73 ++++++++++++++++++- .../kieker/webgui/common/util/Analysis.java | 60 +++++++++++++++ .../webgui/common/util/PluginFinder.java | 10 ++- 9 files changed, 230 insertions(+), 31 deletions(-) diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ProjectsBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ProjectsBean.java index 9f625e6b..7d0eb40c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ProjectsBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/application/ProjectsBean.java @@ -42,14 +42,12 @@ import kieker.webgui.common.ProjectManagerFacade; import kieker.webgui.common.exception.ProjectAlreadyExistingException; import kieker.webgui.common.exception.ProjectLoadException; import kieker.webgui.common.exception.ProjectNotExistingException; -import kieker.webgui.common.util.ACManager; -import kieker.webgui.common.util.FSManager; /** * The {@link ProjectsBean} is a JSF managed bean to manage a list with all application wide available projects. It provides methods to receive this list as well as * methods to add, create, rename, open and copy projects. Furthermore the state of existing projects (like the timestamp or the state of the analysis) can be * received via this bean. In order to realize a good abstraction, this bean should be used for any access to the projects. The necessary synchronization is achieved - * in the {@link FSManager}.<br> + * in the {@link ProjectManagerFacade}.<br> * As this bean contains the whole list of the available projects, it is application scoped. There is no reason for multiple instances of this class. * * @author Nils Christian Ehmke @@ -152,7 +150,7 @@ public final class ProjectsBean { /** * This method can be used to open an already existing project. This means that the current state of the project on the file system is loaded into an instance of - * {@link MIProject}. This instance can be modified at will and for example later saved by the {@link FSManager}. + * {@link MIProject}. This instance can be modified at will and for example later saved by the {@link ProjectManagerFacade}. * * @param project * The name of the project to be opened. @@ -211,7 +209,7 @@ public final class ProjectsBean { * * @param project * The project whose state should be delivered. - * @return The current state of the corresponding AnalysisController as defined by {@link ACManager#getAnalysisControllerStateString(String)}. + * @return The current state of the corresponding AnalysisController. */ public String getAnalysisControllerState(final String project) { try { diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/UserBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/UserBean.java index fe9f0217..e52c4a38 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/UserBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/UserBean.java @@ -20,8 +20,6 @@ package kieker.webgui.beans.session; -import java.io.Serializable; - import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty; import javax.faces.bean.SessionScoped; @@ -39,12 +37,7 @@ import org.primefaces.context.RequestContext; */ @ManagedBean @SessionScoped -public final class UserBean implements Serializable { - - /** - * The serial version UID. - */ - private static final long serialVersionUID = 3942693805646862667L; +public final class UserBean { /** * This field contains the name of the user. */ @@ -88,19 +81,36 @@ public final class UserBean implements Serializable { return this.globalPropertiesBean.getProjectOverviewPage(); } + /** + * The getter for the property {@link UserBean#globalPropertiesBean}. + * + * @return The current value of the property. + */ public GlobalPropertiesBean getGlobalPropertiesBean() { return this.globalPropertiesBean; } + /** + * The setter for the property {@link UserBean#globalPropertiesBean}. + * + * @param globalPropertiesBean + * The new value of the property. + */ public void setGlobalPropertiesBean(final GlobalPropertiesBean globalPropertiesBean) { this.globalPropertiesBean = globalPropertiesBean; } + /** + * This method shows the welcome message using the growl component and the global properties. + */ public void showWelcomeMessage() { - final String welcomeMsgTemplate = "growlComp.renderMessage({summary : '%s', detail : '%s', severity: 'info'});"; - final String finalMsg = String.format(welcomeMsgTemplate, this.globalPropertiesBean.getShortWelcomeMessage(), this.globalPropertiesBean.getWelcomeMessage()); + if (this.globalPropertiesBean != null) { + final String welcomeMsgTemplate = "growlComp.renderMessage({summary : '%s', detail : '%s', severity: 'info'});"; + final String finalMsg = String.format(welcomeMsgTemplate, this.globalPropertiesBean.getShortWelcomeMessage(), + this.globalPropertiesBean.getWelcomeMessage()); - RequestContext.getCurrentInstance().execute(finalMsg); + RequestContext.getCurrentInstance().execute(finalMsg); + } } } 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 ea04294a..782ef4c2 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 @@ -471,7 +471,12 @@ public final class CurrentAnalysisEditorBean { if (component instanceof MIPlugin) { className = ((MIPlugin) component).getClassname(); } else { - className = ((MIRepository) component).getClassname(); + if (component instanceof MIRepository) { + className = ((MIRepository) component).getClassname(); + } else { + // Unknown type + return "N/A"; + } } final Class<?> clazz = this.classLoader.loadClass(className); final List<Annotation> properties = this.getProperties(clazz); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorGraphBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorGraphBean.java index 73c77ba6..63caeeb8 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorGraphBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/view/CurrentAnalysisEditorGraphBean.java @@ -232,7 +232,7 @@ public class CurrentAnalysisEditorGraphBean { * * @param source * The source plugin. - * @param repository + * @param destination * The destination repository. * @param port * The repository port. 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 59c0c733..031ce5e3 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 @@ -145,9 +145,7 @@ public class CurrentCockpitBean { } } } catch (final ProjectNotExistingException ex) { - // TODO } catch (final IOException ex) { - // TODO } } @@ -206,7 +204,6 @@ public class CurrentCockpitBean { return result; } catch (final Exception ex) { return ""; - // TODO } } @@ -246,7 +243,6 @@ public class CurrentCockpitBean { return result; } catch (final Exception ex) { return ""; - // TODO } } @@ -286,7 +282,6 @@ public class CurrentCockpitBean { return result; } catch (final Exception ex) { return ""; - // TODO } } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/IProjectManagerFacade.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/IProjectManagerFacade.java index 804fc092..309dd3ed 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/IProjectManagerFacade.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/IProjectManagerFacade.java @@ -184,17 +184,71 @@ public interface IProjectManagerFacade { */ public List<String> listAllLibraries(final String projectName) throws ProjectNotExistingException; + /** + * This method delivers the available classes from the type {@link AbstractRepository} within the given dependency for the given project, using the given + * parameters. + * + * @param lib + * The library to be searched. + * @param project + * The project for the given library. + * @param classLoader + * The class loader to be used. + * @param classAndMethodContainer + * The container with classes and methods to be used. + * @return A list with all repository-classes. + * @throws LibraryLoadException + * If something went wrong during the loading of the library. + */ public List<Class<AbstractRepository>> getAllRepositoriesWithinLib(final MIDependency lib, final String project, final ClassLoader classLoader, final ClassAndMethodContainer classAndMethodContainer) throws LibraryLoadException; + /** + * This method delivers the available classes from the type {@link AbstractPlugin} within the given dependency for the given project, using the given + * parameters. + * + * @param lib + * The library to be searched. + * @param project + * The project for the given library. + * @param classLoader + * The class loader to be used. + * @param classAndMethodContainer + * The container with classes and methods to be used. + * @return A list with all plugin-classes. + * @throws LibraryLoadException + * If something went wrong during the loading of the library. + */ public List<Class<AbstractPlugin>> getAllPluginsWithinLib(final MIDependency lib, final String project, final ClassLoader classLoader, final ClassAndMethodContainer classAndMethodContainer) throws LibraryLoadException; - public List<Class<AbstractRepository>> getAllRepositoriesWithinKiekerLib(final ClassLoader classLoader, final ClassAndMethodContainer classAndMethodContainer) - throws LibraryLoadException; + /** + * This method delivers the available classes from the type {@link AbstractRepository} within the kieker dependency using the given parameters. + * + * @param classLoader + * The class loader to be used. + * @param classAndMethodContainer + * The container with classes and methods to be used. + * @return A list with all repository-classes. + * @throws LibraryLoadException + * If something went wrong during the loading of the library. + */ + public List<Class<AbstractRepository>> getAllRepositoriesWithinKiekerLib(final ClassLoader classLoader, + final ClassAndMethodContainer classAndMethodContainer) throws LibraryLoadException; - public List<Class<AbstractPlugin>> getAllPluginsWithinKiekerLib(final ClassLoader classLoader, final ClassAndMethodContainer classAndMethodContainer) - throws LibraryLoadException; + /** + * This method delivers the available classes from the type {@link AbstractPlugin} within the kieker dependency using the given parameters. + * + * @param classLoader + * The class loader to be used. + * @param classAndMethodContainer + * The container with classes and methods to be used. + * @return A list with all plugin-classes. + * @throws LibraryLoadException + * If something went wrong during the loading of the library. + */ + public List<Class<AbstractPlugin>> getAllPluginsWithinKiekerLib(final ClassLoader classLoader, final ClassAndMethodContainer classAndMethodContainer) throws + LibraryLoadException; /** * This method lists all available projects on the file system. @@ -208,6 +262,8 @@ public interface IProjectManagerFacade { * * @param projectName * The name of the project whose analysis should be initialized. + * @param classLoader + * The class loader to be used during the loading. * @throws ProjectNotExistingException * If a project with the given name does not exist. * @throws AnalysisStateException diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/ACManager.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/ACManager.java index c4629998..6ff24db5 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/ACManager.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/ACManager.java @@ -52,8 +52,19 @@ public final class ACManager { // No code necessary. } - public void initializeAnalysis(final String projectName, final ClassLoader classLoader) - throws ProjectNotExistingException, AnalysisStateException { + /** + * This method initializes the analysis for the given project. + * + * @param projectName + * The name of the project to be initialized. + * @param classLoader + * The class loader to be used during the loading. + * @throws ProjectNotExistingException + * If a project with the given name does not exist. + * @throws AnalysisStateException + * If the analysis is in an invalid state to be initialized. + */ + public void initializeAnalysis(final String projectName, final ClassLoader classLoader) throws ProjectNotExistingException, AnalysisStateException { // The analysis for the given project must not exist! if (this.analyses.containsKey(projectName)) { throw new AnalysisStateException("The analysis has not been cleaned yet."); @@ -63,6 +74,16 @@ public final class ACManager { this.analyses.put(projectName, analysis); } + /** + * This method cleans the analysis for the given project. + * + * @param projectName + * The name of the project to be cleaned. + * @throws ProjectNotExistingException + * If a project with the given name does not exist. + * @throws AnalysisStateException + * If the analysis is in an invalid state to be cleaned. + */ public void cleanAnalysis(final String projectName) throws AnalysisStateException { // The analysis for the given project must exist! if (!this.analyses.containsKey(projectName)) { @@ -79,6 +100,16 @@ public final class ACManager { this.analyses.remove(projectName); } + /** + * This method starts the analysis for the given project. + * + * @param projectName + * The name of the project to be started. + * @throws ProjectNotExistingException + * If a project with the given name does not exist. + * @throws AnalysisStateException + * If the analysis is in an invalid state to be started. + */ public void startAnalysis(final String projectName) throws ProjectNotExistingException, AnalysisStateException { // The analysis for the given project must exist! if (!this.analyses.containsKey(projectName)) { @@ -94,6 +125,16 @@ public final class ACManager { analysis.start(); } + /** + * This method stops the analysis for the given project. + * + * @param projectName + * The name of the project to be stopped. + * @throws ProjectNotExistingException + * If a project with the given name does not exist. + * @throws AnalysisStateException + * If the analysis is in an invalid state to be stopped. + */ public void stopAnalysis(final String projectName) throws ProjectNotExistingException, AnalysisStateException { // The analysis for the given project must exist! if (!this.analyses.containsKey(projectName)) { @@ -109,7 +150,24 @@ public final class ACManager { analysis.stop(); } - public Object getDisplay(final String projectName, final String viewName, final String displayName) throws ProjectNotExistingException, DisplayNotFoundException { + /** + * This method delivers the display object of the (currently running) analysis for the given project and the given parameters. Technically it is an instance of + * {@code AbstractDisplay}, but in fact the project specific class loader has been used. + * + * @param projectName + * The name of the project. + * @param viewName + * The name of the view. + * @param displayName + * The name of the display. + * @return A display object for the given parameters. + * @throws ProjectNotExistingException + * If a project with the given name does not exist. + * @throws DisplayNotFoundException + * If a view or a display within the given view does not exist. + */ + public Object getDisplay(final String projectName, final String viewName, final String displayName) throws ProjectNotExistingException, + DisplayNotFoundException { // The analysis for the given project must exist! if (!this.analyses.containsKey(projectName)) { throw new ProjectNotExistingException("The analysis has not been initialized yet."); @@ -118,6 +176,15 @@ public final class ACManager { return this.analyses.get(projectName).getDisplay(viewName, displayName); } + /** + * This method delivers the current state of the analysis, if it is available, an exception otherwise. + * + * @param projectName + * The name of the project. + * @return The state of the given project. + * @throws ProjectNotExistingException + * If a project with the given name does not exist. + */ public STATE getCurrentState(final String projectName) throws ProjectNotExistingException { // The analysis for the given project must exist! if (!this.analyses.containsKey(projectName)) { diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/Analysis.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/Analysis.java index 3f281a6d..c62914ac 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/Analysis.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/Analysis.java @@ -1,3 +1,23 @@ +/*************************************************************************** + * Copyright 2012 by + * + Christian-Albrechts-University of Kiel + * + Department of Computer Science + * + Software Engineering Group + * and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + package kieker.webgui.common.util; import java.io.File; @@ -16,6 +36,12 @@ import kieker.webgui.common.ClassAndMethodContainer; import kieker.webgui.common.exception.AnalysisStateException; import kieker.webgui.common.exception.ProjectLoadException; +/** + * An analysis within the web gui. + * + * @author Nils Christian Ehmke + * @version 1.0 + */ public class Analysis { /** * This is the log for errors, exceptions etc. @@ -28,6 +54,16 @@ public class Analysis { private final Object analysisControllerThread; private final UpdateDisplaysThread updateDisplaysThread; + /** + * Creates a new instance of this class using the given parameters. + * + * @param classLoader + * The class loader to be used to initialize the analysis. + * @param projectFile + * The file to be loaded. + * @throws AnalysisStateException + * If something went wrong during the loading of the analysis. + */ public Analysis(final ClassLoader classLoader, final File projectFile) throws AnalysisStateException { try { this.classAndMethodContainer = new ClassAndMethodContainer(classLoader); @@ -51,6 +87,12 @@ public class Analysis { } } + /** + * Starts the analysis. + * + * @throws AnalysisStateException + * If the analysis is in the wrong state to be started. + */ public void start() throws AnalysisStateException { synchronized (this) { try { @@ -69,6 +111,9 @@ public class Analysis { } + /** + * Stops the analysis. + */ public void stop() { synchronized (this) { try { @@ -90,12 +135,27 @@ public class Analysis { } } + /** + * Delivers the current state of the analysis. + * + * @return The state. + */ public Enum<?> getCurrentState() { synchronized (this) { return (Enum<?>) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getAnalysisControllerGetState(), this.analysisController, null); } } + /** + * This method delivers the display object of the (currently running) analysis. Technically it is an instance of {@code AbstractDisplay}, but in fact the project + * specific class loader has been used. + * + * @param viewName + * The name of the view. + * @param displayName + * The name of the display. + * @return A display object for the given parameters. + */ public Object getDisplay(final String viewName, final String displayName) { return this.updateDisplaysThread.getDisplay(viewName, displayName); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/PluginFinder.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/PluginFinder.java index 39f14a92..e8faa575 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/PluginFinder.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/PluginFinder.java @@ -104,10 +104,11 @@ public final class PluginFinder { * @return A list containing all available classes or null, if an exception occurred. */ private static List<Class<?>> getAllClassesWithinJar(final URL url, final ClassLoader classLoader) { + JarInputStream stream = null; try { final List<Class<?>> result = new ArrayList<Class<?>>(); // Open the jar as a stream and run through all entries within this file - final JarInputStream stream = new JarInputStream(url.openStream()); + stream = new JarInputStream(url.openStream()); JarEntry jarEntry; while ((jarEntry = stream.getNextJarEntry()) != null) { @@ -127,6 +128,13 @@ public final class PluginFinder { stream.close(); return result; } catch (final IOException ex) { + if (stream != null) { + try { + stream.close(); + } catch (final IOException ex1) { + ex1.printStackTrace(); + } + } ex.printStackTrace(); } return null; -- GitLab