From d124c5d90256ee3b395cc0b424a4d956c219381c Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Thu, 1 Nov 2012 22:36:12 +0100 Subject: [PATCH] Refactoring --- Kieker.WebGUI/.pmd | 4 - Kieker.WebGUI/.project | 6 + .../config/quality-config/cs-conf.xml | 4 - .../config/quality-config/fb-filter.xml | 9 +- .../config/quality-config/pmdrules.xml | 1 + .../webgui/common/{util => }/ViewScope.java | 2 +- .../webgui/common/util/package-info.java | 23 - .../webgui/persistence/IProjectDAO.java | 2 +- .../kieker/webgui/persistence/IUserDAO.java | 8 +- .../persistence/impl/DerbyUserDAOImpl.java | 38 +- .../persistence/impl/FSProjectDAOImpl.java | 72 +- .../impl/util/CloseableURLClassLoader.java | 14 +- .../service/impl/ProjectServiceImpl.java | 34 +- .../webgui/service/impl/UserServiceImpl.java | 4 + .../webgui/service/impl/util/ACManager.java | 2 + .../service/impl/util/PluginFinder.java | 3 + .../web/beans/application/ProjectsBean.java | 12 +- .../webgui/web/beans/request/NewUserBean.java | 5 + .../webgui/web/beans/request/StringBean.java | 5 + .../webgui/web/beans/session/UserBean.java | 11 +- .../beans/view/CurrentAnalysisEditorBean.java | 659 ++++++++---------- .../view/CurrentAnalysisEditorGraphBean.java | 67 +- .../web/beans/view/CurrentCockpitBean.java | 126 ++-- .../beans/view/CurrentCockpitEditorBean.java | 326 ++++----- .../web/beans/view/CurrentControllerBean.java | 257 +++---- .../view/CurrentProjectOverviewBean.java | 11 +- .../beans/view/CurrentUserManagementBean.java | 11 +- .../web/converter/RoleStringConverter.java | 4 + .../webapp/WEB-INF/spring-bean-config.xml | 60 +- .../webapp/WEB-INF/spring-common-config.xml | 2 +- 30 files changed, 773 insertions(+), 1009 deletions(-) rename Kieker.WebGUI/src/main/java/kieker/webgui/common/{util => }/ViewScope.java (98%) delete mode 100644 Kieker.WebGUI/src/main/java/kieker/webgui/common/util/package-info.java diff --git a/Kieker.WebGUI/.pmd b/Kieker.WebGUI/.pmd index 5bed86c3..8305b0f7 100644 --- a/Kieker.WebGUI/.pmd +++ b/Kieker.WebGUI/.pmd @@ -243,10 +243,6 @@ <name>AvoidReassigningParameters</name> <ruleset>Design Rules</ruleset> </rule> - <rule> - <name>AvoidSynchronizedAtMethodLevel</name> - <ruleset>Design Rules</ruleset> - </rule> <rule> <name>BadComparison</name> <ruleset>Design Rules</ruleset> diff --git a/Kieker.WebGUI/.project b/Kieker.WebGUI/.project index 7007fdd7..5a6290a8 100644 --- a/Kieker.WebGUI/.project +++ b/Kieker.WebGUI/.project @@ -25,11 +25,17 @@ <arguments> </arguments> </buildCommand> + <buildCommand> + <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.m2e.core.maven2Nature</nature> <nature>org.eclipse.jdt.core.javanature</nature> <nature>net.sourceforge.pmd.eclipse.plugin.pmdNature</nature> <nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature> + <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> </natures> </projectDescription> diff --git a/Kieker.WebGUI/config/quality-config/cs-conf.xml b/Kieker.WebGUI/config/quality-config/cs-conf.xml index e0caec33..172de58c 100644 --- a/Kieker.WebGUI/config/quality-config/cs-conf.xml +++ b/Kieker.WebGUI/config/quality-config/cs-conf.xml @@ -347,10 +347,6 @@ <!-- See http://checkstyle.sf.net/config_coding.html !--> <module name="DefaultComesLast"/> - <!-- The "double-checked locking" idiom (DCL) tries to avoid the runtime cost of synchronization. !--> - <!-- See http://checkstyle.sf.net/config_coding.html !--> - <module name="DoubleCheckedLocking"/> - <!-- Detects empty statements (standalone ;). !--> <!-- See http://checkstyle.sf.net/config_coding.html !--> <module name="EmptyStatement"/> diff --git a/Kieker.WebGUI/config/quality-config/fb-filter.xml b/Kieker.WebGUI/config/quality-config/fb-filter.xml index 7c54c756..0a7a6e1f 100644 --- a/Kieker.WebGUI/config/quality-config/fb-filter.xml +++ b/Kieker.WebGUI/config/quality-config/fb-filter.xml @@ -1,3 +1,10 @@ <FindBugsFilter> - + <Match> + <Class name="kieker.webgui.persistence.impl.util.CloseableURLClassLoader" /> + </Match> + + <Match> + <Class name="kieker.webgui.persistence.impl.DerbyUserDAOImpl" /> + <Bug code="ODR, OBL" /> + </Match> </FindBugsFilter> \ No newline at end of file diff --git a/Kieker.WebGUI/config/quality-config/pmdrules.xml b/Kieker.WebGUI/config/quality-config/pmdrules.xml index 47c4870b..3dc27826 100644 --- a/Kieker.WebGUI/config/quality-config/pmdrules.xml +++ b/Kieker.WebGUI/config/quality-config/pmdrules.xml @@ -36,6 +36,7 @@ <rule ref="rulesets/design.xml"> <exclude name="ConfusingTernary"/> + <exclude name="AvoidSynchronizedAtMethodLevel"/> </rule> <rule ref="rulesets/finalizers.xml"/> diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/ViewScope.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/ViewScope.java similarity index 98% rename from Kieker.WebGUI/src/main/java/kieker/webgui/common/util/ViewScope.java rename to Kieker.WebGUI/src/main/java/kieker/webgui/common/ViewScope.java index d16f3ce1..652aa84f 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/ViewScope.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/common/ViewScope.java @@ -14,7 +14,7 @@ * limitations under the License. ***************************************************************************/ -package kieker.webgui.common.util; +package kieker.webgui.common; import java.util.Map; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/package-info.java b/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/package-info.java deleted file mode 100644 index 06fc0c4f..00000000 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/common/util/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/*************************************************************************** - * Copyright 2012 Kieker Project (http://kieker-monitoring.net) - * - * 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. - ***************************************************************************/ - -/** - * This package contains utility classes, which are used in the parent-package. The classes within this package are not for public use. They should only be used by - * the classes in {@code kieker.webgui.common}. - * - * @author Nils Christian Ehmke - */ -package kieker.webgui.common.util; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java index bf55230f..4c5702e6 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IProjectDAO.java @@ -39,7 +39,7 @@ import org.primefaces.model.UploadedFile; /** * @author Nils Christian Ehmke */ -// FIXME @Transactional doesn't work yet +// FIXME The transactional annotations do not work yet. public interface IProjectDAO { /** diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IUserDAO.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IUserDAO.java index f641af29..b6236f10 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IUserDAO.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/IUserDAO.java @@ -19,32 +19,28 @@ package kieker.webgui.persistence; import java.util.List; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.transaction.annotation.Transactional; import kieker.webgui.domain.User; import kieker.webgui.domain.User.Role; /** + * This is the interface for the data access object(s) which will access for example a database to manage the available users. The methods within this interface are + * only accessible by administrators. Furthermore the methods should be transactional. * * @author Nils Christian Ehmke */ -// FIXME @Transactional doesn't work yet public interface IUserDAO { @PreAuthorize("hasRole('ROLE_ADMIN')") - @Transactional public void addUser(final String username, final String password, final List<Role> roles); @PreAuthorize("hasRole('ROLE_ADMIN')") - @Transactional public void removeUser(final String username); @PreAuthorize("hasRole('ROLE_ADMIN')") - @Transactional public void editUser(final String username, final String password, final Role... roles); @PreAuthorize("hasRole('ROLE_ADMIN')") - @Transactional public List<User> getUsers(); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/DerbyUserDAOImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/DerbyUserDAOImpl.java index f11448d0..9f5ca3df 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/DerbyUserDAOImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/DerbyUserDAOImpl.java @@ -25,9 +25,15 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.sql.DataSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; @@ -39,9 +45,12 @@ import kieker.webgui.persistence.IUserDAO; * * @author Nils Christian Ehmke */ +// FIXME The transactional annotations do not work yet. +@Service public class DerbyUserDAOImpl implements IUserDAO { private static final Log LOG = LogFactory.getLog(DerbyUserDAOImpl.class); + @Autowired private DataSource dataSource; private Connection connection; @@ -54,29 +63,23 @@ public class DerbyUserDAOImpl implements IUserDAO { /** * This method initializes the object.. <b>Do not call this method manually. It will only be accessed by Spring.</b> + * + * @throws SQLException + * If something went wrong during the initialization */ - public void initialize() { - try { - this.connection = this.dataSource.getConnection(); - } catch (final SQLException ex) { - DerbyUserDAOImpl.LOG.error("Could not establish database connection.", ex); - } - } - - public void destroy() { - try { - this.connection.close(); - } catch (final SQLException ex) { - DerbyUserDAOImpl.LOG.error("Could not close database connection.", ex); - } + @PostConstruct + public void initialize() throws SQLException { + this.connection = DataSourceUtils.getConnection(this.dataSource); } - public void setDataSource(final DataSource dataSource) { - this.dataSource = dataSource; + @PreDestroy + public void destroy() throws SQLException { + this.connection.close(); } @Override @PreAuthorize("hasRole('ROLE_ADMIN')") + @Transactional public void addUser(final String username, final String password, final List<Role> roles) { PreparedStatement userCmd = null; PreparedStatement roleCmd = null; @@ -115,6 +118,7 @@ public class DerbyUserDAOImpl implements IUserDAO { @Override @PreAuthorize("hasRole('ROLE_ADMIN')") + @Transactional public void removeUser(final String username) { // TODO Auto-generated method stub @@ -122,12 +126,14 @@ public class DerbyUserDAOImpl implements IUserDAO { @Override @PreAuthorize("hasRole('ROLE_ADMIN')") + @Transactional public void editUser(final String username, final String password, final Role... roles) { // TODO Auto-generated method stub } @Override @PreAuthorize("hasRole('ROLE_ADMIN')") + @Transactional(readOnly = true) public List<User> getUsers() { // FIXME Users without roles final List<User> result = new ArrayList<User>(); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java index f7b39517..84d5ad5c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/FSProjectDAOImpl.java @@ -37,6 +37,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; +import javax.annotation.PostConstruct; + +import org.springframework.stereotype.Service; import org.springframework.util.WeakReferenceMonitor; import org.springframework.util.WeakReferenceMonitor.ReleaseListener; @@ -60,6 +63,7 @@ import org.primefaces.model.UploadedFile; /** * @author Nils Christian Ehmke */ +@Service public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { private static final Log LOG = LogFactory.getLog(FSProjectDAOImpl.class); @@ -87,9 +91,9 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { } /** - * This method initializes the class. Normally this method should be called via the @PostConstruction annotation, but for unknown reason it does only work for - * beans. + * This method initializes the class. */ + @PostConstruct public void initialize() { // Check for our root-directory and create it if necessary final File rootDir = new File(FSProjectDAOImpl.ROOT_DIRECTORY); @@ -580,6 +584,38 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { return this.assembleKaxFile(projectName); } + /* + * (non-Javadoc) + * + * @see org.springframework.util.WeakReferenceMonitor.ReleaseListener#released() + */ + @Override + public void released() { + synchronized (this.classLoaders) { + int open = 0; + + final List<CloseableURLClassLoader> toBeRemoved = new ArrayList<CloseableURLClassLoader>(); + // Run through the class loaders and check which of them can be closed + for (final Entry<CloseableURLClassLoader, WeakReference<Object>> entry : this.classLoaders.entrySet()) { + if (entry.getValue().get() == null) { + toBeRemoved.add(entry.getKey()); + } else { + open++; + } + } + for (final CloseableURLClassLoader classLoader : toBeRemoved) { + try { + classLoader.close(); + this.classLoaders.remove(classLoader); + FSProjectDAOImpl.LOG.info("Closed classloader (" + classLoader + ")"); + } catch (final IOException ex) { + FSProjectDAOImpl.LOG.error("Could not close classloader (" + classLoader + ")"); + } + } + FSProjectDAOImpl.LOG.info(open + " classloaders still open."); + } + } + /** * This helper class is responsible for creating a classloader as a privileged action. This is recommended due to the java security manager. * @@ -614,36 +650,4 @@ public class FSProjectDAOImpl implements IProjectDAO, ReleaseListener { } } - /* - * (non-Javadoc) - * - * @see org.springframework.util.WeakReferenceMonitor.ReleaseListener#released() - */ - @Override - public void released() { - synchronized (this.classLoaders) { - int open = 0; - - final List<CloseableURLClassLoader> toBeRemoved = new ArrayList<CloseableURLClassLoader>(); - // Run through the class loaders and check which of them can be closed - for (final Entry<CloseableURLClassLoader, WeakReference<Object>> entry : this.classLoaders.entrySet()) { - if (entry.getValue().get() == null) { - toBeRemoved.add(entry.getKey()); - } else { - open++; - } - } - for (final CloseableURLClassLoader classLoader : toBeRemoved) { - try { - classLoader.close(); - this.classLoaders.remove(classLoader); - FSProjectDAOImpl.LOG.info("Closed classloader (" + classLoader + ")"); - } catch (final IOException ex) { - FSProjectDAOImpl.LOG.error("Could not close classloader (" + classLoader + ")"); - } - } - FSProjectDAOImpl.LOG.info(open + " classloaders still open."); - } - } - } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/util/CloseableURLClassLoader.java b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/util/CloseableURLClassLoader.java index 0b75d894..8da748bd 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/util/CloseableURLClassLoader.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/persistence/impl/util/CloseableURLClassLoader.java @@ -49,17 +49,17 @@ public class CloseableURLClassLoader extends URLClassLoader implements Closeable final java.lang.reflect.Field ucp = clazz.getDeclaredField("ucp"); ucp.setAccessible(true); - final Object sun_misc_URLClassPath = ucp.get(this); - final java.lang.reflect.Field loaders = sun_misc_URLClassPath.getClass().getDeclaredField("loaders"); + final Object sunMiscURLClassPath = ucp.get(this); + final java.lang.reflect.Field loaders = sunMiscURLClassPath.getClass().getDeclaredField("loaders"); loaders.setAccessible(true); - final Object java_util_Collection = loaders.get(sun_misc_URLClassPath); - for (final Object sun_misc_URLClassPath_JarLoader : ((Collection<?>) java_util_Collection).toArray()) { + final Object javaUtilCollection = loaders.get(sunMiscURLClassPath); + for (final Object sunMiscURLClassPathJarLoader : ((Collection<?>) javaUtilCollection).toArray()) { try { - final java.lang.reflect.Field loader = sun_misc_URLClassPath_JarLoader.getClass().getDeclaredField("jar"); + final java.lang.reflect.Field loader = sunMiscURLClassPathJarLoader.getClass().getDeclaredField("jar"); loader.setAccessible(true); - final Object java_util_jar_JarFile = loader.get(sun_misc_URLClassPath_JarLoader); - ((java.util.jar.JarFile) java_util_jar_JarFile).close(); + final Object javaUtilIarJarFile = loader.get(sunMiscURLClassPathJarLoader); + ((java.util.jar.JarFile) javaUtilIarJarFile).close(); } catch (final Throwable t) { // if we got this far, this is probably not a JAR loader so skip it } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java index 0f81448f..863fa788 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/ProjectServiceImpl.java @@ -22,6 +22,9 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentHashMap; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + import kieker.analysis.AnalysisController.STATE; import kieker.analysis.model.analysisMetaModel.MIDependency; import kieker.analysis.model.analysisMetaModel.MIProject; @@ -48,12 +51,16 @@ import org.primefaces.model.UploadedFile; * * @author Nils Christian Ehmke */ +@Service public final class ProjectServiceImpl implements IProjectService { private final ConcurrentHashMap<String, Object> fileSystemLocks = new ConcurrentHashMap<String, Object>(); private final ConcurrentHashMap<String, Object> analysesLocks = new ConcurrentHashMap<String, Object>(); + @Autowired private ACManager acManager; + @Autowired private IProjectDAO projectDAO; + @Autowired private PluginFinder pluginFinder; /** @@ -63,33 +70,6 @@ public final class ProjectServiceImpl implements IProjectService { // No code necessary. } - /** - * The setter for the property {@link ProjectServiceImplImpl#acManager}. <b>Do not use this method. This property is Spring managed.</b> - * - * @param acManager - */ - public void setAcManager(final ACManager acManager) { - this.acManager = acManager; - } - - /** - * The setter for the property {@link ProjectServiceImplImpl#projectDAO}. <b>Do not use this method. This property is Spring managed.</b> - * - * @param projectDAO - */ - public void setProjectDAO(final IProjectDAO projectDAO) { - this.projectDAO = projectDAO; - } - - /** - * The setter for the property {@link ProjectServiceImplImpl#pluginFinder}. <b>Do not use this method. This property is Spring managed.</b> - * - * @param pluginFinder - */ - public void setPluginFinder(final PluginFinder pluginFinder) { - this.pluginFinder = pluginFinder; - } - @Override public void addProject(final String projectName) throws ProjectAlreadyExistingException, IOException { final Object projectLock = this.getLock(projectName, this.fileSystemLocks); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/UserServiceImpl.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/UserServiceImpl.java index 80bd5e36..d8db0c94 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/UserServiceImpl.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/UserServiceImpl.java @@ -17,7 +17,9 @@ package kieker.webgui.service.impl; import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import kieker.webgui.domain.User; @@ -28,8 +30,10 @@ import kieker.webgui.service.IUserService; /** * @author Nils Christian Ehmke */ +@Service public class UserServiceImpl implements IUserService { + @Autowired private IUserDAO userDAO; public UserServiceImpl() { diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/ACManager.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/ACManager.java index 0471b989..86f5d42d 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/ACManager.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/ACManager.java @@ -19,6 +19,7 @@ package kieker.webgui.service.impl.util; import java.util.concurrent.ConcurrentHashMap; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import kieker.analysis.AnalysisController.STATE; import kieker.webgui.common.exception.AnalysisInitializationException; @@ -33,6 +34,7 @@ import kieker.webgui.persistence.IProjectDAO; * * @author Nils Christian Ehmke */ +@Service public final class ACManager { /** * This list contains the current analysis controllers and their corresponding threads. Not every project does have a controller, but every project can have diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/PluginFinder.java b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/PluginFinder.java index 177c5afb..a5ba59b7 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/PluginFinder.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/service/impl/util/PluginFinder.java @@ -22,6 +22,8 @@ import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; +import org.springframework.stereotype.Service; + import kieker.analysis.plugin.AbstractPlugin; import kieker.analysis.repository.AbstractRepository; import kieker.webgui.common.ClassAndMethodContainer; @@ -31,6 +33,7 @@ import kieker.webgui.common.ClassAndMethodContainer; * * @author Nils Christian Ehmke */ +@Service public final class PluginFinder { /** diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java index 2280c6d7..f21c1e7c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/application/ProjectsBean.java @@ -22,16 +22,21 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import javax.annotation.PostConstruct; import javax.faces.application.FacesMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + import kieker.analysis.model.analysisMetaModel.MIProject; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; -import kieker.webgui.web.beans.view.CurrentProjectOverviewBean; import kieker.webgui.common.exception.ProjectAlreadyExistingException; import kieker.webgui.common.exception.ProjectLoadException; import kieker.webgui.common.exception.ProjectNotExistingException; import kieker.webgui.service.IProjectService; +import kieker.webgui.web.beans.view.CurrentProjectOverviewBean; /** * The {@link ProjectsBean} is a Spring managed bean to manage a list with all application wide available projects. It provides methods to receive this list as well @@ -42,6 +47,8 @@ import kieker.webgui.service.IProjectService; * * @author Nils Christian Ehmke */ +@Component +@Lazy public final class ProjectsBean { private static final Log LOG = LogFactory.getLog(ProjectsBean.class); @@ -49,7 +56,7 @@ public final class ProjectsBean { private static final String DEFAULT_ANALYSIS_STATE = ""; private final List<String> projects = Collections.synchronizedList(new ArrayList<String>()); - + @Autowired private IProjectService projectService; /** @@ -72,6 +79,7 @@ public final class ProjectsBean { /** * This method does some initialization work after construction. <b>Do not call this method. The method is Spring managed.</b> */ + @PostConstruct protected void initialize() { // Load a list with all available projects on the FS this.projects.addAll(this.projectService.listAllProjects()); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/request/NewUserBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/request/NewUserBean.java index 21ae5892..a9e20780 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/request/NewUserBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/request/NewUserBean.java @@ -19,6 +19,9 @@ package kieker.webgui.web.beans.request; import java.util.ArrayList; import java.util.List; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + import kieker.webgui.domain.User.Role; /** @@ -27,6 +30,8 @@ import kieker.webgui.domain.User.Role; * * @author Nils Christian Ehmke */ +@Component +@Scope("request") public class NewUserBean { private List<Role> roles; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/request/StringBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/request/StringBean.java index 6bde06dd..720d2fee 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/request/StringBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/request/StringBean.java @@ -16,6 +16,9 @@ package kieker.webgui.web.beans.request; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + /** * This simple bean can be used to store a string during a request. Furthermore it provides some simple methods to handle strings within the application where a bean * is necessary. <br> @@ -23,6 +26,8 @@ package kieker.webgui.web.beans.request; * * @author Nils Christian Ehmke */ +@Component +@Scope("request") public final class StringBean { private String string; diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/session/UserBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/session/UserBean.java index 94e62188..da3ea02c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/session/UserBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/session/UserBean.java @@ -19,12 +19,16 @@ package kieker.webgui.web.beans.session; import java.io.Serializable; import java.util.Map; +import javax.annotation.PostConstruct; import javax.faces.context.FacesContext; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Component; import kieker.webgui.web.beans.application.GlobalPropertiesBean; @@ -34,6 +38,8 @@ import kieker.webgui.web.beans.application.GlobalPropertiesBean; * * @author Nils Christian Ehmke */ +@Component +@Scope("session") public final class UserBean implements Serializable { private static final long serialVersionUID = 6422563876003638348L; @@ -42,9 +48,7 @@ public final class UserBean implements Serializable { private String gridColor; private int gridSize; - /** - * This property is injected by Spring. - */ + @Autowired private GlobalPropertiesBean globalPropertiesBean; /** @@ -58,6 +62,7 @@ public final class UserBean implements Serializable { * This method initializes the bean. In fact it loads the default values before trying to load the values of the user from their cookies. <b>Do not call this * method. The method is Spring managed.</b> */ + @PostConstruct protected void initialize() { this.loadDefaultValues(); this.loadValuesFromCookies(); diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java index 7edd84ca..57bb009b 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorBean.java @@ -29,6 +29,10 @@ import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.event.ValueChangeEvent; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + import kieker.analysis.model.analysisMetaModel.MIAnalysisMetaModelFactory; import kieker.analysis.model.analysisMetaModel.MIDependency; import kieker.analysis.model.analysisMetaModel.MIDisplay; @@ -49,9 +53,6 @@ import kieker.analysis.plugin.reader.AbstractReaderPlugin; import kieker.analysis.repository.AbstractRepository; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; -import kieker.webgui.web.beans.application.GlobalPropertiesBean; -import kieker.webgui.web.beans.application.ProjectsBean; -import kieker.webgui.web.beans.session.UserBean; import kieker.webgui.common.ClassAndMethodContainer; import kieker.webgui.common.exception.LibraryAlreadyExistingException; import kieker.webgui.common.exception.LibraryLoadException; @@ -59,6 +60,9 @@ import kieker.webgui.common.exception.NewerProjectException; import kieker.webgui.common.exception.ProjectLoadException; import kieker.webgui.common.exception.ProjectNotExistingException; import kieker.webgui.service.IProjectService; +import kieker.webgui.web.beans.application.GlobalPropertiesBean; +import kieker.webgui.web.beans.application.ProjectsBean; +import kieker.webgui.web.beans.session.UserBean; import org.primefaces.context.RequestContext; import org.primefaces.event.FileUploadEvent; @@ -79,6 +83,8 @@ import org.eclipse.emf.ecore.EObject; * * @author Nils Christian Ehmke */ +@Component +@Scope("view") public final class CurrentAnalysisEditorBean { /** * This field contains the log-object for the whole class, which will be used to log all important errors and exceptions which occur. @@ -132,10 +138,15 @@ public final class CurrentAnalysisEditorBean { * This field contains the currently selected component (this can either be a plugin ({@link MIPlugin}) or a repository ({@link MIRepository})). */ private EObject selectedComponent; + @Autowired private IProjectService projectService; + @Autowired private ProjectsBean projectsBean; + @Autowired private CurrentAnalysisEditorGraphBean currentAnalysisEditorGraphBean; + @Autowired private UserBean userBean; + @Autowired private GlobalPropertiesBean globalPropertiesBean; /** @@ -145,63 +156,13 @@ public final class CurrentAnalysisEditorBean { // No code necessary } - /** - * Setter for the attribute {@link CurrentAnalysisEditorBean#projectService}. - * - * @param projectService - * The new value of the attribute. - */ - public void setProjectService(final IProjectService projectService) { - this.projectService = projectService; - } - - /** - * Getter for the attribute {@link CurrentAnalysisEditorBean#currentAnalysisEditorGraphBean}. - * - * @return Delivers the value of the attribute. - */ - public CurrentAnalysisEditorGraphBean getCurrentAnalysisEditorGraphBean() { - return this.currentAnalysisEditorGraphBean; - } - - /** - * Setter for the attribute {@link CurrentAnalysisEditorBean#currentAnalysisEditorGraphBean}. - * - * @param currentAnalysisEditorGraphBean - * The new value of the attribute. - */ - public void setCurrentAnalysisEditorGraphBean(final CurrentAnalysisEditorGraphBean currentAnalysisEditorGraphBean) { - this.currentAnalysisEditorGraphBean = currentAnalysisEditorGraphBean; - } - - /** - * Getter for the attribute {@link CurrentAnalysisEditorBean#projectsBean}. - * - * @return Delivers the value of the attribute. - */ - public ProjectsBean getProjectsBean() { - return this.projectsBean; - } - - /** - * Setter for the attribute {@link CurrentAnalysisEditorBean#projectsBean}. - * - * @param projectsBean - * The new value of the attribute. - */ - public void setProjectsBean(final ProjectsBean projectsBean) { - this.projectsBean = projectsBean; - } - /** * This method delivers the project stored in this bean. * * @return The project for this user. */ - public MIProject getProject() { - synchronized (this) { - return this.project; - } + public synchronized MIProject getProject() { + return this.project; } /** @@ -210,42 +171,38 @@ public final class CurrentAnalysisEditorBean { * @param newName * The name of the project. */ - public void setProjectName(final String newName) { - synchronized (this) { - // Remember the given parameters - this.projectName = newName; - } + public synchronized void setProjectName(final String newName) { + // Remember the given parameters + this.projectName = newName; } /** * This method initializes the bean by using the current project name to load the project. <b>Do not call this method manually. It will only be accessed by * Spring.</b> */ - public void initialize() { - synchronized (this) { - try { - // Make sure that the initialization will only be done for the init request. During all other requests, the method call have to be ignored. - if (!FacesContext.getCurrentInstance().isPostback()) { - // Load the project itself - this.project = this.projectsBean.openProject(this.projectName); - // Remember the current time! This is important for the later comparison of the time stamps. - this.resetTimeStamp(); - // Update the class loader and the specific classes used within various methods in this bean - this.reloadClassLoader(); - this.reloadClassesAndMethods(); - // Add the libraries within the lib-folder to the current model - this.initializeModelLibraries(); - // Load the available readers, filters and repositories - this.initializeToolPalette(); - } - } catch (final ProjectLoadException ex) { - CurrentAnalysisEditorBean.LOG.error("An error occured while loading the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectLoadingException()); - } catch (final NullPointerException ex) { - // This exception can occur, when a property has not been initialized - CurrentAnalysisEditorBean.LOG.error("An error occured while loading the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectLoadingException()); + public synchronized void initialize() { + try { + // Make sure that the initialization will only be done for the init request. During all other requests, the method call have to be ignored. + if (!FacesContext.getCurrentInstance().isPostback()) { + // Load the project itself + this.project = this.projectsBean.openProject(this.projectName); + // Remember the current time! This is important for the later comparison of the time stamps. + this.resetTimeStamp(); + // Update the class loader and the specific classes used within various methods in this bean + this.reloadClassLoader(); + this.reloadClassesAndMethods(); + // Add the libraries within the lib-folder to the current model + this.initializeModelLibraries(); + // Load the available readers, filters and repositories + this.initializeToolPalette(); } + } catch (final ProjectLoadException ex) { + CurrentAnalysisEditorBean.LOG.error("An error occured while loading the project.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectLoadingException()); + } catch (final NullPointerException ex) { + // This exception can occur, when a property has not been initialized + CurrentAnalysisEditorBean.LOG.error("An error occured while loading the project.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectLoadingException()); } } @@ -255,10 +212,8 @@ public final class CurrentAnalysisEditorBean { * @throws ProjectLoadException * If one or more of the classes and methods necessary for {@link ClassAndMethodContainer} could not be found using the given class loader. */ - private void reloadClassesAndMethods() throws ProjectLoadException { - synchronized (this) { - this.classAndMethodContainer = new ClassAndMethodContainer(this.classLoader); - } + private synchronized void reloadClassesAndMethods() throws ProjectLoadException { + this.classAndMethodContainer = new ClassAndMethodContainer(this.classLoader); } /** @@ -267,24 +222,22 @@ public final class CurrentAnalysisEditorBean { * @throws ProjectLoadException * If something went wrong during the loading of the libraries. */ - private void initializeToolPalette() throws ProjectLoadException { - synchronized (this) { - try { - // Clean our tool palette - this.availableFilters.clear(); - this.availableReaders.clear(); - this.availableRepositories.clear(); - - // Run through all libraries and add their content to our lists - for (final MIDependency lib : this.project.getDependencies()) { - this.addContentsToToolPalette(lib); - } - // Run also through the kieker library - this.addKiekerContentsToToolPalette(); - } catch (final LibraryLoadException ex) { - CurrentAnalysisEditorBean.LOG.error("A library could not be loaded correctly.", ex); - throw new ProjectLoadException("A library could not be loaded correctly.", ex); + private synchronized void initializeToolPalette() throws ProjectLoadException { + try { + // Clean our tool palette + this.availableFilters.clear(); + this.availableReaders.clear(); + this.availableRepositories.clear(); + + // Run through all libraries and add their content to our lists + for (final MIDependency lib : this.project.getDependencies()) { + this.addContentsToToolPalette(lib); } + // Run also through the kieker library + this.addKiekerContentsToToolPalette(); + } catch (final LibraryLoadException ex) { + CurrentAnalysisEditorBean.LOG.error("A library could not be loaded correctly.", ex); + throw new ProjectLoadException("A library could not be loaded correctly.", ex); } } @@ -296,7 +249,7 @@ public final class CurrentAnalysisEditorBean { * @throws LibraryLoadException * If something went wrong during the loading of the library. */ - private void addContentsToToolPalette(final MIDependency dependency) throws LibraryLoadException { + private synchronized void addContentsToToolPalette(final MIDependency dependency) throws LibraryLoadException { this.addContentsToToolPalette( this.projectService.getAllPluginsWithinLib(dependency, this.projectName, this.classLoader, this.classAndMethodContainer), this.projectService.getAllRepositoriesWithinLib(dependency, this.projectName, this.classLoader, this.classAndMethodContainer)); @@ -308,7 +261,7 @@ public final class CurrentAnalysisEditorBean { * @throws LibraryLoadException * If something went wrong during the loading of the library. */ - private void addKiekerContentsToToolPalette() throws LibraryLoadException { + private synchronized void addKiekerContentsToToolPalette() throws LibraryLoadException { this.addContentsToToolPalette( this.projectService.getAllPluginsWithinKiekerLib(this.classLoader, this.classAndMethodContainer), this.projectService.getAllRepositoriesWithinKiekerLib(this.classLoader, this.classAndMethodContainer)); @@ -323,37 +276,35 @@ public final class CurrentAnalysisEditorBean { * The available repositories. */ @SuppressWarnings("unchecked") - private void addContentsToToolPalette(final List<Class<AbstractPlugin>> plugins, final List<Class<AbstractRepository>> repositories) { - synchronized (this) { - // Now run through the available classes and add all non-abstract classes to our lists. - for (final Class<AbstractRepository> repository : repositories) { - if (!Modifier.isAbstract(repository.getModifiers())) { - // Make also sure that the current repository is not "programmaticOnly" - final Annotation annotationRepository = repository.getAnnotation(this.classAndMethodContainer.getRepositoryAnnotationClass()); - final boolean programmaticOnly = (Boolean) ClassAndMethodContainer.invokeMethod( - this.classAndMethodContainer.getRepositoryProgrammaticOnlyMethod(), - annotationRepository, false); - if (!programmaticOnly) { - this.availableRepositories.add(repository); - } + private synchronized void addContentsToToolPalette(final List<Class<AbstractPlugin>> plugins, final List<Class<AbstractRepository>> repositories) { + // Now run through the available classes and add all non-abstract classes to our lists. + for (final Class<AbstractRepository> repository : repositories) { + if (!Modifier.isAbstract(repository.getModifiers())) { + // Make also sure that the current repository is not "programmaticOnly" + final Annotation annotationRepository = repository.getAnnotation(this.classAndMethodContainer.getRepositoryAnnotationClass()); + final boolean programmaticOnly = (Boolean) ClassAndMethodContainer.invokeMethod( + this.classAndMethodContainer.getRepositoryProgrammaticOnlyMethod(), + annotationRepository, false); + if (!programmaticOnly) { + this.availableRepositories.add(repository); } } + } - for (final Class<?> plugin : plugins) { - // Make sure that the current plugin is neither abstract nor "programmaticOnly" - final Annotation annotationPlugin = plugin.getAnnotation(this.classAndMethodContainer.getPluginAnnotationClass()); - final boolean programmaticOnly = (Boolean) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getPluginProgrammaticOnlyMethod(), - annotationPlugin, false); - final boolean isAbstract = Modifier.isAbstract(plugin.getModifiers()); - - if (!isAbstract && !programmaticOnly) { - // The following cast results in the unchecked-cast-warnings, but we know that the cast should be correct. - if (this.classAndMethodContainer.getAbstractFilterPluginClass().isAssignableFrom(plugin)) { - this.availableFilters.add((Class<AbstractFilterPlugin>) plugin); - } else { - if (this.classAndMethodContainer.getAbstractReaderPluginClass().isAssignableFrom(plugin)) { - this.availableReaders.add((Class<AbstractReaderPlugin>) plugin); - } + for (final Class<?> plugin : plugins) { + // Make sure that the current plugin is neither abstract nor "programmaticOnly" + final Annotation annotationPlugin = plugin.getAnnotation(this.classAndMethodContainer.getPluginAnnotationClass()); + final boolean programmaticOnly = (Boolean) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getPluginProgrammaticOnlyMethod(), + annotationPlugin, false); + final boolean isAbstract = Modifier.isAbstract(plugin.getModifiers()); + + if (!isAbstract && !programmaticOnly) { + // The following cast results in the unchecked-cast-warnings, but we know that the cast should be correct. + if (this.classAndMethodContainer.getAbstractFilterPluginClass().isAssignableFrom(plugin)) { + this.availableFilters.add((Class<AbstractFilterPlugin>) plugin); + } else { + if (this.classAndMethodContainer.getAbstractReaderPluginClass().isAssignableFrom(plugin)) { + this.availableReaders.add((Class<AbstractReaderPlugin>) plugin); } } } @@ -366,22 +317,20 @@ public final class CurrentAnalysisEditorBean { * @throws ProjectLoadException * If something went wrong during the loading of the libraries. */ - private void initializeModelLibraries() throws ProjectLoadException { - synchronized (this) { - try { - final List<String> libs = this.projectService.listAllLibraries(this.projectName); - // Add them, but remove all existing dependencies so far to avoid double entries. This also makes sure that the model - after it has been opened - - // points - // just to valid dependencies (and to all of them). - this.project.getDependencies().clear(); - for (final String lib : libs) { - final MIDependency dep = this.factory.createDependency(); - dep.setFilePath(lib); - this.project.getDependencies().add(dep); - } - } catch (final ProjectNotExistingException ex) { - throw new ProjectLoadException("The project does not exist.", ex); + private synchronized void initializeModelLibraries() throws ProjectLoadException { + try { + final List<String> libs = this.projectService.listAllLibraries(this.projectName); + // Add them, but remove all existing dependencies so far to avoid double entries. This also makes sure that the model - after it has been opened - + // points + // just to valid dependencies (and to all of them). + this.project.getDependencies().clear(); + for (final String lib : libs) { + final MIDependency dep = this.factory.createDependency(); + dep.setFilePath(lib); + this.project.getDependencies().add(dep); } + } catch (final ProjectNotExistingException ex) { + throw new ProjectLoadException("The project does not exist.", ex); } } @@ -392,27 +341,23 @@ public final class CurrentAnalysisEditorBean { * @throws ProjectLoadException * If something went wrong. */ - private void reloadClassLoader() throws ProjectLoadException { - synchronized (this) { - try { - this.classLoader = this.projectService.getClassLoader(this.projectName, this); // NOPMD (ClassLoader) - } catch (final NullPointerException ex) { - throw new ProjectLoadException("Invalid class loader.", ex); - } catch (final IOException ex) { - throw new ProjectLoadException("Could not load classes.", ex); - } catch (final ProjectNotExistingException ex) { - throw new ProjectLoadException("Project does not exist.", ex); - } + private synchronized void reloadClassLoader() throws ProjectLoadException { + try { + this.classLoader = this.projectService.getClassLoader(this.projectName, this); // NOPMD (ClassLoader) + } catch (final NullPointerException ex) { + throw new ProjectLoadException("Invalid class loader.", ex); + } catch (final IOException ex) { + throw new ProjectLoadException("Could not load classes.", ex); + } catch (final ProjectNotExistingException ex) { + throw new ProjectLoadException("Project does not exist.", ex); } } /** * This method sets the time stamp to the current system time. */ - public void resetTimeStamp() { - synchronized (this) { - this.timeStamp = System.currentTimeMillis(); - } + public synchronized void resetTimeStamp() { + this.timeStamp = System.currentTimeMillis(); } /** @@ -420,10 +365,8 @@ public final class CurrentAnalysisEditorBean { * * @return The project name for this user. */ - public String getProjectName() { - synchronized (this) { - return this.projectName; - } + public synchronized String getProjectName() { + return this.projectName; } /** @@ -431,10 +374,8 @@ public final class CurrentAnalysisEditorBean { * * @return The time stamp for this user. */ - public long getTimeStamp() { - synchronized (this) { - return this.timeStamp; - } + public synchronized long getTimeStamp() { + return this.timeStamp; } /** @@ -445,7 +386,7 @@ public final class CurrentAnalysisEditorBean { * The class whose description should be extracted. * @return The description for the class or a substitute if none is available. This is in either case human readable. */ - public String getDescription(final Class<?> clazz) { + public synchronized String getDescription(final Class<?> clazz) { // Get the two potential annotations final Annotation annotationPlugin = clazz.getAnnotation(this.classAndMethodContainer.getPluginAnnotationClass()); final Annotation annotationRepository = clazz.getAnnotation(this.classAndMethodContainer.getRepositoryAnnotationClass()); @@ -473,7 +414,7 @@ public final class CurrentAnalysisEditorBean { * The class whose dependencies should be extracted. * @return The dependencies for the class or a substitute if none is available. This is in either case human readable. */ - public String getDependencies(final Class<?> clazz) { + public synchronized String getDependencies(final Class<?> clazz) { // Get the two potential annotations final Annotation annotationPlugin = clazz.getAnnotation(this.classAndMethodContainer.getPluginAnnotationClass()); final Annotation annotationRepository = clazz.getAnnotation(this.classAndMethodContainer.getRepositoryAnnotationClass()); @@ -503,7 +444,7 @@ public final class CurrentAnalysisEditorBean { * The name of the property in question. * @return The description of the property. */ - public String getDescription(final EObject component, final String propertyName) { + public synchronized String getDescription(final EObject component, final String propertyName) { try { final String className; if (component instanceof MIPlugin) { @@ -539,7 +480,7 @@ public final class CurrentAnalysisEditorBean { * The class whose properties will be delivered. * @return A list of properties. It contains instances of {@link Property} - but those from the project class loader. */ - public List<Annotation> getProperties(final Class<?> clazz) { + public synchronized List<Annotation> getProperties(final Class<?> clazz) { // Get the two potential annotations final Annotation annotationPlugin = clazz.getAnnotation(this.classAndMethodContainer.getPluginAnnotationClass()); final Annotation annotationRepository = clazz.getAnnotation(this.classAndMethodContainer.getRepositoryAnnotationClass()); @@ -570,7 +511,7 @@ public final class CurrentAnalysisEditorBean { * The class to be analyzed. * @return A list containing the available input ports. */ - public List<Annotation> getInputPorts(final Class<?> clazz) { + public synchronized List<Annotation> getInputPorts(final Class<?> clazz) { final List<Annotation> result = new ArrayList<Annotation>(); for (final Method method : clazz.getMethods()) { @@ -592,7 +533,7 @@ public final class CurrentAnalysisEditorBean { * The class to be analyzed. * @return A list containing the available output ports. */ - public List<Annotation> getOutputPorts(final Class<?> clazz) { + public synchronized List<Annotation> getOutputPorts(final Class<?> clazz) { final List<Annotation> result = new ArrayList<Annotation>(); // Get the potential annotation @@ -616,7 +557,7 @@ public final class CurrentAnalysisEditorBean { * The class to be analyzed. * @return A list containing the available repository ports. */ - public List<Annotation> getRepositoryPorts(final Class<?> clazz) { + public synchronized List<Annotation> getRepositoryPorts(final Class<?> clazz) { final List<Annotation> result = new ArrayList<Annotation>(); // Get the potential annotation @@ -640,7 +581,7 @@ public final class CurrentAnalysisEditorBean { * The class to be analyzed. * @return A list containing the available displays. */ - public List<Annotation> getDisplays(final Class<?> clazz) { + public synchronized List<Annotation> getDisplays(final Class<?> clazz) { final List<Annotation> result = new ArrayList<Annotation>(); for (final Method method : clazz.getMethods()) { @@ -661,21 +602,19 @@ public final class CurrentAnalysisEditorBean { * @param event * The upload event. */ - public void handleFileUpload(final FileUploadEvent event) { + public synchronized void handleFileUpload(final FileUploadEvent event) { // Get the file from the event final UploadedFile file = event.getFile(); try { // Use the file system manager to upload the new file final MIDependency lib; - synchronized (this) { - this.projectService.uploadLibrary(file, this.projectName); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgLibraryUploaded()); - // As it seem to have worked, we can add the library to our model. - lib = this.factory.createDependency(); - lib.setFilePath(file.getFileName()); - this.project.getDependencies().add(lib); - } + this.projectService.uploadLibrary(file, this.projectName); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgLibraryUploaded()); + // As it seem to have worked, we can add the library to our model. + lib = this.factory.createDependency(); + lib.setFilePath(file.getFileName()); + this.project.getDependencies().add(lib); // Update our class loader and the available plugins & repositories this.reloadClassLoader(); this.reloadClassesAndMethods(); @@ -706,21 +645,19 @@ public final class CurrentAnalysisEditorBean { * * @return The available libraries. */ - public List<String> getLibraries() { - synchronized (this) { - try { - final List<String> result = this.projectService.listAllLibraries(this.projectName); - result.add(0, "Kieker"); - - return result; - } catch (final ProjectNotExistingException ex) { - CurrentAnalysisEditorBean.LOG.error("The project does not exist.", ex); - return new ArrayList<String>(); - } catch (final NullPointerException ex) { - // This exception occurs when a property has not been initialized correctly. - CurrentAnalysisEditorBean.LOG.error("A null pointer exception occured.", ex); - return new ArrayList<String>(); - } + public synchronized List<String> getLibraries() { + try { + final List<String> result = this.projectService.listAllLibraries(this.projectName); + result.add(0, "Kieker"); + + return result; + } catch (final ProjectNotExistingException ex) { + CurrentAnalysisEditorBean.LOG.error("The project does not exist.", ex); + return new ArrayList<String>(); + } catch (final NullPointerException ex) { + // This exception occurs when a property has not been initialized correctly. + CurrentAnalysisEditorBean.LOG.error("A null pointer exception occured.", ex); + return new ArrayList<String>(); } } @@ -729,7 +666,7 @@ public final class CurrentAnalysisEditorBean { * * @return A list with all readers. */ - public final List<Class<AbstractReaderPlugin>> getAvailableReaders() { + public synchronized List<Class<AbstractReaderPlugin>> getAvailableReaders() { return this.availableReaders; } @@ -738,7 +675,7 @@ public final class CurrentAnalysisEditorBean { * * @return A list with all filter. */ - public final List<Class<AbstractFilterPlugin>> getAvailableFilters() { + public synchronized List<Class<AbstractFilterPlugin>> getAvailableFilters() { return this.availableFilters; } @@ -747,7 +684,7 @@ public final class CurrentAnalysisEditorBean { * * @return A list with all repositories. */ - public final List<Class<AbstractRepository>> getAvailableRepositories() { + public synchronized List<Class<AbstractRepository>> getAvailableRepositories() { return this.availableRepositories; } @@ -757,25 +694,23 @@ public final class CurrentAnalysisEditorBean { * @param overwriteNewerProject * This flag determines whether a newer project should be overwritten. */ - public void saveProject(final boolean overwriteNewerProject) { - synchronized (this) { - try { - this.projectService.saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgProjectSaved()); - // Update the time stamp! - this.resetTimeStamp(); - } catch (final IOException ex) { - CurrentAnalysisEditorBean.LOG.error("An error occured while saving the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectSavingException()); - } catch (final NewerProjectException ex) { - CurrentAnalysisEditorBean.LOG.info("The project has been modified externally in the meanwhile.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_WARN, this.globalPropertiesBean.getMsgProjectModified()); - // Give the user the possibility to force-save the project - RequestContext.getCurrentInstance().execute("forceSaveDlg.show()"); - } catch (final ProjectNotExistingException ex) { - CurrentAnalysisEditorBean.LOG.error("The project does not exist.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectNotExistingException()); - } + public synchronized void saveProject(final boolean overwriteNewerProject) { + try { + this.projectService.saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgProjectSaved()); + // Update the time stamp! + this.resetTimeStamp(); + } catch (final IOException ex) { + CurrentAnalysisEditorBean.LOG.error("An error occured while saving the project.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectSavingException()); + } catch (final NewerProjectException ex) { + CurrentAnalysisEditorBean.LOG.info("The project has been modified externally in the meanwhile.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_WARN, this.globalPropertiesBean.getMsgProjectModified()); + // Give the user the possibility to force-save the project + RequestContext.getCurrentInstance().execute("forceSaveDlg.show()"); + } catch (final ProjectNotExistingException ex) { + CurrentAnalysisEditorBean.LOG.error("The project does not exist.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgProjectNotExistingException()); } } @@ -788,15 +723,13 @@ public final class CurrentAnalysisEditorBean { * @param plugin * The plugin to be filled. */ - private void fillDisplays(final Class<AbstractPlugin> clazz, final MIPlugin plugin) { - synchronized (this) { - // Get the displays and convert them into model instances - final List<Annotation> displays = this.getDisplays(clazz); - for (final Annotation display : displays) { - final MIDisplay mDisplay = this.factory.createDisplay(); - mDisplay.setName((String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getDisplayNameMethod(), display, "N/A")); - plugin.getDisplays().add(mDisplay); - } + private synchronized void fillDisplays(final Class<AbstractPlugin> clazz, final MIPlugin plugin) { + // Get the displays and convert them into model instances + final List<Annotation> displays = this.getDisplays(clazz); + for (final Annotation display : displays) { + final MIDisplay mDisplay = this.factory.createDisplay(); + mDisplay.setName((String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getDisplayNameMethod(), display, "N/A")); + plugin.getDisplays().add(mDisplay); } } @@ -809,36 +742,34 @@ public final class CurrentAnalysisEditorBean { * @param plugin * The plugin to be filled. */ - private void fillPorts(final Class<AbstractPlugin> clazz, final MIPlugin plugin) { - synchronized (this) { - // Get the ports - final List<Annotation> inputPorts = this.getInputPorts(clazz); - final List<Annotation> outputPorts = this.getOutputPorts(clazz); - final List<Annotation> repositoryPorts = this.getRepositoryPorts(clazz); - - // Add input ports - if (plugin instanceof MIFilter) { - for (final Annotation inputPort : inputPorts) { - final MIInputPort mInputPort = this.factory.createInputPort(); - mInputPort.setName((String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getInputPortNameMethod(), inputPort, "N/A")); - mInputPort.setParent((MIFilter) plugin); - } + private synchronized void fillPorts(final Class<AbstractPlugin> clazz, final MIPlugin plugin) { + // Get the ports + final List<Annotation> inputPorts = this.getInputPorts(clazz); + final List<Annotation> outputPorts = this.getOutputPorts(clazz); + final List<Annotation> repositoryPorts = this.getRepositoryPorts(clazz); + + // Add input ports + if (plugin instanceof MIFilter) { + for (final Annotation inputPort : inputPorts) { + final MIInputPort mInputPort = this.factory.createInputPort(); + mInputPort.setName((String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getInputPortNameMethod(), inputPort, "N/A")); + mInputPort.setParent((MIFilter) plugin); } + } - // Add output ports. - for (final Annotation outputPort : outputPorts) { - final MIOutputPort mOutputPort = this.factory.createOutputPort(); - mOutputPort.setName((String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getOutputPortNameMethod(), outputPort, "N/A")); - mOutputPort.setParent(plugin); - } + // Add output ports. + for (final Annotation outputPort : outputPorts) { + final MIOutputPort mOutputPort = this.factory.createOutputPort(); + mOutputPort.setName((String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getOutputPortNameMethod(), outputPort, "N/A")); + mOutputPort.setParent(plugin); + } - // Add repository ports. - for (final Annotation repositoryPort : repositoryPorts) { - final MIRepositoryConnector mConnector = this.factory.createRepositoryConnector(); - mConnector.setName((String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getRepositoryPortNameMethod(), repositoryPort, - "N/A")); - plugin.getRepositories().add(mConnector); - } + // Add repository ports. + for (final Annotation repositoryPort : repositoryPorts) { + final MIRepositoryConnector mConnector = this.factory.createRepositoryConnector(); + mConnector.setName((String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getRepositoryPortNameMethod(), repositoryPort, + "N/A")); + plugin.getRepositories().add(mConnector); } } @@ -851,7 +782,7 @@ public final class CurrentAnalysisEditorBean { * @param component * The component to be filled. */ - private void fillProperties(final Class<?> clazz, final EObject component) { + private synchronized void fillProperties(final Class<?> clazz, final EObject component) { // Get the default configuration and use it to initialize the model repository final List<Annotation> properties = this.getProperties(clazz); @@ -876,7 +807,7 @@ public final class CurrentAnalysisEditorBean { * @param clazz * The class of the repository to be added. */ - public void addRepository(final Class<AbstractRepository> clazz) { + public synchronized void addRepository(final Class<AbstractRepository> clazz) { try { // Create a new instance for the model final MIRepository repository = this.factory.createRepository(); @@ -884,12 +815,10 @@ public final class CurrentAnalysisEditorBean { repository.setName(clazz.getSimpleName()); this.fillProperties(clazz, repository); - synchronized (this) { - // Add it to the project - and to the graph - this.project.getRepositories().add(repository); - this.currentAnalysisEditorGraphBean.addRepository(repository); - this.currentAnalysisEditorGraphBean.refreshGraph(); - } + // Add it to the project - and to the graph + this.project.getRepositories().add(repository); + this.currentAnalysisEditorGraphBean.addRepository(repository); + this.currentAnalysisEditorGraphBean.refreshGraph(); } catch (final NoClassDefFoundError ex) { // This exception can occur if (for example) a class is missing GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgRepositoryCreationException()); @@ -903,7 +832,7 @@ public final class CurrentAnalysisEditorBean { * @param clazz * The class of the plugin to be added. This can be both, a filter or a reader. */ - public void addPlugin(final Class<AbstractPlugin> clazz) { + public synchronized void addPlugin(final Class<AbstractPlugin> clazz) { try { // Create a new instance for the model final MIPlugin plugin; @@ -919,18 +848,16 @@ public final class CurrentAnalysisEditorBean { this.fillPorts(clazz, plugin); this.fillDisplays(clazz, plugin); - synchronized (this) { - // Add it to the project - this.project.getPlugins().add(plugin); + // Add it to the project + this.project.getPlugins().add(plugin); - // Add the element to the graph - if (plugin instanceof MIReader) { - this.currentAnalysisEditorGraphBean.addReader((MIReader) plugin); - } else { - this.currentAnalysisEditorGraphBean.addFilter((MIFilter) plugin); - } - this.currentAnalysisEditorGraphBean.refreshGraph(); + // Add the element to the graph + if (plugin instanceof MIReader) { + this.currentAnalysisEditorGraphBean.addReader((MIReader) plugin); + } else { + this.currentAnalysisEditorGraphBean.addFilter((MIFilter) plugin); } + this.currentAnalysisEditorGraphBean.refreshGraph(); } catch (final NoClassDefFoundError ex) { // This exception can occur if (for example) a class is missing GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, this.globalPropertiesBean.getMsgPluginCreationException()); @@ -943,10 +870,8 @@ public final class CurrentAnalysisEditorBean { * * @return The currently selected plugin or repository. */ - public EObject getSelectedPlugin() { - synchronized (this) { - return this.selectedComponent; - } + public synchronized EObject getSelectedPlugin() { + return this.selectedComponent; } /** @@ -956,23 +881,21 @@ public final class CurrentAnalysisEditorBean { * @return A list with all properties of the plugin plus the name- and class-properties. If no plugin is selected, the list of the selected repository is * delivered. */ - public List<Object> getAdvancedPluginProperties() { - synchronized (this) { - final List<Object> result = new ArrayList<Object>(); + public synchronized List<Object> getAdvancedPluginProperties() { + final List<Object> result = new ArrayList<Object>(); - // Add the properties as strings - result.add("Name"); - result.add("ClassName"); + // Add the properties as strings + result.add("Name"); + result.add("ClassName"); - // Get the original properties of the plugin - if (this.selectedComponent instanceof MIPlugin) { - result.addAll(((MIPlugin) this.selectedComponent).getProperties()); - } else { - result.addAll(((MIRepository) this.selectedComponent).getProperties()); - } - - return result; + // Get the original properties of the plugin + if (this.selectedComponent instanceof MIPlugin) { + result.addAll(((MIPlugin) this.selectedComponent).getProperties()); + } else { + result.addAll(((MIRepository) this.selectedComponent).getProperties()); } + + return result; } /** @@ -981,19 +904,17 @@ public final class CurrentAnalysisEditorBean { * * @return A list with the available filters. */ - public List<MIPlugin> getFilters() { - synchronized (this) { - final EList<MIPlugin> plugins = this.project.getPlugins(); - final List<MIPlugin> filter = new ArrayList<MIPlugin>(); - - for (final MIPlugin plugin : plugins) { - if (plugin instanceof MIFilter) { - filter.add(plugin); - } - } + public synchronized List<MIPlugin> getFilters() { + final EList<MIPlugin> plugins = this.project.getPlugins(); + final List<MIPlugin> filter = new ArrayList<MIPlugin>(); - return filter; + for (final MIPlugin plugin : plugins) { + if (plugin instanceof MIFilter) { + filter.add(plugin); + } } + + return filter; } /** @@ -1001,10 +922,8 @@ public final class CurrentAnalysisEditorBean { * * @return A list with all repositories within the model. */ - public EList<MIRepository> getRepositories() { - synchronized (this) { - return this.project.getRepositories(); - } + public synchronized EList<MIRepository> getRepositories() { + return this.project.getRepositories(); } /** @@ -1012,37 +931,25 @@ public final class CurrentAnalysisEditorBean { * * @return The name of the plugin/repository. */ - public String getCurrentPluginName() { - synchronized (this) { - if (this.selectedComponent != null) { - if (this.selectedComponent instanceof MIPlugin) { - return ((MIPlugin) this.selectedComponent).getName(); - } else { - return ((MIRepository) this.selectedComponent).getName(); - } + public synchronized String getCurrentPluginName() { + if (this.selectedComponent != null) { + if (this.selectedComponent instanceof MIPlugin) { + return ((MIPlugin) this.selectedComponent).getName(); } else { - return ""; + return ((MIRepository) this.selectedComponent).getName(); } + } else { + return ""; } } - /** - * The setter for the property {@link CurrentAnalysisEditorBean#userBean}. - * - * @param userBean - * The new value of the property. - */ - public void setUserBean(final UserBean userBean) { - this.userBean = userBean; - } - /** * This method should be called if the grid color has been modified. * * @param event * The change event. */ - public void gridColorListener(final ValueChangeEvent event) { + public synchronized void gridColorListener(final ValueChangeEvent event) { this.currentAnalysisEditorGraphBean.setGridColor((String) event.getNewValue()); } @@ -1052,7 +959,7 @@ public final class CurrentAnalysisEditorBean { * @param event * The change event. */ - public void gridSizeListener(final ValueChangeEvent event) { + public synchronized void gridSizeListener(final ValueChangeEvent event) { this.currentAnalysisEditorGraphBean.setGridSize((Integer) event.getNewValue()); } @@ -1060,7 +967,7 @@ public final class CurrentAnalysisEditorBean { * This method initializes the modified jit-graph by delivering the necessary javascript commands to the client. It prints all current existing plugins, * repositories and their connections. All further components will be added mostly by other methods. */ - public void initializeGraph() { + public synchronized void initializeGraph() { // Make sure that the currentAnalysisEditorGraphBean knows "this" as well. this.currentAnalysisEditorGraphBean.setCurrentAnalysisEditorBean(this); @@ -1116,10 +1023,8 @@ public final class CurrentAnalysisEditorBean { * @param node * The new node to be selected. */ - public void nodeSelected(final EObject node) { - synchronized (this) { - this.selectedComponent = node; - } + public synchronized void nodeSelected(final EObject node) { + this.selectedComponent = node; } /** @@ -1128,53 +1033,41 @@ public final class CurrentAnalysisEditorBean { * @param node * The new node to be removed. */ - public void nodeRemoved(final EObject node) { - synchronized (this) { - // Remove the component from the project - if (node instanceof MIPlugin) { - this.project.getPlugins().remove(node); - - // Remove the corresponding connections - final List<MIInputPort> toBeRemoved = new ArrayList<MIInputPort>(); - for (final MIPlugin plugin : this.project.getPlugins()) { - for (final MIOutputPort oPort : plugin.getOutputPorts()) { - toBeRemoved.clear(); - for (final MIInputPort iPort : oPort.getSubscribers()) { - if (iPort.getParent() == node) { - toBeRemoved.add(iPort); - } + public synchronized void nodeRemoved(final EObject node) { + // Remove the component from the project + if (node instanceof MIPlugin) { + this.project.getPlugins().remove(node); + + // Remove the corresponding connections + final List<MIInputPort> toBeRemoved = new ArrayList<MIInputPort>(); + for (final MIPlugin plugin : this.project.getPlugins()) { + for (final MIOutputPort oPort : plugin.getOutputPorts()) { + toBeRemoved.clear(); + for (final MIInputPort iPort : oPort.getSubscribers()) { + if (iPort.getParent() == node) { + toBeRemoved.add(iPort); } - oPort.getSubscribers().removeAll(toBeRemoved); } + oPort.getSubscribers().removeAll(toBeRemoved); } - } else { - this.project.getRepositories().remove(node); + } + } else { + this.project.getRepositories().remove(node); - // Remove the corresponding connections - for (final MIPlugin plugin : this.project.getPlugins()) { - for (final MIRepositoryConnector repoConn : plugin.getRepositories()) { - if (repoConn.getRepository() == node) { - repoConn.setRepository(null); - } + // Remove the corresponding connections + for (final MIPlugin plugin : this.project.getPlugins()) { + for (final MIRepositoryConnector repoConn : plugin.getRepositories()) { + if (repoConn.getRepository() == node) { + repoConn.setRepository(null); } } } - - // Unselect the currently selected node if it is the one which has just been removed - if (this.selectedComponent == node) { - this.selectedComponent = null; // NOPMD - } } - } - /** - * The setter for the property {@link CurrentAnalysisEditorBean#globalPropertiesBean}. - * - * @param globalPropertiesBean - * The new value of the property. - */ - public void setGlobalPropertiesBean(final GlobalPropertiesBean globalPropertiesBean) { - this.globalPropertiesBean = globalPropertiesBean; + // Unselect the currently selected node if it is the one which has just been removed + if (this.selectedComponent == node) { + this.selectedComponent = null; // NOPMD + } } /** @@ -1185,7 +1078,7 @@ public final class CurrentAnalysisEditorBean { * @param targetPort * The target port. */ - public void edgeCreated(final MIOutputPort sourcePort, final MIInputPort targetPort) { + public synchronized void edgeCreated(final MIOutputPort sourcePort, final MIInputPort targetPort) { sourcePort.getSubscribers().add(targetPort); } @@ -1197,7 +1090,7 @@ public final class CurrentAnalysisEditorBean { * @param targetPort * The target port. */ - public void edgeRemoved(final MIOutputPort sourcePort, final MIInputPort targetPort) { + public synchronized void edgeRemoved(final MIOutputPort sourcePort, final MIInputPort targetPort) { sourcePort.getSubscribers().remove(targetPort); } @@ -1209,7 +1102,7 @@ public final class CurrentAnalysisEditorBean { * @param target * The target repository. */ - public void edgeCreated(final MIRepositoryConnector sourcePort, final MIRepository target) { + public synchronized void edgeCreated(final MIRepositoryConnector sourcePort, final MIRepository target) { sourcePort.setRepository(target); } @@ -1221,7 +1114,7 @@ public final class CurrentAnalysisEditorBean { * @param target * The target repository. */ - public void edgeRemoved(final MIRepositoryConnector sourcePort, final MIRepository target) { + public synchronized void edgeRemoved(final MIRepositoryConnector sourcePort, final MIRepository target) { sourcePort.setRepository(null); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java index e8a24cfd..5140ac41 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentAnalysisEditorGraphBean.java @@ -20,6 +20,9 @@ import java.util.Map; import javax.faces.context.FacesContext; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + import kieker.analysis.model.analysisMetaModel.MIFilter; import kieker.analysis.model.analysisMetaModel.MIInputPort; import kieker.analysis.model.analysisMetaModel.MIOutputPort; @@ -45,6 +48,8 @@ import org.eclipse.emf.ecore.EObject; * * @author Nils Christian Ehmke */ +@Component +@Scope("view") public final class CurrentAnalysisEditorGraphBean { /** * This is the log for errors, exceptions etc. @@ -163,7 +168,7 @@ public final class CurrentAnalysisEditorGraphBean { /** * Declares the the graph variable. */ - public void declareGraph() { + public synchronized void declareGraph() { RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_CREATE_GRAPH_VAR); RequestContext.getCurrentInstance().execute("graph.setNodeIcon('Filter', '../img/graphIcons/FilterIcon.png');"); RequestContext.getCurrentInstance().execute("graph.setNodeIcon('Reader', '../img/graphIcons/ReaderIcon.png');"); @@ -173,7 +178,7 @@ public final class CurrentAnalysisEditorGraphBean { /** * Initializes the listeners for the graph. */ - public void initListeners() { + public synchronized void initListeners() { RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_CLICK_LISTENER); RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_REMOVE_NODE_LISTENER); RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_CREATE_EDGE_LISTENER); @@ -183,14 +188,14 @@ public final class CurrentAnalysisEditorGraphBean { /** * Adds the edge constraints to the graph. */ - public void addEdgeConstraints() { + public synchronized void addEdgeConstraints() { RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_EDGE_CONSTRAINTS); } /** * Refreshes the graph after changes have been made. */ - public void refreshGraph() { + public synchronized void refreshGraph() { RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_REFRESH_GRAPH); } @@ -200,7 +205,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param filter * The filter which should be added to the graph. */ - public void addFilter(final MIFilter filter) { + public synchronized void addFilter(final MIFilter filter) { RequestContext.getCurrentInstance().execute( String.format(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_FILTER, 0, 0, this.assembleGraphString(filter), this.assembleGraphRepositoryPortString(filter.getRepositories()), this.assembleGraphInputPortString(filter), @@ -213,7 +218,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param reader * The reader which should be added to the graph. */ - public void addReader(final MIReader reader) { + public synchronized void addReader(final MIReader reader) { RequestContext.getCurrentInstance().execute(String.format(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_READER, 0, 0, this.assembleGraphString(reader), this.assembleGraphRepositoryPortString(reader.getRepositories()), this.assembleGraphOutputPortString(reader))); } @@ -224,7 +229,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param repository * The repository which should be added to the graph. */ - public void addRepository(final MIRepository repository) { + public synchronized void addRepository(final MIRepository repository) { final String repoPort = String.format(CurrentAnalysisEditorGraphBean.JS_CMD_PORT, CurrentAnalysisEditorGraphBean.JS_CMD_PORT_TYPE_INPUT, CurrentAnalysisEditorGraphBean.REPOSITORY_INPUT_PORT, "N/A"); RequestContext.getCurrentInstance().execute(String.format(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_REPOSITORY, 0, 0, @@ -244,7 +249,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param inputPort * The input port. */ - public void addConnection(final MIPlugin source, final MIPlugin destination, final MIOutputPort outputPort, final MIInputPort inputPort) { + public synchronized void addConnection(final MIPlugin source, final MIPlugin destination, final MIOutputPort outputPort, final MIInputPort inputPort) { RequestContext.getCurrentInstance().execute(String.format(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_EDGE, this.assembleGraphPortID(source, outputPort), this.assembleGraphPortID(destination, inputPort), "")); } @@ -259,7 +264,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param port * The repository port. */ - public void addConnection(final MIPlugin source, final MIRepository destination, final MIRepositoryConnector port) { + public synchronized void addConnection(final MIPlugin source, final MIRepository destination, final MIRepositoryConnector port) { RequestContext.getCurrentInstance().execute(String.format(CurrentAnalysisEditorGraphBean.JS_CMD_ADD_EDGE, this.assembleGraphPortID(source, port), this.assembleGraphPortID(destination), "")); } @@ -271,7 +276,7 @@ public final class CurrentAnalysisEditorGraphBean { * The ports to be used within the string command. * @return A string containing the JS commands to create the ports. */ - private String assembleGraphPortString(final EList<? extends MIPort> ports) { + private synchronized String assembleGraphPortString(final EList<? extends MIPort> ports) { final StringBuilder builder = new StringBuilder(); final int len = ports.size(); @@ -297,7 +302,7 @@ public final class CurrentAnalysisEditorGraphBean { * The ports which will be used. * @return A string containing the JS commands to create the repository ports. */ - private String assembleGraphRepositoryPortString(final EList<MIRepositoryConnector> ports) { + private synchronized String assembleGraphRepositoryPortString(final EList<MIRepositoryConnector> ports) { final StringBuilder builder = new StringBuilder(); final int len = ports.size(); @@ -322,7 +327,7 @@ public final class CurrentAnalysisEditorGraphBean { * The filter whose input ports will be used. * @return A string containing the JS commands to create the input ports. */ - private String assembleGraphInputPortString(final MIFilter filter) { + private synchronized String assembleGraphInputPortString(final MIFilter filter) { return this.assembleGraphPortString(filter.getInputPorts()); } @@ -333,7 +338,7 @@ public final class CurrentAnalysisEditorGraphBean { * The plugin whose output ports will be used. * @return A string containing the JS commands to create the output ports. */ - private String assembleGraphOutputPortString(final MIPlugin plugin) { + private synchronized String assembleGraphOutputPortString(final MIPlugin plugin) { return this.assembleGraphPortString(plugin.getOutputPorts()); } @@ -346,7 +351,7 @@ public final class CurrentAnalysisEditorGraphBean { * The port itself. * @return The ID for the port within the graph */ - private String assembleGraphPortID(final MIPlugin plugin, final MIPort port) { + private synchronized String assembleGraphPortID(final MIPlugin plugin, final MIPort port) { return this.componentMap.get(plugin) + "." + this.componentMap.get(port); } @@ -359,7 +364,7 @@ public final class CurrentAnalysisEditorGraphBean { * The port itself. * @return The ID for the port within the graph */ - private Object assembleGraphPortID(final MIPlugin plugin, final MIRepositoryConnector port) { + private synchronized Object assembleGraphPortID(final MIPlugin plugin, final MIRepositoryConnector port) { return this.componentMap.get(plugin) + "." + this.componentMap.get(port); } @@ -370,7 +375,7 @@ public final class CurrentAnalysisEditorGraphBean { * The parent repository of the port. * @return The ID for the port within the graph */ - private Object assembleGraphPortID(final MIRepository repository) { + private synchronized Object assembleGraphPortID(final MIRepository repository) { return this.componentMap.get(repository) + "." + CurrentAnalysisEditorGraphBean.REPOSITORY_INPUT_PORT; } @@ -381,7 +386,7 @@ public final class CurrentAnalysisEditorGraphBean { * The repository whose ID should be delivered. * @return A human readable ID. */ - private String assembleGraphString(final MIRepository repository) { + private synchronized String assembleGraphString(final MIRepository repository) { final String className = repository.getClassname(); final String shortName = className.substring(className.lastIndexOf('.') + 1); return String.format(CurrentAnalysisEditorGraphBean.JS_CMD_NODE, this.componentMap.get(repository), repository.getName(), shortName, className); @@ -394,7 +399,7 @@ public final class CurrentAnalysisEditorGraphBean { * The plugin whose ID should be delivered. * @return A human readable ID. */ - private String assembleGraphString(final MIPlugin plugin) { + private synchronized String assembleGraphString(final MIPlugin plugin) { final String className = plugin.getClassname(); final String shortName = className.substring(className.lastIndexOf('.') + 1); return String.format(CurrentAnalysisEditorGraphBean.JS_CMD_NODE, this.componentMap.get(plugin), plugin.getName(), shortName, className); @@ -404,7 +409,7 @@ public final class CurrentAnalysisEditorGraphBean { * This is the action which can be called from the javascript code to show that a node has been clicked. It informs the connected * {@link CurrentAnalysisEditorBean} about this. */ - public void nodeClicked() { + public synchronized void nodeClicked() { // Get the parameters final Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); final String clickedNodeID = paramMap.get("ID"); @@ -425,7 +430,7 @@ public final class CurrentAnalysisEditorGraphBean { * This is the action which can be called from the javascript code to show that a node has been removed. It informs the connected * {@link CurrentAnalysisEditorBean} about this. */ - public void nodeRemoved() { + public synchronized void nodeRemoved() { // Get the parameters final Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); final String clickedNodeID = paramMap.get("ID"); @@ -445,7 +450,7 @@ public final class CurrentAnalysisEditorGraphBean { * This is the action which can be called from the javascript code to show that an edge has been created. It informs the connected * {@link CurrentAnalysisEditorBean} about this. */ - public void edgeCreated() { + public synchronized void edgeCreated() { // Get the parameters final Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); @@ -481,7 +486,7 @@ public final class CurrentAnalysisEditorGraphBean { * This is the action which can be called from the javascript code to show that an edge has been removed. It informs the connected * {@link CurrentAnalysisEditorBean} about this. */ - public void edgeRemoved() { + public synchronized void edgeRemoved() { // Get the parameters final Map<String, String> paramMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); @@ -518,7 +523,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param color * The new color as a HTML color (FF0080 e.g.). */ - public void setGridColor(final String color) { + public synchronized void setGridColor(final String color) { final String cmd = String.format(CurrentAnalysisEditorGraphBean.JS_CMD_SET_GRID_COLOR, "#" + color); RequestContext.getCurrentInstance().execute(cmd); this.refreshGraph(); @@ -530,7 +535,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param size * The new grid size. */ - public void setGridSize(final int size) { + public synchronized void setGridSize(final int size) { final String cmd = String.format(CurrentAnalysisEditorGraphBean.JS_CMD_SET_GRID_SIZE, size); RequestContext.getCurrentInstance().execute(cmd); this.refreshGraph(); @@ -539,14 +544,14 @@ public final class CurrentAnalysisEditorGraphBean { /** * This method scales the graph to fit the current view. After this method-call, all components of the graph should be visible. */ - public void scaleToFit() { + public synchronized void scaleToFit() { RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_SCALE_TO_FIT); } /** * This method switches the visibility of the grid within the graph. */ - public void switchGrid() { + public synchronized void switchGrid() { if (this.gridEnabled) { RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_DISABLE_GRID); } else { @@ -560,7 +565,7 @@ public final class CurrentAnalysisEditorGraphBean { /** * This method switches the grid snap within the graph. */ - public void switchSnap() { + public synchronized void switchSnap() { if (this.snapEnabled) { RequestContext.getCurrentInstance().execute(CurrentAnalysisEditorGraphBean.JS_CMD_DISABLE_SNAP); } else { @@ -575,7 +580,7 @@ public final class CurrentAnalysisEditorGraphBean { * * @return The current value of the property. */ - public boolean isGridEnabled() { + public synchronized boolean isGridEnabled() { return this.gridEnabled; } @@ -584,7 +589,7 @@ public final class CurrentAnalysisEditorGraphBean { * * @return The current value of the property. */ - public boolean isSnapEnabled() { + public synchronized boolean isSnapEnabled() { return this.snapEnabled; } @@ -594,7 +599,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param currentAnalysisEditorBean * The new value for this field. */ - public void setCurrentAnalysisEditorBean(final CurrentAnalysisEditorBean currentAnalysisEditorBean) { + public synchronized void setCurrentAnalysisEditorBean(final CurrentAnalysisEditorBean currentAnalysisEditorBean) { this.currentAnalysisEditorBean = currentAnalysisEditorBean; } @@ -606,7 +611,7 @@ public final class CurrentAnalysisEditorGraphBean { * @param newName * The new name of the node. */ - public void renameNode(final EObject node, final String newName) { + public synchronized void renameNode(final EObject node, final String newName) { RequestContext.getCurrentInstance().execute(String.format(CurrentAnalysisEditorGraphBean.JS_CMD_RENAME_NODE, this.componentMap.get(node), newName)); this.refreshGraph(); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitBean.java index 1a065350..60a650f4 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitBean.java @@ -21,16 +21,20 @@ import java.io.IOException; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + import kieker.analysis.model.analysisMetaModel.MIProject; import kieker.analysis.model.analysisMetaModel.MIView; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; -import kieker.webgui.web.beans.application.GlobalPropertiesBean; -import kieker.webgui.web.beans.application.ProjectsBean; import kieker.webgui.common.ClassAndMethodContainer; import kieker.webgui.common.exception.DisplayNotFoundException; import kieker.webgui.common.exception.ProjectNotExistingException; import kieker.webgui.service.IProjectService; +import kieker.webgui.web.beans.application.GlobalPropertiesBean; +import kieker.webgui.web.beans.application.ProjectsBean; /** * The {@link CurrentCockpitBean} contains the necessary data behind an instance of the cockpit. It provides methods to read the state of the currently selected @@ -40,14 +44,18 @@ import kieker.webgui.service.IProjectService; * * @author Nils Christian Ehmke */ +@Component +@Scope("view") public final class CurrentCockpitBean { private static final Log LOG = LogFactory.getLog(CurrentCockpitBean.class); + @Autowired private IProjectService projectService; private String projectName; private MIProject project; private MIView activeView; private ClassAndMethodContainer classAndMethodContainer; + @Autowired private ProjectsBean projectsBean; /** @@ -62,13 +70,11 @@ public final class CurrentCockpitBean { * * @return The project for this user. */ - public MIProject getProject() { - synchronized (this) { - return this.project; - } + public synchronized MIProject getProject() { + return this.project; } - public void setProjectService(final IProjectService projectService) { + public synchronized void setProjectService(final IProjectService projectService) { this.projectService = projectService; } @@ -77,10 +83,8 @@ public final class CurrentCockpitBean { * * @return {@link #projectsBean} */ - public ProjectsBean getProjectsBean() { - synchronized (this) { - return this.projectsBean; - } + public synchronized ProjectsBean getProjectsBean() { + return this.projectsBean; } /** @@ -89,10 +93,8 @@ public final class CurrentCockpitBean { * @param projectsBean * The new value for {@link #projectsBean}. */ - public void setProjectsBean(final ProjectsBean projectsBean) { - synchronized (this) { - this.projectsBean = projectsBean; - } + public synchronized void setProjectsBean(final ProjectsBean projectsBean) { + this.projectsBean = projectsBean; } /** @@ -101,42 +103,38 @@ public final class CurrentCockpitBean { * @param newName * The name of the project. */ - public void setProjectName(final String newName) { - synchronized (this) { - // Remember the given parameters - this.projectName = newName; - } + public synchronized void setProjectName(final String newName) { + // Remember the given parameters + this.projectName = newName; } /** * This method initializes the bean by using the current project name to load the project. <b>Do not call this method manually. It will only be accessed by * Spring.</b> */ - public void initalize() { + public synchronized void initalize() { // TODO Replace the log messages with the localizes messages - synchronized (this) { - try { - // Make sure that the initialization will only be done for the init request. - if (!FacesContext.getCurrentInstance().isPostback()) { - // Remember the given parameters - this.project = this.projectsBean.openProject(this.projectName); - - if (this.project != null) { - final ClassLoader classLoader = this.projectService.getClassLoader(this.projectName, this); // NOPMD (ClassLoader) - this.classAndMethodContainer = new ClassAndMethodContainer(classLoader); - } + try { + // Make sure that the initialization will only be done for the init request. + if (!FacesContext.getCurrentInstance().isPostback()) { + // Remember the given parameters + this.project = this.projectsBean.openProject(this.projectName); + + if (this.project != null) { + final ClassLoader classLoader = this.projectService.getClassLoader(this.projectName, this); // NOPMD (ClassLoader) + this.classAndMethodContainer = new ClassAndMethodContainer(classLoader); } - } catch (final ProjectNotExistingException ex) { - CurrentCockpitBean.LOG.error("An error occured while loading the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); - } catch (final IOException ex) { - CurrentCockpitBean.LOG.error("An error occured while loading the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); - } catch (final NullPointerException ex) { - // This exception occurs, when the projectsBean has not been initialized - CurrentCockpitBean.LOG.error("An error occured while loading the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); } + } catch (final ProjectNotExistingException ex) { + CurrentCockpitBean.LOG.error("An error occured while loading the project.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); + } catch (final IOException ex) { + CurrentCockpitBean.LOG.error("An error occured while loading the project.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); + } catch (final NullPointerException ex) { + // This exception occurs, when the projectsBean has not been initialized + CurrentCockpitBean.LOG.error("An error occured while loading the project.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); } } @@ -145,10 +143,8 @@ public final class CurrentCockpitBean { * * @return The project name for this user. */ - public String getProjectName() { - synchronized (this) { - return this.projectName; - } + public synchronized String getProjectName() { + return this.projectName; } /** @@ -159,20 +155,18 @@ public final class CurrentCockpitBean { * @return The current content of the display, if it exists. If the display does not exist or the active view is not set 'N/A' will be returned. If an access to * the display fails, "Error" will be returned. */ - public String updatePlainTextDisplay(final String displayName) { - synchronized (this) { - if ((this.activeView != null) && (this.projectName != null)) { - try { - final Object displayObj = this.projectService.getDisplay(this.projectName, this.activeView.getName(), displayName); - final String result = (String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getPlainTextgetTextMethod(), displayObj, - "Error"); - return result; - } catch (final DisplayNotFoundException ex) { - CurrentCockpitBean.LOG.warn("Display not found.", ex); - } + public synchronized String updatePlainTextDisplay(final String displayName) { + if ((this.activeView != null) && (this.projectName != null)) { + try { + final Object displayObj = this.projectService.getDisplay(this.projectName, this.activeView.getName(), displayName); + final String result = (String) ClassAndMethodContainer.invokeMethod(this.classAndMethodContainer.getPlainTextgetTextMethod(), displayObj, + "Error"); + return result; + } catch (final DisplayNotFoundException ex) { + CurrentCockpitBean.LOG.warn("Display not found.", ex); } - return "N/A"; } + return "N/A"; } /** @@ -180,7 +174,7 @@ public final class CurrentCockpitBean { * * @return Currently this method returns only N/A. */ - public String updateHtmlTextDisplay() { + public synchronized String updateHtmlTextDisplay() { return "N/A"; } @@ -189,7 +183,7 @@ public final class CurrentCockpitBean { * * @return Currently this method returns only N/A. */ - public String updateImageDisplay() { + public synchronized String updateImageDisplay() { return "N/A"; } @@ -198,10 +192,8 @@ public final class CurrentCockpitBean { * * @return The active view. */ - public MIView getActiveView() { - synchronized (this) { - return this.activeView; - } + public synchronized MIView getActiveView() { + return this.activeView; } /** @@ -210,9 +202,7 @@ public final class CurrentCockpitBean { * @param activeView * The new active view. */ - public void setActiveView(final MIView activeView) { - synchronized (this) { - this.activeView = activeView; - } + public synchronized void setActiveView(final MIView activeView) { + this.activeView = activeView; } } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java index cb7d9875..ea73f84c 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentCockpitEditorBean.java @@ -30,6 +30,10 @@ import javax.faces.component.UIInput; import javax.faces.component.html.HtmlOutputText; import javax.faces.context.FacesContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + import kieker.analysis.display.annotation.Display; import kieker.analysis.model.analysisMetaModel.MIAnalysisMetaModelFactory; import kieker.analysis.model.analysisMetaModel.MIDisplay; @@ -40,13 +44,13 @@ import kieker.analysis.model.analysisMetaModel.impl.MAnalysisMetaModelFactory; import kieker.analysis.plugin.AbstractPlugin; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; -import kieker.webgui.web.beans.application.GlobalPropertiesBean; -import kieker.webgui.web.beans.application.ProjectsBean; import kieker.webgui.common.ClassAndMethodContainer; import kieker.webgui.common.exception.NewerProjectException; import kieker.webgui.common.exception.ProjectLoadException; import kieker.webgui.common.exception.ProjectNotExistingException; import kieker.webgui.service.IProjectService; +import kieker.webgui.web.beans.application.GlobalPropertiesBean; +import kieker.webgui.web.beans.application.ProjectsBean; import org.primefaces.component.dashboard.Dashboard; import org.primefaces.component.panel.Panel; @@ -64,12 +68,15 @@ import org.primefaces.model.DefaultDashboardModel; * * @author Nils Christian Ehmke */ +@Component +@Scope("view") public final class CurrentCockpitEditorBean { private static final int NUMBER_COLUMNS = 2; private static final Log LOG = LogFactory.getLog(CurrentCockpitEditorBean.class); private final MIAnalysisMetaModelFactory factory = new MAnalysisMetaModelFactory(); + @Autowired private IProjectService projectService; private ClassAndMethodContainer classAndMethodContainer; @@ -80,8 +87,9 @@ public final class CurrentCockpitEditorBean { private ClassLoader classLoader; private Dashboard dashboard; private DashboardModel dashboardModel; - + @Autowired private ProjectsBean projectsBean; + @Autowired private GlobalPropertiesBean globalPropertiesBean; /** @@ -91,17 +99,7 @@ public final class CurrentCockpitEditorBean { this.createDashboard(); } - /** - * Setter for the property {@link CurrentCockpitEditorBean#projectService}. - * - * @param projectService - * The new value of the property. - */ - public void setProjectService(final IProjectService projectService) { - this.projectService = projectService; - } - - private void createDashboard() { + private synchronized void createDashboard() { final FacesContext fc = FacesContext.getCurrentInstance(); final Application application = fc.getApplication(); @@ -118,7 +116,7 @@ public final class CurrentCockpitEditorBean { this.dashboard.setModel(this.dashboardModel); } - private void fillDashboard() { + private synchronized void fillDashboard() { // Dump the old entries this.clearDashboard(); @@ -149,7 +147,7 @@ public final class CurrentCockpitEditorBean { } } - private void clearDashboard() { + private synchronized void clearDashboard() { // Run through all columns of the dashboard and remove the items final List<DashboardColumn> columns = this.dashboard.getModel().getColumns(); for (final DashboardColumn column : columns) { @@ -159,50 +157,31 @@ public final class CurrentCockpitEditorBean { this.dashboard.getChildren().clear(); } - /** - * Getter for the attribute {@link CurrentCockpitEditorBean#projectsBean}. - * - * @return Delivers the value of the attribute. - */ - public ProjectsBean getProjectsBean() { - return this.projectsBean; - } - - /** - * Setter for the attribute {@link CurrentCockpitEditorBean#projectsBean}. - * - * @param projectsBean - * The new value of the attribute. - */ - public void setProjectsBean(final ProjectsBean projectsBean) { - this.projectsBean = projectsBean; - } - /** * This method initializes the bean by using the current project name to load the project. <b>Do not call this method manually. It will only be accessed by * Spring.</b> */ - public void initalize() { - synchronized (this) { - try { - // Make sure that the initialization will only be done for the init request. - if (!FacesContext.getCurrentInstance().isPostback()) { - // Remember the given parameters - this.project = this.projectsBean.openProject(this.projectName); - if (this.project != null) { - // Remember the current time! This is important for the later comparison of the time stamps. - this.resetTimeStamp(); - // Update the class loader and the specific classes used within various methods in this bean - this.reloadClassLoader(); - this.reloadClassesAndMethods(); - this.fillDashboard(); - } + public synchronized void initalize() { + + try { + // Make sure that the initialization will only be done for the init request. + if (!FacesContext.getCurrentInstance().isPostback()) { + // Remember the given parameters + this.project = this.projectsBean.openProject(this.projectName); + if (this.project != null) { + // Remember the current time! This is important for the later comparison of the time stamps. + this.resetTimeStamp(); + // Update the class loader and the specific classes used within various methods in this bean + this.reloadClassLoader(); + this.reloadClassesAndMethods(); + this.fillDashboard(); } - } catch (final ProjectLoadException ex) { - CurrentCockpitEditorBean.LOG.error("An error occured while loading the project.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); } + } catch (final ProjectLoadException ex) { + CurrentCockpitEditorBean.LOG.error("An error occured while loading the project.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while loading the project."); } + } /** @@ -211,10 +190,8 @@ public final class CurrentCockpitEditorBean { * @throws ProjectLoadException * If one or more of the classes and methods necessary for {@link ClassAndMethodContainer} could not be found using the given class loader. */ - private void reloadClassesAndMethods() throws ProjectLoadException { - synchronized (this) { - this.classAndMethodContainer = new ClassAndMethodContainer(this.classLoader); - } + private synchronized void reloadClassesAndMethods() throws ProjectLoadException { + this.classAndMethodContainer = new ClassAndMethodContainer(this.classLoader); } /** @@ -224,17 +201,15 @@ public final class CurrentCockpitEditorBean { * @throws ProjectLoadException * If something went wrong. */ - private void reloadClassLoader() throws ProjectLoadException { - synchronized (this) { - try { - this.classLoader = this.projectService.getClassLoader(this.projectName, this); // NOPMD (ClassLoader) - } catch (final NullPointerException ex) { - throw new ProjectLoadException("Invalid class loader.", ex); - } catch (final IOException ex) { - throw new ProjectLoadException("Could not load classes.", ex); - } catch (final ProjectNotExistingException ex) { - throw new ProjectLoadException("Project does not exist.", ex); - } + private synchronized void reloadClassLoader() throws ProjectLoadException { + try { + this.classLoader = this.projectService.getClassLoader(this.projectName, this); // NOPMD (ClassLoader) + } catch (final NullPointerException ex) { + throw new ProjectLoadException("Invalid class loader.", ex); + } catch (final IOException ex) { + throw new ProjectLoadException("Could not load classes.", ex); + } catch (final ProjectNotExistingException ex) { + throw new ProjectLoadException("Project does not exist.", ex); } } @@ -243,10 +218,8 @@ public final class CurrentCockpitEditorBean { * * @return The project for this user. */ - public MIProject getProject() { - synchronized (this) { - return this.project; - } + public synchronized MIProject getProject() { + return this.project; } /** @@ -255,10 +228,8 @@ public final class CurrentCockpitEditorBean { * @param newName * The name of the project. */ - public void setProjectName(final String newName) { - synchronized (this) { - this.projectName = newName; - } + public synchronized void setProjectName(final String newName) { + this.projectName = newName; } /** @@ -266,10 +237,8 @@ public final class CurrentCockpitEditorBean { * * @return The project name for this user. */ - public String getProjectName() { - synchronized (this) { - return this.projectName; - } + public synchronized String getProjectName() { + return this.projectName; } /** @@ -279,7 +248,7 @@ public final class CurrentCockpitEditorBean { * The display whose description should be extracted. * @return The description for the display or a substitute if none is available. This is in either case human readable. */ - public String getDescription(final MIDisplay display) { + public synchronized String getDescription(final MIDisplay display) { try { final String classname = display.getParent().getClassname(); final String displayName = display.getName(); @@ -311,35 +280,31 @@ public final class CurrentCockpitEditorBean { * @param overwriteNewerProject * This flag determines whether a newer project should be overwritten. */ - public void saveProject(final boolean overwriteNewerProject) { - synchronized (this) { - try { - this.projectService.saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgProjectSaved()); - // Update the time stamp! - this.resetTimeStamp(); - } catch (final IOException ex) { - CurrentCockpitEditorBean.LOG.error("An error occured while saving the projet.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while saving the project."); - } catch (final NewerProjectException ex) { - CurrentCockpitEditorBean.LOG.info("The project has been modified externally in the meanwhile.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_WARN, "The project has been modified externally in the meanwhile."); - // Give the user the possibility to force-save the project - RequestContext.getCurrentInstance().execute("forceSaveDlg.show()"); - } catch (final ProjectNotExistingException ex) { - CurrentCockpitEditorBean.LOG.error("A project with the given name does not exist.", ex); - GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "A project with the given name does not exist."); - } + public synchronized void saveProject(final boolean overwriteNewerProject) { + try { + this.projectService.saveProject(this.projectName, this.project, this.timeStamp, overwriteNewerProject); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_INFO, this.globalPropertiesBean.getMsgProjectSaved()); + // Update the time stamp! + this.resetTimeStamp(); + } catch (final IOException ex) { + CurrentCockpitEditorBean.LOG.error("An error occured while saving the projet.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while saving the project."); + } catch (final NewerProjectException ex) { + CurrentCockpitEditorBean.LOG.info("The project has been modified externally in the meanwhile.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_WARN, "The project has been modified externally in the meanwhile."); + // Give the user the possibility to force-save the project + RequestContext.getCurrentInstance().execute("forceSaveDlg.show()"); + } catch (final ProjectNotExistingException ex) { + CurrentCockpitEditorBean.LOG.error("A project with the given name does not exist.", ex); + GlobalPropertiesBean.showMessage(FacesMessage.SEVERITY_ERROR, "A project with the given name does not exist."); } } /** * This method sets the time stamp to the current system time. */ - public void resetTimeStamp() { - synchronized (this) { - this.timeStamp = System.currentTimeMillis(); - } + public synchronized void resetTimeStamp() { + this.timeStamp = System.currentTimeMillis(); } /** @@ -349,19 +314,17 @@ public final class CurrentCockpitEditorBean { * The plugin whose displays should be delivered. * @return The available displays. */ - public List<Display> getDisplays(final Class<AbstractPlugin> clazz) { + public synchronized List<Display> getDisplays(final Class<AbstractPlugin> clazz) { final List<Display> result = new ArrayList<Display>(); - synchronized (this) { - if (clazz != null) { - // Run through all available methods and find the annotated ones - final Method[] methods = clazz.getMethods(); - for (final Method method : methods) { - final Display displayAnnot = method.getAnnotation(Display.class); - // Check whether the annotation is available. If yes - add it to our result list - if (displayAnnot != null) { - result.add(displayAnnot); - } + if (clazz != null) { + // Run through all available methods and find the annotated ones + final Method[] methods = clazz.getMethods(); + for (final Method method : methods) { + final Display displayAnnot = method.getAnnotation(Display.class); + // Check whether the annotation is available. If yes - add it to our result list + if (displayAnnot != null) { + result.add(displayAnnot); } } } @@ -375,15 +338,13 @@ public final class CurrentCockpitEditorBean { * @param viewName * The name of the new view. */ - public void addView(final String viewName) { - synchronized (this) { - if (this.project != null) { - // Create the view and add it to our project - final MIView view = this.factory.createView(); - view.setName(viewName); - view.setDescription("No description available."); - this.project.getViews().add(view); - } + public synchronized void addView(final String viewName) { + if (this.project != null) { + // Create the view and add it to our project + final MIView view = this.factory.createView(); + view.setName(viewName); + view.setDescription("No description available."); + this.project.getViews().add(view); } } @@ -392,10 +353,8 @@ public final class CurrentCockpitEditorBean { * * @return The currently active view. */ - public MIView getActiveView() { - synchronized (this) { - return this.activeView; - } + public synchronized MIView getActiveView() { + return this.activeView; } /** @@ -404,12 +363,10 @@ public final class CurrentCockpitEditorBean { * @param view * The new active view. */ - public void setActiveView(final MIView view) { - synchronized (this) { - this.activeView = view; + public synchronized void setActiveView(final MIView view) { + this.activeView = view; - this.fillDashboard(); - } + this.fillDashboard(); } /** @@ -418,32 +375,30 @@ public final class CurrentCockpitEditorBean { * @param display * The display which should be added to the current view. */ - public void addDisplayToView(final MIDisplay display) { - synchronized (this) { - if (this.activeView != null) { - final MIDisplayConnector connector = this.factory.createDisplayConnector(); - connector.setDisplay(display); - connector.setName(UUID.randomUUID().toString()); - this.activeView.getDisplayConnectors().add(connector); - - // Now add it to the dashboard as well - final FacesContext fc = FacesContext.getCurrentInstance(); - final Application application = fc.getApplication(); + public synchronized void addDisplayToView(final MIDisplay display) { + if (this.activeView != null) { + final MIDisplayConnector connector = this.factory.createDisplayConnector(); + connector.setDisplay(display); + connector.setName(UUID.randomUUID().toString()); + this.activeView.getDisplayConnectors().add(connector); - final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer"); - panel.setId("displayConnectorPanel_" + (this.dashboard.getChildCount() + 1)); - panel.setHeader(connector.getName()); - panel.setClosable(true); - panel.setToggleable(false); + // Now add it to the dashboard as well + final FacesContext fc = FacesContext.getCurrentInstance(); + final Application application = fc.getApplication(); - this.getDashboard().getChildren().add(panel); - final DashboardColumn column = this.dashboardModel.getColumn(CurrentCockpitEditorBean.NUMBER_COLUMNS - 1); - column.addWidget(panel.getId()); - final HtmlOutputText text = new HtmlOutputText(); - text.setValue("N/A"); + final Panel panel = (Panel) application.createComponent(fc, "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer"); + panel.setId("displayConnectorPanel_" + (this.dashboard.getChildCount() + 1)); + panel.setHeader(connector.getName()); + panel.setClosable(true); + panel.setToggleable(false); - panel.getChildren().add(text); - } + this.getDashboard().getChildren().add(panel); + final DashboardColumn column = this.dashboardModel.getColumn(CurrentCockpitEditorBean.NUMBER_COLUMNS - 1); + column.addWidget(panel.getId()); + final HtmlOutputText text = new HtmlOutputText(); + text.setValue("N/A"); + + panel.getChildren().add(text); } } @@ -466,23 +421,21 @@ public final class CurrentCockpitEditorBean { * The name to be checked. * @return true iff the name exists already. */ - private boolean existsDisplayConnectorName(final String name) { - synchronized (this) { - // Make sure a view is selected - if (this.activeView == null) { - return false; - } + private synchronized boolean existsDisplayConnectorName(final String name) { + // Make sure a view is selected + if (this.activeView == null) { + return false; + } - // Run through all display connectors and check the name against the given one - for (final MIDisplayConnector connector : this.activeView.getDisplayConnectors()) { - if (connector.getName().equals(name)) { - return true; - } + // Run through all display connectors and check the name against the given one + for (final MIDisplayConnector connector : this.activeView.getDisplayConnectors()) { + if (connector.getName().equals(name)) { + return true; } - - // The name has not been found - return false; } + + // The name has not been found + return false; } /** @@ -495,41 +448,20 @@ public final class CurrentCockpitEditorBean { * @param value * The new value. */ - public void validateDisplayConnectorName(final FacesContext context, final UIComponent toValidate, final Object value) { - synchronized (this) { - if ((value instanceof String) && (toValidate instanceof UIInput)) { - final boolean nameExists = this.existsDisplayConnectorName((String) value); - ((UIInput) toValidate).setValid(!nameExists); - } + public synchronized void validateDisplayConnectorName(final FacesContext context, final UIComponent toValidate, final Object value) { + if ((value instanceof String) && (toValidate instanceof UIInput)) { + final boolean nameExists = this.existsDisplayConnectorName((String) value); + ((UIInput) toValidate).setValid(!nameExists); } } - public Dashboard getDashboard() { + public synchronized Dashboard getDashboard() { return this.dashboard; } - public void setDashboard(final Dashboard dashboard) { + public synchronized void setDashboard(final Dashboard dashboard) { this.dashboard = dashboard; this.dashboard.setModel(this.dashboardModel); } - /** - * The getter for the property {@link CurrentCockpitEditorBean#globalPropertiesBean}. - * - * @return The current value of the property. - */ - public GlobalPropertiesBean getGlobalPropertiesBean() { - return this.globalPropertiesBean; - } - - /** - * The setter for the property {@link CurrentCockpitEditorBean#globalPropertiesBean}. - * - * @param globalPropertiesBean - * The new value of the property. - */ - public void setGlobalPropertiesBean(final GlobalPropertiesBean globalPropertiesBean) { - this.globalPropertiesBean = globalPropertiesBean; - } - } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentControllerBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentControllerBean.java index fb1bacde..b037dacb 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentControllerBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentControllerBean.java @@ -25,14 +25,18 @@ import java.util.Collection; import java.util.Date; import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + import kieker.analysis.AnalysisController; import kieker.common.logging.Log; import kieker.common.logging.LogFactory; -import kieker.webgui.web.beans.application.ProjectsBean; import kieker.webgui.common.exception.AnalysisInitializationException; import kieker.webgui.common.exception.AnalysisStateException; import kieker.webgui.common.exception.ProjectNotExistingException; import kieker.webgui.service.IProjectService; +import kieker.webgui.web.beans.application.ProjectsBean; /** * /** @@ -41,13 +45,17 @@ import kieker.webgui.service.IProjectService; * * @author Nils Christian Ehmke */ +@Component +@Scope("view") public final class CurrentControllerBean { private static final Log LOG = LogFactory.getLog(CurrentControllerBean.class); - + @Autowired private IProjectService projectService; private final List<String> logEntries = new ArrayList<String>(); + private String projectName; + @Autowired private ProjectsBean projectsBean; /** @@ -57,40 +65,16 @@ public final class CurrentControllerBean { // No code necessary } - /** - * The getter for the {@link #projectsBean}-property. - * - * @return {@link #projectsBean} - */ - public ProjectsBean getProjectsBean() { - return this.projectsBean; - } - - public void setProjectService(final IProjectService projectService) { - this.projectService = projectService; - } - - /** - * The setter for the {@link #projectsBean}-property. - * - * @param projectsBean - * The new value for {@link #projectsBean}. - */ - public void setProjectsBean(final ProjectsBean projectsBean) { - this.projectsBean = projectsBean; - } - /** * This method sets the project stored within this bean and returns the new page for the navigation. * * @param newName * The name of the project. */ - public void setProjectName(final String newName) { - synchronized (this) { - // Remember the given parameters - this.projectName = newName; - } + public synchronized void setProjectName(final String newName) { + // Remember the given parameters + this.projectName = newName; + } /** @@ -98,34 +82,31 @@ public final class CurrentControllerBean { * * @return The project name for this user. */ - public String getProjectName() { - synchronized (this) { - return this.projectName; - } + public synchronized String getProjectName() { + return this.projectName; } /** * This method starts the current analysis and informs the user about a fail. */ - public void startAnalysis() { - synchronized (this) { - this.addLogEntry("Starting Analysis for project '" + this.projectName + "'"); - try { - this.projectService.startAnalysis(this.projectName); - } catch (final AnalysisStateException ex) { - CurrentControllerBean.LOG.info("The analysis has already been started.", ex); - this.addLogEntry(ex); - } catch (final ProjectNotExistingException ex) { - CurrentControllerBean.LOG.info("The project does not exist.", ex); - this.addLogEntry(ex); - } + public synchronized void startAnalysis() { + this.addLogEntry("Starting Analysis for project '" + this.projectName + "'"); + try { + this.projectService.startAnalysis(this.projectName); + } catch (final AnalysisStateException ex) { + CurrentControllerBean.LOG.info("The analysis has already been started.", ex); + this.addLogEntry(ex); + } catch (final ProjectNotExistingException ex) { + CurrentControllerBean.LOG.info("The project does not exist.", ex); + this.addLogEntry(ex); } + } /** * This method stops the current analysis and informs the user about a fail. */ - public void stopAnalysis() { + public synchronized void stopAnalysis() { try { this.addLogEntry("Stopping Analysis for project '" + this.projectName + "'"); synchronized (this) { @@ -143,42 +124,39 @@ public final class CurrentControllerBean { /** * This method initializes the current analysis and informs the user about a fail. */ - public void instantiateAnalysis() { - synchronized (this) { - this.addLogEntry("Instantiating Analysis for project '" + this.projectName + "'"); - try { - this.projectService.initializeAnalysis(this.projectName, this.projectService.getClassLoader(this.projectName, this)); // NOPMD (ClassLoader) - } catch (final AnalysisStateException ex) { - CurrentControllerBean.LOG.error("The analysis has already been instantiated.", ex); - this.addLogEntry(ex); - } catch (final ProjectNotExistingException ex) { - CurrentControllerBean.LOG.info("The project does not exist.", ex); - this.addLogEntry(ex); - } catch (final IOException ex) { - CurrentControllerBean.LOG.info("An error occured during the initialization.", ex); - this.addLogEntry(ex); - } catch (final AnalysisInitializationException ex) { - CurrentControllerBean.LOG.info("An error occured during the initialization.", ex); - this.addLogEntry(ex); - } + public synchronized void instantiateAnalysis() { + this.addLogEntry("Instantiating Analysis for project '" + this.projectName + "'"); + try { + this.projectService.initializeAnalysis(this.projectName, this.projectService.getClassLoader(this.projectName, this)); // NOPMD (ClassLoader) + } catch (final AnalysisStateException ex) { + CurrentControllerBean.LOG.error("The analysis has already been instantiated.", ex); + this.addLogEntry(ex); + } catch (final ProjectNotExistingException ex) { + CurrentControllerBean.LOG.info("The project does not exist.", ex); + this.addLogEntry(ex); + } catch (final IOException ex) { + CurrentControllerBean.LOG.info("An error occured during the initialization.", ex); + this.addLogEntry(ex); + } catch (final AnalysisInitializationException ex) { + CurrentControllerBean.LOG.info("An error occured during the initialization.", ex); + this.addLogEntry(ex); } } /** * This method cleans the current analysis instance. */ - public void cleanAnalysis() { - synchronized (this) { - this.addLogEntry("Cleaning Analysis for project '" + this.projectName + "'"); - try { - this.projectService.cleanAnalysis(this.projectName); - } catch (final ProjectNotExistingException ex) { - CurrentControllerBean.LOG.info("The project does not exist.", ex); - this.addLogEntry(ex); - } catch (final AnalysisStateException ex) { - CurrentControllerBean.LOG.error("The analysis has not been instantiated yet.", ex); - this.addLogEntry(ex); - } + public synchronized void cleanAnalysis() { + this.addLogEntry("Cleaning Analysis for project '" + this.projectName + "'"); + try { + this.projectService.cleanAnalysis(this.projectName); + } catch (final ProjectNotExistingException ex) { + CurrentControllerBean.LOG.info("The project does not exist.", ex); + this.addLogEntry(ex); + } catch (final AnalysisStateException ex) { + CurrentControllerBean.LOG.error("The analysis has not been instantiated yet.", ex); + this.addLogEntry(ex); + } } @@ -187,18 +165,16 @@ public final class CurrentControllerBean { * * @return true if and only if the analysis is running. */ - public boolean isAnalysisRunning() { - synchronized (this) { - try { - return this.projectService.getCurrentState(this.projectName) == AnalysisController.STATE.RUNNING; - } catch (final ProjectNotExistingException ex) { - CurrentControllerBean.LOG.info("The project does not exist.", ex); - return false; - } catch (final NullPointerException ex) { - // This exception can occur, when the projectsBean has not been initialized - CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); - return false; - } + public synchronized boolean isAnalysisRunning() { + try { + return this.projectService.getCurrentState(this.projectName) == AnalysisController.STATE.RUNNING; + } catch (final ProjectNotExistingException ex) { + CurrentControllerBean.LOG.info("The project does not exist.", ex); + return false; + } catch (final NullPointerException ex) { + // This exception can occur, when the projectsBean has not been initialized + CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); + return false; } } @@ -207,18 +183,17 @@ public final class CurrentControllerBean { * * @return true if and only if the analysis is ready to be started. */ - public boolean isAnalysisReady() { - synchronized (this) { - try { - return this.projectService.getCurrentState(this.projectName) == AnalysisController.STATE.READY; - } catch (final ProjectNotExistingException ex) { - CurrentControllerBean.LOG.info("The project does not exist.", ex); - return false; - } catch (final NullPointerException ex) { - // This exception can occur, when the projectsBean has not been initialized - CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); - return false; - } + public synchronized boolean isAnalysisReady() { + try { + return this.projectService.getCurrentState(this.projectName) == AnalysisController.STATE.READY; + } catch (final ProjectNotExistingException ex) { + CurrentControllerBean.LOG.info("The project does not exist.", ex); + return false; + } catch (final NullPointerException ex) { + // This exception can occur, when the projectsBean has not been initialized + CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); + return false; + } } @@ -227,19 +202,19 @@ public final class CurrentControllerBean { * * @return true if and only if the analysis is <b>not</b> available. */ - public boolean isAnalysisNotAvailable() { - synchronized (this) { - try { - return this.projectService.getCurrentState(this.projectName) == null; - } catch (final ProjectNotExistingException ex) { - CurrentControllerBean.LOG.info("The project does not exist.", ex); - return true; - } catch (final NullPointerException ex) { - // This exception can occur, when the projectsBean has not been initialized - CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); - return true; - } + public synchronized boolean isAnalysisNotAvailable() { + + try { + return this.projectService.getCurrentState(this.projectName) == null; + } catch (final ProjectNotExistingException ex) { + CurrentControllerBean.LOG.info("The project does not exist.", ex); + return true; + } catch (final NullPointerException ex) { + // This exception can occur, when the projectsBean has not been initialized + CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); + return true; } + } /** @@ -247,19 +222,19 @@ public final class CurrentControllerBean { * * @return true if and only if the analysis has been terminated. */ - public boolean isAnalysisTerminated() { - synchronized (this) { - try { - return this.projectService.getCurrentState(this.projectName) == AnalysisController.STATE.TERMINATED; - } catch (final ProjectNotExistingException ex) { - CurrentControllerBean.LOG.info("The project does not exist.", ex); - return false; - } catch (final NullPointerException ex) { - // This exception can occur, when the projectsBean has not been initialized - CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); - return false; - } + public synchronized boolean isAnalysisTerminated() { + + try { + return this.projectService.getCurrentState(this.projectName) == AnalysisController.STATE.TERMINATED; + } catch (final ProjectNotExistingException ex) { + CurrentControllerBean.LOG.info("The project does not exist.", ex); + return false; + } catch (final NullPointerException ex) { + // This exception can occur, when the projectsBean has not been initialized + CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); + return false; } + } /** @@ -267,19 +242,19 @@ public final class CurrentControllerBean { * * @return true if and only if the analysis has failed. */ - public boolean isAnalysisFailed() { - synchronized (this) { - try { - return this.projectService.getCurrentState(this.projectName) == AnalysisController.STATE.FAILED; - } catch (final ProjectNotExistingException ex) { - CurrentControllerBean.LOG.info("The project does not exist.", ex); - return false; - } catch (final NullPointerException ex) { - // This exception can occur, when the projectsBean has not been initialized - CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); - return false; - } + public synchronized boolean isAnalysisFailed() { + + try { + return this.projectService.getCurrentState(this.projectName) == AnalysisController.STATE.FAILED; + } catch (final ProjectNotExistingException ex) { + CurrentControllerBean.LOG.info("The project does not exist.", ex); + return false; + } catch (final NullPointerException ex) { + // This exception can occur, when the projectsBean has not been initialized + CurrentControllerBean.LOG.warn("A null pointer exception occured.", ex); + return false; } + } /** @@ -287,7 +262,7 @@ public final class CurrentControllerBean { * * @return The current log entries. */ - public Object[] getAnalysisLog() { + public synchronized Object[] getAnalysisLog() { try { return this.projectService.getLogEntries(this.projectName); } catch (final AnalysisStateException ex) { @@ -301,7 +276,7 @@ public final class CurrentControllerBean { * * @return The current log entries. */ - public Collection<String> getViewLog() { + public synchronized Collection<String> getViewLog() { return this.logEntries; } @@ -311,7 +286,7 @@ public final class CurrentControllerBean { * @param cause * The element to be added. */ - private void addLogEntry(final Throwable cause) { + private synchronized void addLogEntry(final Throwable cause) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); cause.printStackTrace(printWriter); @@ -324,7 +299,7 @@ public final class CurrentControllerBean { * @param msg * The log message. */ - private void addLogEntry(final String msg) { + private synchronized void addLogEntry(final String msg) { final String finalMsg = new Date().toString() + " : " + msg; synchronized (this) { if (this.logEntries.size() > 50) { diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentProjectOverviewBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentProjectOverviewBean.java index ac5bc4f7..5f56521e 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentProjectOverviewBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentProjectOverviewBean.java @@ -19,6 +19,12 @@ package kieker.webgui.web.beans.view; import java.util.ArrayList; import java.util.List; +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + import kieker.webgui.web.beans.application.ProjectsBean; import org.primefaces.event.SelectEvent; @@ -29,8 +35,10 @@ import org.primefaces.event.SelectEvent; * * @author Nils Christian Ehmke */ +@Component +@Scope("view") public final class CurrentProjectOverviewBean { - + @Autowired private ProjectsBean projectsBean; /** * This list contains all available projects by name. @@ -90,6 +98,7 @@ public final class CurrentProjectOverviewBean { /** * This method should only be called automatically by Spring to update the projects list. */ + @PostConstruct protected void initialialize() { this.updateLists(); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentUserManagementBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentUserManagementBean.java index ea0195bb..3e82f388 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentUserManagementBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/beans/view/CurrentUserManagementBean.java @@ -19,6 +19,12 @@ package kieker.webgui.web.beans.view; import java.util.ArrayList; import java.util.List; +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + import kieker.webgui.domain.User; import kieker.webgui.domain.User.Role; import kieker.webgui.service.IUserService; @@ -26,8 +32,10 @@ import kieker.webgui.service.IUserService; /** * @author Nils Christian Ehmke */ +@Component +@Scope("view") public final class CurrentUserManagementBean { - + @Autowired private IUserService userService; /** * This list contains all available users. @@ -94,6 +102,7 @@ public final class CurrentUserManagementBean { /** * This method initializes the bean. <b>Do not call this method manually. It will only be accessed by Spring.</b> */ + @PostConstruct protected void initialialize() { this.updateList(); } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/web/converter/RoleStringConverter.java b/Kieker.WebGUI/src/main/java/kieker/webgui/web/converter/RoleStringConverter.java index 99b15498..d8e580ff 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/web/converter/RoleStringConverter.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/web/converter/RoleStringConverter.java @@ -26,6 +26,10 @@ import kieker.webgui.domain.User.Role; @FacesConverter("roleStringConverter") public class RoleStringConverter implements Converter { + public RoleStringConverter() { + // No code necessary + } + @Override public Object getAsObject(final FacesContext context, final UIComponent comp, final String str) { return Role.valueOf(str); diff --git a/Kieker.WebGUI/src/main/webapp/WEB-INF/spring-bean-config.xml b/Kieker.WebGUI/src/main/webapp/WEB-INF/spring-bean-config.xml index a3ccefdb..3e101623 100644 --- a/Kieker.WebGUI/src/main/webapp/WEB-INF/spring-bean-config.xml +++ b/Kieker.WebGUI/src/main/webapp/WEB-INF/spring-bean-config.xml @@ -3,25 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd - http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd" xmlns:context="http://www.springframework.org/schema/context"> <!-- The singleton scoped beans. --> - <bean id="projectDAO" class="kieker.webgui.persistence.impl.FSProjectDAOImpl" init-method="initialize"/> - <bean id="pluginFinder" class="kieker.webgui.service.impl.util.PluginFinder" /> - <bean id="projectService" class="kieker.webgui.service.impl.ProjectServiceImpl"> - <property name="projectDAO" ref="projectDAO" /> - <property name="acManager" ref="acManager" /> - <property name="pluginFinder" ref="pluginFinder" /> - </bean> - <bean id="userService" class="kieker.webgui.service.impl.UserServiceImpl"> - <property name="userDAO" ref="userDAO" /> - </bean> - <bean id="acManager" class="kieker.webgui.service.impl.util.ACManager"> - <property name="projectDAO" ref="projectDAO" /> - </bean> - <bean id="projectsBean" lazy-init="true" class="kieker.webgui.web.beans.application.ProjectsBean" init-method="initialize"> - <property name="projectService" ref="projectService" /> - </bean> <bean id="globalPropertiesBean" class="kieker.webgui.web.beans.application.GlobalPropertiesBean"> <property name="themeCookieName" value="${kieker.webgui.config.lookAndFeel.cookieName}"/> <property name="projectOverviewPage" value="${kieker.webgui.page.projectOverview}"/> @@ -69,47 +54,8 @@ </map> </property> </bean> - <bean id="userDAO" class="kieker.webgui.persistence.impl.DerbyUserDAOImpl" init-method="initialize" destroy-method="destroy"> - <property name="dataSource" ref="userDataSource"/> - </bean> - - <!-- The session scoped beans. --> - <bean id="userBean" init-method="initialize" class="kieker.webgui.web.beans.session.UserBean" scope="session"> - <property name="globalPropertiesBean" ref="globalPropertiesBean"/> - </bean> - - <!-- The view scoped beans. --> - <bean id="currentAnalysisEditorBean" class="kieker.webgui.web.beans.view.CurrentAnalysisEditorBean" scope="view"> - <property name="globalPropertiesBean" ref="globalPropertiesBean"/> - <property name="projectService" ref="projectService" /> - <property name="projectsBean" ref="projectsBean" /> - <property name="currentAnalysisEditorGraphBean" ref="currentAnalysisEditorGraphBean" /> - <property name="userBean" ref="userBean" /> - </bean> - <bean id="currentAnalysisEditorGraphBean" class="kieker.webgui.web.beans.view.CurrentAnalysisEditorGraphBean" scope="view"/> - <bean id="currentCockpitBean" class="kieker.webgui.web.beans.view.CurrentCockpitBean" scope="view"> - <property name="projectsBean" ref="projectsBean"/> - <property name="projectService" ref="projectService" /> - </bean> - <bean id="currentCockpitEditorBean" class="kieker.webgui.web.beans.view.CurrentCockpitEditorBean" scope="view"> - <property name="globalPropertiesBean" ref="globalPropertiesBean"/> - <property name="projectService" ref="projectService" /> - <property name="projectsBean" ref="projectsBean"/> - </bean> - <bean id="currentControllerBean" class="kieker.webgui.web.beans.view.CurrentControllerBean" scope="view"> - <property name="projectsBean" ref="projectsBean"/> - <property name="projectService" ref="projectService" /> - </bean> - <bean id="currentProjectOverviewBean" class="kieker.webgui.web.beans.view.CurrentProjectOverviewBean" scope="view" init-method="initialialize"> - <property name="projectsBean" ref="projectsBean"/> - </bean> - <bean id="currentUserManagementBean" class="kieker.webgui.web.beans.view.CurrentUserManagementBean" init-method="initialialize" scope="view"> - <property name="userService" ref="userService"/> - </bean> - <!-- The request scoped beans. --> - <bean id="stringBean" class="kieker.webgui.web.beans.request.StringBean" scope="request"/> - <bean id="newUserBean" class="kieker.webgui.web.beans.request.NewUserBean" scope="request"/> + <context:component-scan base-package="kieker.webgui"/> <!-- The enums. --> <util:constant id="ROLE_USER" static-field="kieker.webgui.domain.User.Role.ROLE_USER"/> diff --git a/Kieker.WebGUI/src/main/webapp/WEB-INF/spring-common-config.xml b/Kieker.WebGUI/src/main/webapp/WEB-INF/spring-common-config.xml index b3006a95..3ea30317 100644 --- a/Kieker.WebGUI/src/main/webapp/WEB-INF/spring-common-config.xml +++ b/Kieker.WebGUI/src/main/webapp/WEB-INF/spring-common-config.xml @@ -7,7 +7,7 @@ <property name="scopes"> <map> <entry key="view"> - <bean class="kieker.webgui.common.util.ViewScope"/> + <bean class="kieker.webgui.common.ViewScope"/> </entry> </map> </property> -- GitLab