Source Code Cross Referenced for Echo2SessionAspect.java in  » Web-Framework » roma-webwizard » org » romaframework » aspect » session » echo2 » 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 » Web Framework » roma webwizard » org.romaframework.aspect.session.echo2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.romaframework.aspect.session.echo2;
018:
019:        import java.util.Collection;
020:        import java.util.List;
021:        import java.util.Locale;
022:        import java.util.Map;
023:        import java.util.WeakHashMap;
024:
025:        import javax.servlet.http.HttpServletRequest;
026:        import javax.servlet.http.HttpSession;
027:        import javax.servlet.http.HttpSessionEvent;
028:        import javax.servlet.http.HttpSessionListener;
029:
030:        import nextapp.echo2.webrender.Connection;
031:        import nextapp.echo2.webrender.WebRenderServlet;
032:
033:        import org.apache.commons.logging.Log;
034:        import org.apache.commons.logging.LogFactory;
035:        import org.romaframework.aspect.session.SessionAspectAbstract;
036:        import org.romaframework.aspect.session.SessionInfo;
037:        import org.romaframework.aspect.session.SessionListener;
038:        import org.romaframework.aspect.view.echo2.Echo2ApplicationContext;
039:        import org.romaframework.core.flow.Controller;
040:
041:        /**
042:         * Uses Echo2 to identify user session aspects by current thread.
043:         * 
044:         * @author Luca Garulli (luca.garulli@assetdata.it)
045:         */
046:        public class Echo2SessionAspect extends SessionAspectAbstract implements 
047:                HttpSessionListener {
048:
049:            private Map<HttpSession, SessionInfo> sessions;
050:            private static Log log = LogFactory
051:                    .getLog(Echo2SessionAspect.class);
052:
053:            public Echo2SessionAspect() {
054:                super ();
055:                sessions = new WeakHashMap<HttpSession, SessionInfo>();
056:            }
057:
058:            public SessionInfo getActiveSessionInfo() {
059:                // GET THREAD'S CURRENT CONTEXT
060:                Connection connection = WebRenderServlet.getActiveConnection();
061:
062:                if (connection == null)
063:                    return null;
064:
065:                // RETURN SESSION INFO, IF ANY
066:                return sessions.get(connection.getRequest().getSession());
067:            }
068:
069:            public SessionInfo getSession(Object iSystemSession) {
070:                return sessions.get(iSystemSession);
071:            }
072:
073:            public SessionInfo addSession(Object iSession) {
074:                // CREATE ACTIVE SESSION OBJECT
075:                SessionInfo activeSession = new SessionInfo(iSession);
076:
077:                HttpServletRequest req = WebRenderServlet.getActiveConnection()
078:                        .getRequest();
079:
080:                activeSession.setSystemSession(req.getSession());
081:                activeSession.setSource(req.getRemoteHost() + ":"
082:                        + req.getRemotePort());
083:
084:                synchronized (sessions) {
085:                    sessions.put(
086:                            (HttpSession) activeSession.getSystemSession(),
087:                            activeSession);
088:                }
089:
090:                if (log.isDebugEnabled())
091:                    log
092:                            .debug("[Echo2SessionAspect.addSession] User session created id='"
093:                                    + WebRenderServlet.getActiveConnection()
094:                                            .getRequest().getSession().getId()
095:                                    + "'");
096:
097:                List<SessionListener> listeners = Controller.getInstance()
098:                        .getListeners(SessionListener.class);
099:
100:                synchronized (listeners) {
101:                    for (SessionListener listener : listeners) {
102:                        listener.onSessionCreating(activeSession);
103:                    }
104:                }
105:
106:                return activeSession;
107:            }
108:
109:            public SessionInfo removeSession(Object iSession) {
110:                SessionInfo sessInfo = null;
111:                synchronized (sessions) {
112:                    sessInfo = sessions.remove(iSession);
113:                }
114:
115:                if (sessInfo != null) {
116:                    if (log.isDebugEnabled())
117:                        log
118:                                .debug("[Echo2SessionAspect.removeSession] Removed session created: account="
119:                                        + sessInfo.getAccount()
120:                                        + ", source="
121:                                        + sessInfo.getSource()
122:                                        + ", created="
123:                                        + sessInfo.getCreated());
124:                } else
125:                    return null;
126:
127:                List<SessionListener> listeners = Controller.getInstance()
128:                        .getListeners(SessionListener.class);
129:
130:                synchronized (listeners) {
131:                    for (SessionListener listener : listeners) {
132:                        listener.onSessionDestroying(sessInfo);
133:                    }
134:                }
135:
136:                return sessInfo;
137:            }
138:
139:            public SessionInfo removeSessionBySystem(Object iSystemSession) {
140:                if (log.isInfoEnabled())
141:                    log
142:                            .info("[Echo2SessionAspect.removeSessionBySystem] User session destroyed id='"
143:                                    + ((HttpSession) iSystemSession).getId()
144:                                    + "'");
145:
146:                return removeSession(iSystemSession);
147:            }
148:
149:            public Collection<SessionInfo> getSessionInfos() {
150:                return sessions.values();
151:            }
152:
153:            public Locale getActiveLocale() {
154:                Echo2ApplicationContext context = Echo2ApplicationContext
155:                        .getApp();
156:                if (context == null)
157:                    return null;
158:                return context.getLocale();
159:            }
160:
161:            public void logout() {
162:                shutdown(getActiveSessionInfo().getSystemSession());
163:            }
164:
165:            public void shutdown(Object iSystemSession) {
166:                ((HttpSession) iSystemSession).invalidate();
167:            }
168:
169:            /**
170:             * Read the property from active HttpSession
171:             */
172:            public Object getProperty(String iKey) {
173:                return getProperty(getActiveSessionInfo().getSystemSession(),
174:                        iKey);
175:            }
176:
177:            /**
178:             * Read the property from a HttpSession
179:             */
180:            public Object getProperty(Object iSession, String iKey) {
181:                HttpSession sess = (HttpSession) iSession;
182:                if (sess != null)
183:                    return sess.getAttribute(iKey);
184:                return null;
185:            }
186:
187:            /**
188:             * Set the property inside current HttpSession
189:             */
190:            public void setProperty(String iKey, Object iValue) {
191:                setProperty(getActiveSessionInfo().getSystemSession(), iKey,
192:                        iValue);
193:            }
194:
195:            /**
196:             * Set the property inside a HttpSession
197:             */
198:            public void setProperty(Object iSession, String iKey, Object iValue) {
199:                HttpSession sess = (HttpSession) iSession;
200:                if (sess != null)
201:                    sess.setAttribute(iKey, iValue);
202:            }
203:
204:            public void sessionCreated(HttpSessionEvent iEvent) {
205:            }
206:
207:            public void sessionDestroyed(HttpSessionEvent iEvent) {
208:                removeSessionBySystem(iEvent.getSession());
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.