View Javadoc

1   /*
2    * Copyright (c) 2005 Regents of the University of California (Regents). Created
3    * by TELS, Graduate School of Education, University of California at Berkeley.
4    *
5    * This software is distributed under the GNU Lesser General Public License, v2.
6    *
7    * Permission is hereby granted, without written agreement and without license
8    * or royalty fees, to use, copy, modify, and distribute this software and its
9    * documentation for any purpose, provided that the above copyright notice and
10   * the following two paragraphs appear in all copies of this software.
11   *
12   * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
13   * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
14   * PURPOSE. THE SOFTWAREAND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
15   * HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
16   * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17   *
18   * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
19   * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
20   * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
21   * REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22   */
23  package net.sf.sail.core.session;
24  
25  import java.util.Collection;
26  import java.util.Collections;
27  import java.util.HashSet;
28  import java.util.Properties;
29  import java.util.Set;
30  
31  import net.sf.sail.core.beans.SessionContext;
32  import net.sf.sail.core.beans.event.SessionEventListener;
33  import net.sf.sail.core.beans.service.SessionService;
34  import net.sf.sail.core.entity.User;
35  import net.sf.sail.core.uuid.SessionUuid;
36  
37  
38  public class DefaultSessionService implements SessionService {
39  
40  	SessionContext session;
41  
42  	Set<User> users = new HashSet<User>();
43  	Properties properties = new Properties();
44  	
45  	public DefaultSessionService(SessionContext session) {
46  		this.session = session;
47  	}
48  
49  	public void userRequestsTermination() {
50  		session.tryToTerminate();
51  	}
52  
53  	public void addSessionEventListener(SessionEventListener sel) {
54  		session.addSessionEventListener(sel);
55  	}
56  
57  	public Collection<User> getUsers() {
58  		return Collections.unmodifiableCollection(users);
59  	}
60  
61  	public void addUser(User user) {
62  		users.add(user);
63  	}
64  
65  	public void removeUser(User user) {
66  		users.remove(user);
67  	}
68  
69  	public SessionUuid getSessionId() {
70  		return session.getSessionId();
71  	}
72  	
73  	public String getProperty(String key, String def) {
74  		return properties.getProperty(key, def);
75  	}
76  	
77  	public void setProperty(String key, String value) {
78  		properties.setProperty(key, value);
79  	}
80  }