KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > impl > user > UserContextImpl


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.impl.user;
10
11 import java.util.Map JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Date JavaDoc;
14 import java.io.Serializable JavaDoc;
15 import java.io.ObjectInputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.ObjectOutputStream JavaDoc;
18
19 import org.jboss.portal.server.ServerObject;
20 import org.jboss.portal.server.plugins.preferences.PreferenceStore;
21 import org.jboss.portal.server.user.ServerObjectContext;
22 import org.jboss.portal.server.user.UserContext;
23 import org.apache.log4j.Logger;
24
25 import javax.servlet.http.HttpSessionBindingListener JavaDoc;
26 import javax.servlet.http.HttpSessionBindingEvent JavaDoc;
27
28 /**
29  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
30  * @version $Revision: 1.6 $
31  */

32 public class UserContextImpl implements UserContext, Serializable JavaDoc, HttpSessionBindingListener JavaDoc
33 {
34
35    private static final Logger log = Logger.getLogger(UserContextImpl.class);
36
37    private boolean signedIn;
38    private Map JavaDoc contexts;
39
40    // Never serialized
41

42    private transient Map JavaDoc informations;
43    private transient UserImpl user;
44    private transient PreferenceStore store;
45
46    public UserContextImpl()
47    {
48       this.contexts = new HashMap JavaDoc();
49    }
50
51    public boolean isSignedIn()
52    {
53       return signedIn;
54    }
55
56    public void setSignedIn(boolean signedIn)
57    {
58       this.signedIn = signedIn;
59    }
60
61    public void setUser(UserImpl user)
62    {
63       this.user = user;
64    }
65
66    public UserImpl getUser()
67    {
68       return user;
69    }
70
71    public void setInformations(Map JavaDoc informations)
72    {
73       this.informations = informations;
74    }
75
76    public void setPreferenceStore(PreferenceStore store)
77    {
78       this.store = store;
79    }
80
81    public ServerObjectContext getContext(ServerObject serverObject)
82    {
83       ServerObjectContext ctx = (ServerObjectContext)contexts.get(serverObject.getID());
84       if (ctx == null)
85       {
86          ctx = serverObject.createContext();
87          contexts.put(serverObject.getID(), ctx);
88       }
89       return ctx;
90    }
91
92    public PreferenceStore getPreferenceStore()
93    {
94       return store;
95    }
96
97    public Map JavaDoc getInformations()
98    {
99       return informations;
100    }
101
102    private void readObject(ObjectInputStream JavaDoc in) throws ClassNotFoundException JavaDoc, IOException JavaDoc
103    {
104       if (log.isDebugEnabled())
105       {
106          log.debug("Read object");
107       }
108       in.defaultReadObject();
109    }
110
111    private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc
112    {
113       if (log.isDebugEnabled())
114       {
115          log.debug("Write object");
116       }
117       out.defaultWriteObject();
118    }
119
120    public void valueBound(HttpSessionBindingEvent JavaDoc event)
121    {
122    }
123
124    public void valueUnbound(HttpSessionBindingEvent JavaDoc event)
125    {
126       // Implement the last login date feature
127
if (user != null)
128       {
129          user.setLastVisitDate(new Date JavaDoc());
130       }
131    }
132 }
133
Popular Tags