Source Code Cross Referenced for DwrScopes.java in  » Ajax » dwr » org » directwebremoting » guice » 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 » Ajax » dwr » org.directwebremoting.guice 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Tim Peierls
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:        package org.directwebremoting.guice;
017:
018:        import javax.servlet.ServletContext;
019:        import javax.servlet.http.HttpServletRequest;
020:        import javax.servlet.http.HttpSession;
021:
022:        import org.apache.commons.logging.Log;
023:        import org.apache.commons.logging.LogFactory;
024:        import org.directwebremoting.ScriptSession;
025:        import org.directwebremoting.WebContextFactory;
026:
027:        import static org.directwebremoting.guice.DwrGuiceUtil.getServletContext;
028:
029:        /**
030:         * Scopes available to DWR applications.
031:         * @author Tim Peierls [tim at peierls dot net]
032:         */
033:        public class DwrScopes {
034:            /**
035:             * HTTP request scope.
036:             */
037:            public static final ContextScope<HttpServletRequest> REQUEST = new AbstractSimpleContextScope<HttpServletRequest>(
038:                    HttpServletRequest.class, "DwrScopes.REQUEST") {
039:                @Override
040:                public HttpServletRequest get() {
041:                    return WebContextFactory.get().getHttpServletRequest();
042:                }
043:
044:                @Override
045:                public Object get(HttpServletRequest request, String name) {
046:                    return request.getAttribute(name);
047:                }
048:
049:                @Override
050:                public void put(HttpServletRequest request, String name,
051:                        Object value) {
052:                    request.setAttribute(name, value);
053:                }
054:            };
055:
056:            /**
057:             * DWR script session scope.
058:             */
059:            public static final ContextScope<ScriptSession> SCRIPT = new AbstractSimpleContextScope<ScriptSession>(
060:                    ScriptSession.class, "DwrScopes.SCRIPT") {
061:                @Override
062:                public ScriptSession get() {
063:                    return WebContextFactory.get().getScriptSession();
064:                }
065:
066:                @Override
067:                public Object get(ScriptSession scriptSession, String name) {
068:                    return scriptSession.getAttribute(name);
069:                }
070:
071:                @Override
072:                public void put(ScriptSession scriptSession, String name,
073:                        Object value) {
074:                    scriptSession.setAttribute(name, value);
075:                }
076:            };
077:
078:            /**
079:             * HTTP session scope. The implementation uses session identity to
080:             * to track which sessions are open. Since the servlet spec doesn't
081:             * guarantee identity of sessions between requests, don't rely on
082:             * {@code getOpenContexts()} or {@code close(session, handlers)} to
083:             * work correctly for this scope.
084:             */
085:            public static final ContextScope<HttpSession> SESSION = new AbstractSimpleContextScope<HttpSession>(
086:                    HttpSession.class, "DwrScopes.SESSION") {
087:                @Override
088:                public HttpSession get() {
089:                    return WebContextFactory.get().getSession();
090:                }
091:
092:                @Override
093:                public Object get(HttpSession session, String name) {
094:                    return session.getAttribute(name);
095:                }
096:
097:                @Override
098:                public void put(HttpSession session, String name, Object value) {
099:                    session.setAttribute(name, value);
100:                }
101:            };
102:
103:            /**
104:             * Application scope: objects in this scope <em>are</em> eagerly initialized
105:             * during DWR servlet initialization, and Closeable objects in this scope are
106:             * closed during DWR servlet destruction.
107:             */
108:            public static final ContextScope<ServletContext> APPLICATION = new ApplicationScope(
109:                    "DwrScopes.APPLICATION");
110:
111:            /**
112:             * Global application scope: like {@link #APPLICATION}, but objects in
113:             * this scope are <em>not</em> eagerly initialized and Closeable objects
114:             * in this scope are closed during servlet context destruction (not
115:             * during DWR servlet destruction).
116:             */
117:            public static final ContextScope<ServletContext> GLOBAL = new ApplicationScope(
118:                    "DwrScopes.GLOBAL");
119:
120:            static class ApplicationScope extends
121:                    AbstractSimpleContextScope<ServletContext> {
122:                ApplicationScope(String scopeName) {
123:                    super (ServletContext.class, scopeName);
124:                }
125:
126:                @Override
127:                public ServletContext get() {
128:                    return getServletContext();
129:                }
130:
131:                @Override
132:                public Object get(ServletContext servletContext, String name) {
133:                    if (log.isDebugEnabled()) {
134:                        log.debug(String.format(
135:                                "servletContext.getAttribute(%s)", name));
136:                    }
137:                    return servletContext.getAttribute(name);
138:                }
139:
140:                @Override
141:                public void put(ServletContext servletContext, String name,
142:                        Object value) {
143:                    if (log.isDebugEnabled()) {
144:                        log.debug(String.format(
145:                                "servletContext.setAttribute(%s, %s)", name,
146:                                value));
147:                    }
148:                    servletContext.setAttribute(name, value);
149:                }
150:            }
151:
152:            private DwrScopes() { /* uninstantiable */
153:            }
154:
155:            /**
156:             * The log stream
157:             */
158:            protected static final Log log = LogFactory.getLog(DwrScopes.class);
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.