Skip to content
Snippets Groups Projects
Commit 61630b19 authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Added some comments; minor refactoring.

parent bee3456d
No related branches found
No related tags found
No related merge requests found
......@@ -26,38 +26,41 @@ import javax.faces.bean.ManagedBean;
import kieker.webgui.beans.IProjectBean;
/**
* This bean is a helper class to change for example from the analysis editor to the cockpit. It clears the source bean (by using the clear-method) and sets the
* project name of the new destination bean, returning its return value.
* The {@link ForwardBean} is a helper class for navigation purposes only. It allows to navigate between specific pages in a generic matter and is furthermore the
* reason for the existence of the interface {@link IProjectBean}. The bean has also no properties or fields which could be modified.<br>
* The bean is an application scoped bean, as there is in its functionality as a utility bean no reason to have more than one instance.
*
* @author Nils Christian Ehmke
* @version 1.0
*/
@ManagedBean
@ApplicationScoped
public class ForwardBean {
public final class ForwardBean {
/**
* Default constructor.
* Default constructor. <b>Do not use this constructor. This bean is JSF managed.</b>
*/
public ForwardBean() {
// No code necessary.
}
/**
* Moves from one page to another. This method clears the source bean (by using the clear-method) and sets the
* project name of the new destination bean, returning its return value.
* This method allows the navigation from one page to another, by saving the project name of the source bean, cleaning the source bean and then setting the
* project name of the destination bean. This method then returns the return value of the setter-method of the destination bean. This is usually the next page of
* the corresponding bean and can be used to redirect the user.
*
* @param sourceBean
* The source bean.
* The bean which will be used to get the project name and will be cleared in this method afterwards.
* @param destinationBean
* The destination bean.
* The destination bean whose project name will be set to the saved value and whose return value will be returned.
* @return The return value of the destination bean.
*/
public String forward(final IProjectBean sourceBean, final IProjectBean destinationBean) {
// Remember the project name and clean the source bean
final String projectName = sourceBean.getProjectName();
sourceBean.clearProject();
// Set the project of the destination bean and return its return value
return destinationBean.setProject(projectName);
}
}
......@@ -43,8 +43,11 @@ import kieker.webgui.common.FSManager;
import kieker.webgui.common.exception.ProjectAlreadyExistingException;
/**
* This bean contains all application wide available projects. It provides methods to create and manage the projects. Synchronization is achieved in the
* {@link FSManager}.
* The {@link ProjectsBean} is a JSF managed bean to manage a list with all application wide available projects. It provides methods to receive this list as well as
* methods to add, create, rename, open and copy projects. Furthermore the state of existing projects (like the timestamp or the state of the analysis) can be
* received via this bean. In order to realize a good abstraction, this bean should be used for any access to the projects. The necessary synchronization is achieved
* in the {@link FSManager}.<br>
* As this bean contains the whole list of the available projects, it is application scoped. There is no reason for multiple instances of this class.
*
* @author Nils Christian Ehmke
* @version 1.0
......@@ -54,23 +57,23 @@ import kieker.webgui.common.exception.ProjectAlreadyExistingException;
public final class ProjectsBean {
/**
* This is the log for errors, exceptions etc.
* This is the log instance which is used by all instances of the {@link ProjectsBean}. All error and exceptions will be logged with this instance.
*/
private static final Log LOG = LogFactory.getLog(ProjectsBean.class);
/**
* This list contains all available projects by name.
* This list contains all available projects by name. It is synchronized as a simple synchronized list, as the fine grained synchronization isn't necessary here.
*/
private final List<String> projects = Collections.synchronizedList(new ArrayList<String>());
/**
* Creates a new instance of this class.
* Default constructor. <b>Do not use this constructor. This bean is JSF managed.</b>
*/
public ProjectsBean() {
// No code necessary
}
/**
* Initializes this bean.
* This method does some initialization work after construction. <b>Do not call this method. The method is managed by the class loader.</b>
*/
@PostConstruct
protected void init() {
......@@ -79,11 +82,15 @@ public final class ProjectsBean {
}
/**
* Adds a new project to this application if possible. It informs the current user (via the growl-component of PrimeFaces) whether the creation was successful or
* not.
* This method adds a new project with the given name to the application if this is possible. In either case (this means if the project has been created, if he
* project could not be created for any reason) the user will be informed via the growl component. In other words: A message will be delivered within the current
* context.The creation of a new project means in this context that a directory with its name will be created and that an empty but valid kax-file will be
* produced. After creating the project (provided that he creation was successful) the projects list of the "calling" {@link CurrentProjectOverviewBean} will be
* updated.<br>
* If something should go wrong, no exception will be thrown. Everything is caught if necessary.
*
* @param project
* The name of the project to be added.
* The name for the new project which should be added to the application.
*/
public void addProject(final String project) {
try {
......@@ -94,10 +101,7 @@ public final class ProjectsBean {
// Inform the user
ProjectsBean.showMessage(FacesMessage.SEVERITY_INFO, "Project created.");
// Update the list of the "calling" bean
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
final CurrentProjectOverviewBean bean = (CurrentProjectOverviewBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null,
"currentProjectOverviewBean");
bean.updateLists();
CurrentProjectOverviewBean.getCurrentInstance().updateLists();
} catch (final IOException ex) {
ProjectsBean.LOG.error("An error occured while creating the project.", ex);
ProjectsBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while creating the project.");
......@@ -108,11 +112,11 @@ public final class ProjectsBean {
}
/**
* This method can be used to open an existing project. This means that the current state of the project on the file system is loaded into an instance of {@link}
* MIProject}. This instance can be modified at will and for example later saved by the {@link FSManager}.
* This method can be used to open an already existing project. This means that the current state of the project on the file system is loaded into an instance of
* {@link MIProject}. This instance can be modified at will and for example later saved by the {@link FSManager}.
*
* @param project
* The name of the project to be saved.
* The name of the project to be opened.
* @return Either the model instance if the loading was successful or null otherwise. In the latter case, the user will be informed via the growl-component.
*/
public MIProject openProject(final String project) {
......@@ -125,47 +129,32 @@ public final class ProjectsBean {
}
}
/**
* This method renames the given project. For other threads active on this project it looks like the project has been removed in the meantime. If something goes
* wrong, the user will be informed via the growl-component.
*
* @param projectName
* The old name of the project.
* @param newName
* The new name of the project.
*/
public void renameProject(final String projectName, final String newName) {
try {
FSManager.getInstance().renameProject(projectName, newName);
} catch (final IOException ex) {
ProjectsBean.LOG.error("An error occured while renaming the project.", ex);
ProjectsBean.showMessage(FacesMessage.SEVERITY_ERROR, "An error occured while renaming the project.");
} catch (final ProjectAlreadyExistingException ex) {
ProjectsBean.LOG.info("A project with the same name exists already.", ex);
ProjectsBean.showMessage(FacesMessage.SEVERITY_WARN, "A project with the same name exists already.");
}
}
/**
* This method can be used to get the current time stamp of a given project as a human readable date. If the project doesn't exist or the time stamp would be
* invalid, the date of 0 is returned.
* invalid "N/A" will be returned.
*
* @param project
* The project whose time stamp should be collected.
* @return The human readable time stamp of the project.
*/
public String getCurrTimeStamp(final String project) {
// Get the current time stamp of the project...
// Get the current time stamp of the project
final long timeStamp = FSManager.getInstance().getCurrTimeStamp(project);
// ...and make sure the user can read it.
if (timeStamp == 0) {
// We can assume that something went wrong
return "N/A";
}
// Convert the stamp into a human readable string.
return new Date(timeStamp).toString();
}
/**
* This method delivers all available projects as a list of string.
* This method delivers all available projects as a list of string. The list itself is just a copy and can be modified as will. Keep in mind that this means also
* that every call to this method will create a new copy.
*
* @return All currently available projects. The list is just a copy.
* @return All currently available projects as a copied and modificable list.
*/
public List<String> getProjects() {
synchronized (this.projects) {
......@@ -197,11 +186,12 @@ public final class ProjectsBean {
}
/**
* Delivers the one and only bean instance of this class.
* Delivers the one and only bean instance of the {@link ProjectsBean}.
*
* @return The bean instance.
*/
public static ProjectsBean getInstance() {
// Get the resolver and find the projects bean via name
final ELResolver el = FacesContext.getCurrentInstance().getApplication().getELResolver();
return (ProjectsBean) el.getValue(FacesContext.getCurrentInstance().getELContext(), null, "projectsBean");
}
......
......@@ -29,7 +29,9 @@ import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
/**
* This bean contains the application wide available themes (Look and Feels). It is not possible to import new themes during runtime.
* The {@link ThemeSwitcherBean} is responsible for holding a list with all application wide available themes (look and feels). As this is a static list, it is not
* possible to import new themes during the runtime.<br>
* As the list with the available themes is a static list, this class is an application scoped JSF managed bean.
*
* @author Nils Christian Ehmke
* @version 1.0
......@@ -41,10 +43,10 @@ public final class ThemeSwitcherBean {
/**
* A map containing all available themes.
*/
private final Map<String, String> themes = new TreeMap<String, String>(); // NOPMD (No concurrent access)
private final Map<String, String> themes = new TreeMap<String, String>();
/**
* Creates a new instance of this class.
* Default constructor. <b>Do not use this constructor. This bean is JSF managed.</b>
*/
public ThemeSwitcherBean() {
// No code necessary
......@@ -60,7 +62,8 @@ public final class ThemeSwitcherBean {
}
/**
* Initializes the bean. If one wants to add new themes to the program, this is the right place.
* This method does some initialization work after construction. <b>Do not call this method. The method is managed by the class loader.</b> If one wants to add
* new themes to the program, this is the right place.
*/
@PostConstruct
protected void init() {
......
......@@ -24,7 +24,9 @@ import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
/**
* This simple bean can be used to store a string. It can only be used for a single request.
* 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>
* For technical reasons this bean is a request scoped bean.
*
* @author Nils Christian Ehmke
* @version 1.0
......@@ -39,7 +41,7 @@ public class StringBean {
private String string;
/**
* Creates a new instance of this bean and initializes it with an empty string.
* Creates a new instance of this bean and initializes it with an empty string. <b>Do not use this constructor. This bean is JSF managed.</b>
*/
public StringBean() {
this.string = "";
......@@ -66,7 +68,7 @@ public class StringBean {
/**
* This method verifies whether the given object is an instance of {@link java.lang.String} or not. This is necessary due to the fact that the
* 'instanceof'-command has not yet been implemented in JSF.
* <i>instanceof</i>-command has not yet been implemented in JSF.
*
* @param object
* The object to be verified.
......@@ -76,18 +78,6 @@ public class StringBean {
return object instanceof String;
}
/**
* Modifies the given string so that it can be used as an ID. In other words: It removes all space characters. It is usually used to convert the 'address' of an
* object into an unique ID. It is not guaranteed that the result will be a valid ID in other cases.
*
* @param str
* The string to be modified.
* @return The given string without space characters.
*/
public String stringToID(final String str) {
return str.replace(" ", "");
}
/**
* Shortens a given name. If the name is longer than the given number of characters, only the first maxChar - 3 characters of the string will be used and the
* last three will be replaced with dots.
......
......@@ -30,8 +30,10 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
/**
* This bean contains the current user theme (look and feel) of the (session) user. The default value is the "glass-x"-theme, if no other value can be find within
* the parameters of the faces context or in the cookies of the user.
* The {@link CurrentThemeBean} contains the current user theme (look and feel) of the (session) user. The default value is the "glass-x"-theme, if no other value
* can be find within the parameters of the faces context or in the cookies of the user. Every change of the theme will also result in storing the new theme within
* the cookies of the user.<br>
* As the theme can be chosen by every user on his own, this class is a session scoped bean.
*
* @author Nils Christian Ehmke
*
......@@ -58,16 +60,25 @@ public final class CurrentThemeBean implements Serializable {
*/
private static final String KEY_THEME = "theme";
/**
* The current theme.
* The current theme for this session.
*/
private String theme;
/**
* Creates a new instance of this class.
* Default constructor. <b>Do not use this constructor. This bean is JSF managed.</b>
*/
public CurrentThemeBean() {
this.setDefaultTheme();
this.searchThemeInCookies();
}
/**
* This method sets the current theme of the user to the default theme. This beans that the bean tries to find the name of the theme within the parameters for
* primefaces. If this fail, the default theme will be used.
*/
private void setDefaultTheme() {
// Get the parameters within the current context.
final Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); // NOPMD (No concurrent access)
final Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
// Try to find the default theme within the parameters.
if (params.containsKey(CurrentThemeBean.KEY_THEME)) {
this.theme = params.get(CurrentThemeBean.KEY_THEME);
......@@ -75,10 +86,14 @@ public final class CurrentThemeBean implements Serializable {
// Use the default theme.
this.theme = CurrentThemeBean.DEFAULT_THEME;
}
}
/**
* This method tries to search the theme within the cookies of the user.
*/
private void searchThemeInCookies() {
// Try to find the cookie for the theme.
final Map<String, Object> cookies = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap(); // NOPMD (No concurrent access)
final Map<String, Object> cookies = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap();
if (cookies.containsKey(CurrentThemeBean.KEY_COOKIE_THEME)) {
this.theme = ((Cookie) cookies.get(CurrentThemeBean.KEY_COOKIE_THEME)).getValue();
}
......@@ -89,19 +104,20 @@ public final class CurrentThemeBean implements Serializable {
*
* @return The currently used theme.
*/
public final String getTheme() {
public String getTheme() {
synchronized (this) {
return this.theme;
}
}
/**
* Sets the value of this bean.
* Sets the value of this bean. This beans that the stored theme will be set to the new value and that the method will try to store the name of this theme within
* the cookies of the user.
*
* @param theme
* The new theme to be stored within this instance.
*/
public final void setTheme(final String theme) {
public void setTheme(final String theme) {
synchronized (this) {
this.theme = theme;
......
......@@ -21,16 +21,15 @@
package kieker.webgui.beans.session;
import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;
import javax.annotation.PreDestroy;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import kieker.webgui.common.Global;
/**
* This bean will later contain information about the user of this session (like user name and authorization). For the moment every user will be a guest user.
* This bean contains information about the user of this session (like user name and authorization). It provides method to log into the application.<br>
* This class is a JSF managed bean with session scope. This means also that it is possible to login the same user multiple times.
*
* @author Nils Christian Ehmke
* @version 1.0
......@@ -43,28 +42,16 @@ public final class UserBean implements Serializable {
* The serial version UID.
*/
private static final long serialVersionUID = 3942693805646862667L;
/**
* The counter to get a number for the current user and to differ the sessions in test purposes.
*/
private static final AtomicLong GUEST_COUNTER = new AtomicLong();
/**
* This field contains the name of the user.
*/
private String userName;
/**
* Creates a new instance of this class. The user name is set to "Guest".
* Default constructor. <b>Do not use this constructor. This bean is JSF managed.</b>
*/
public UserBean() {
this.userName = "Guest #" + UserBean.GUEST_COUNTER.getAndIncrement();
}
/**
* This method should only be called automatically by the JVM just before the object is destroyed.
*/
@PreDestroy
protected void destroy() {
UserBean.GUEST_COUNTER.decrementAndGet();
this.userName = "Guest";
}
/**
......@@ -87,7 +74,7 @@ public final class UserBean implements Serializable {
}
/**
* Tries to login.
* Tries to login. If this has been successful the page of the project overview will be returned.
*
* @return The new page.
*/
......
......@@ -106,6 +106,15 @@ public class CurrentProjectOverviewBean {
this.projects = bean.getProjects();
}
public static CurrentProjectOverviewBean getCurrentInstance() {
// Get both the context and the resolver
final FacesContext facesContext = FacesContext.getCurrentInstance();
final ELResolver el = facesContext.getApplication().getELResolver();
// Get the current bean instance by name
return (CurrentProjectOverviewBean) el.getValue(facesContext.getELContext(), null, "currentProjectOverviewBean");
}
/**
* This method delivers all available projects as a list of string.
*
......
......@@ -21,30 +21,31 @@
package kieker.webgui.common;
/**
* This class contains global variables and constants.
* The class {@link Global} is a utility class with no properties, but global accessible constants. As there are no non-static fields or methods are available, it
* cannot be instantiated. There are also no static fields available which can be modified during runtime.
*
* @author Nils Christian Ehmke
* @version 1.0
*/
public final class Global {
/**
* This is the page used for the redirection to the controller page.
* This is the name of the page for the analysis controller. The page name has been modified to use a redirect of the browser.
*/
public static final String PAGE_ANALYSIS_CONTROLLER = "Controller.xhtml?faces-redirect=true";
/**
* This is the page used for the redirection to the overview.
* This is the name of the page for the project overview. The page name has been modified to use a redirect of the browser.
*/
public static final String PAGE_PROJECT_OVERVIEW = "ProjectOverview.xhtml?faces-redirect=true";
/**
* This is the page used for the redirection to the cockpit.
* This is the name of the page for the cockpit. The page name has been modified to use a redirect of the browser.
*/
public static final String PAGE_ANALYSIS_COCKPIT = "Cockpit.xhtml?faces-redirect=true";
/**
* This is the page used for the redirection to the cockpit editor.
* This is the name of the page for the cockpit editor. The page name has been modified to use a redirect of the browser.
*/
public static final String PAGE_ANALYSIS_VIEW_WORK_SPACE = "CockpitEditor.xhtml?faces-redirect=true";
/**
* This is the page used for the redirection to the analysis editor.
* This is the name of the page for the analysis editor. The page name has been modified to use a redirect of the browser.
*/
public static final String PAGE_PROJECT_WORK_SPACE = "AnalysisEditor.xhtml?faces-redirect=true";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment