KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > presentation > ProjectManagementSessionData


1 package projectmanagement.presentation;
2
3 import projectmanagement.spec.employee.Employee;
4
5 /**
6  * Object that will be held in session data. This should
7  * be the only object held there. Methods should be called
8  * on this object to set and get data.
9  *
10  * @author Sasa Bojanic
11  * @version 1.0
12  */

13 public class ProjectManagementSessionData implements java.io.Serializable JavaDoc {
14
15    /**
16     * Hash key to save session data for the ProjectManagement app in the Session
17     */

18    public static final String JavaDoc SESSION_KEY = "ProjectManagementSessionData";
19
20    protected Employee myUser = null;
21    protected String JavaDoc userMessage = null;
22    protected boolean isAdmin=false;
23
24    /**
25     * Sets the employee object
26     *
27     * @param theEmployee the employee object
28     */

29    public void setUser(Employee theEmployee) {
30       this.myUser = theEmployee;
31    }
32
33    /**
34     * Gets the employee object
35     *
36     * @return employee
37     */

38    public Employee getUser() {
39       return this.myUser;
40    }
41
42    /**
43     * Method to remove the current user from the session
44     */

45    public void removeUser() {
46       this.myUser = null;
47    }
48
49    /**
50     * Sets the message
51     *
52     * @param msg the message to be set
53     */

54    public void setUserMessage(String JavaDoc msg) {
55       this.userMessage = msg;
56    }
57
58    public void setAdmin (boolean isAdmin) {
59       this.isAdmin=isAdmin;
60    }
61
62    public int getAuthLevel() {
63       if (isAdmin) {
64          return 2;
65       } else if (myUser!=null) {
66          return myUser.getAuthLevel();
67       } else {
68          return 0;
69       }
70    }
71
72    /**
73     * Retrieve the most recent user message and then clear it so no
74     * other app tries to use it.
75     */

76    public String JavaDoc getAndClearUserMessage() {
77       String JavaDoc msg = this.userMessage;
78       this.userMessage = null;
79       return msg;
80    }
81 }
82
Popular Tags