1 9 package org.jboss.portal.core.impl.user; 10 11 import java.util.Map ; 12 import java.util.HashMap ; 13 import java.util.Date ; 14 import java.io.Serializable ; 15 import java.io.ObjectInputStream ; 16 import java.io.IOException ; 17 import java.io.ObjectOutputStream ; 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 ; 26 import javax.servlet.http.HttpSessionBindingEvent ; 27 28 32 public class UserContextImpl implements UserContext, Serializable , HttpSessionBindingListener 33 { 34 35 private static final Logger log = Logger.getLogger(UserContextImpl.class); 36 37 private boolean signedIn; 38 private Map contexts; 39 40 42 private transient Map informations; 43 private transient UserImpl user; 44 private transient PreferenceStore store; 45 46 public UserContextImpl() 47 { 48 this.contexts = new HashMap (); 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 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 getInformations() 98 { 99 return informations; 100 } 101 102 private void readObject(ObjectInputStream in) throws ClassNotFoundException , IOException 103 { 104 if (log.isDebugEnabled()) 105 { 106 log.debug("Read object"); 107 } 108 in.defaultReadObject(); 109 } 110 111 private void writeObject(ObjectOutputStream out) throws IOException 112 { 113 if (log.isDebugEnabled()) 114 { 115 log.debug("Write object"); 116 } 117 out.defaultWriteObject(); 118 } 119 120 public void valueBound(HttpSessionBindingEvent event) 121 { 122 } 123 124 public void valueUnbound(HttpSessionBindingEvent event) 125 { 126 if (user != null) 128 { 129 user.setLastVisitDate(new Date ()); 130 } 131 } 132 } 133 | Popular Tags |