KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > session > SessionTool


1 package org.apache.turbine.services.session;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.Collection JavaDoc;
20 import javax.servlet.http.HttpSession JavaDoc;
21
22 import org.apache.turbine.om.security.User;
23 import org.apache.turbine.services.pull.ApplicationTool;
24
25 /**
26  * A pull tool for accessing the SessionService from a velocity template.
27  *
28  * @author <a HREF="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
29  * @version $Id: SessionTool.java,v 1.3.2.2 2004/05/20 03:06:50 seade Exp $
30  */

31 public class SessionTool
32         implements ApplicationTool
33 {
34     public void init(Object JavaDoc o)
35     {
36     }
37
38     public void refresh()
39     {
40     }
41
42     /**
43      * Gets a list of the active sessions
44      *
45      * @return List of HttpSession objects
46      */

47     public Collection JavaDoc getActiveSessions()
48     {
49         return TurbineSession.getActiveSessions();
50     }
51
52     /**
53      * Adds a session to the current list. This method should only be
54      * called by the listener.
55      *
56      * @param session Session to add
57      */

58     public void addSession(HttpSession JavaDoc session)
59     {
60         TurbineSession.addSession(session);
61     }
62
63     /**
64      * Removes a session from the current list. This method should only be
65      * called by the listener.
66      *
67      * @param session Session to remove
68      */

69     public void removeSession(HttpSession JavaDoc session)
70     {
71         TurbineSession.removeSession(session);
72     }
73
74     /**
75      * Determines if a given user is currently logged in. The actual
76      * implementation of the User object must implement the equals()
77      * method. By default, Torque based objects (liek TurbineUser)
78      * have an implementation of equals() that will compare the
79      * result of getPrimaryKey().
80      *
81      * @param user User to check for
82      * @return true if the user is logged in on one of the
83      * active sessions.
84      */

85     public boolean isUserLoggedIn(User user)
86     {
87         return TurbineSession.isUserLoggedIn(user);
88     }
89
90     /**
91      * Gets a collection of all user objects representing the users currently
92      * logged in. This will exclude any instances of anonymous user that
93      * Turbine will use before the user actually logs on.
94      *
95      * @return collection of org.apache.turbine.om.security.User objects
96      */

97     public Collection JavaDoc getActiveUsers()
98     {
99         return TurbineSession.getActiveUsers();
100     }
101
102     /**
103      * Gets the User object of the the specified HttpSession.
104      *
105      * @param session
106      * @return
107      */

108     public User getUserFromSession(HttpSession JavaDoc session)
109     {
110         return TurbineSession.getUserFromSession(session);
111     }
112
113     /**
114      * Get a collection of all session on which the given user
115      * is logged in.
116      *
117      * @param user the user
118      * @return Collection of HtttSession objects
119      */

120     public Collection JavaDoc getSessionsForUser(User user)
121     {
122         return TurbineSession.getSessionsForUser(user);
123     }
124 }
125
Popular Tags