Source Code Cross Referenced for SessionUtil.java in  » J2EE » Enhydra-Application-Framework » com » lutris » appserver » server » sessionEnhydra » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Application Framework » com.lutris.appserver.server.sessionEnhydra 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         * 
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         * 
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         * 
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         * 
019:         * Contributor(s):
020:         * 
021:         * $Id: SessionUtil.java,v 1.2 2006-06-15 13:44:07 sinisa Exp $
022:         */
023:
024:        package com.lutris.appserver.server.sessionEnhydra;
025:
026:        import java.util.Enumeration;
027:
028:        import com.lutris.appserver.server.session.Session;
029:        import com.lutris.appserver.server.session.SessionData;
030:        import com.lutris.appserver.server.session.SessionException;
031:        import com.lutris.appserver.server.session.SessionManager;
032:        import com.lutris.appserver.server.user.User;
033:
034:        /**
035:         * Static methods that can be used by applications to manage sessions.
036:         *
037:         * @version	$Revision: 1.2 $
038:         * @author	Kyle Clark
039:         */
040:        public class SessionUtil {
041:
042:            /**
043:             * Prevent instantiation.
044:             */
045:            private SessionUtil() {
046:            }
047:
048:            /**
049:             * Logs a user in.
050:             *
051:             * @param user the user to log in.
052:             * @param session the session to associated with the user.
053:             * @param multiple if true the user can have more than one session
054:             *   associated with him/her.  If false, all previous sessions
055:             *   associated with the user will be removed.
056:             * @exception SessionException if an error occurs.
057:             */
058:            public static void logIn(User user, Session session,
059:                    boolean multiple) throws SessionException {
060:                SessionManager mgr = session.getSessionManager();
061:                synchronized (mgr) {
062:                    if (!multiple) {
063:                        Enumeration e = mgr.getSessionKeys(user);
064:                        while (e.hasMoreElements()) {
065:                            String key = (String) e.nextElement();
066:                            mgr.deleteSession(key);
067:                        }
068:                    }
069:                    session.setUser(user);
070:                }
071:            }
072:
073:            /**
074:             * Dissasociates the user from the session and all
075:             * references to the session are deleted from the
076:             * session manager.
077:             *
078:             * @param session the session associated with the user.
079:             * @exception SessionException if an error occurs.
080:             */
081:            public static void logOut(Session session) throws SessionException {
082:                if (session != null) {
083:                    SessionManager mgr = session.getSessionManager();
084:                    mgr.deleteSession(session);
085:                }
086:            }
087:
088:            /**
089:             * If a user attempts to login but has not logged
090:             * out from a previous session then this method can be used
091:             * to copy data from the previous session into this session
092:             * and to log out the previous session.
093:             *
094:             * @param user the user
095:             * @param session the session
096:             * @return true if the user was already logged in and the session
097:             *   has been resumed.
098:             * @exception SessionException
099:             *   if an error occurs.
100:             */
101:            public static boolean resumeLogIn(User user, Session session)
102:                    throws SessionException {
103:                SessionManager mgr = session.getSessionManager();
104:                try {
105:                    synchronized (mgr) {
106:                        Enumeration e = mgr.getSessionKeys(user);
107:                        if (e.hasMoreElements()) {
108:                            String key = (String) e.nextElement();
109:                            if (e.hasMoreElements()) {
110:                                // More than one login - we don't deal with it.
111:                                return false;
112:                            }
113:                            Session oldSession = mgr.getSession(Thread
114:                                    .currentThread(), key);
115:                            SessionData dataSrc = oldSession.getSessionData();
116:                            SessionData dataDst = session.getSessionData();
117:                            // Copy src to dst
118:                            String[] k = dataSrc.keys();
119:                            for (int i = 0; i < k.length; i++) {
120:                                dataDst.set(k[i], dataSrc.get(k[i]));
121:                            }
122:                            SessionUtil.logIn(user, session, false);
123:                            return true;
124:                        }
125:                    }
126:                } catch (SessionException e) {
127:                    throw e;
128:                } catch (Exception e) {
129:                    throw new SessionException(e);
130:                }
131:                return false;
132:            }
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.