Source Code Cross Referenced for ActionContext.java in  » J2EE » jfox » org » jfox » mvc » 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 » jfox » org.jfox.mvc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JFox - The most lightweight Java EE Application Server!
003:         * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
004:         *
005:         * JFox is licenced and re-distributable under GNU LGPL.
006:         */
007:        package org.jfox.mvc;
008:
009:        import java.lang.reflect.Method;
010:        import java.util.Collection;
011:        import java.util.HashMap;
012:        import java.util.Map;
013:        import javax.servlet.ServletConfig;
014:        import javax.servlet.ServletContext;
015:        import javax.servlet.http.HttpServletRequest;
016:
017:        /**
018:         * 调用上下文,�装调用过程中的所有资�
019:         *
020:         * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
021:         */
022:        public class ActionContext {
023:
024:            private String actionName;
025:
026:            /**
027:             * ActionMethodå??称
028:             */
029:            private String actionMethodName;
030:
031:            /**
032:             * 执行的Action方法
033:             */
034:            private Method actionMethod = null;
035:
036:            /**
037:             * 表å?• å’Œ QueryString æ??交的数æ?®
038:             */
039:            private Map<String, String[]> parameterMap = new HashMap<String, String[]>();
040:
041:            /**
042:             * 上传的文件 fieldname=>FileUploaded
043:             */
044:            private Map<String, FileUploaded> fileUploadedMap = new HashMap<String, FileUploaded>();
045:
046:            private PageContext pageContext;
047:            private SessionContext sessionContext;
048:            private Invocation invocation;
049:
050:            private ServletConfig servletConfig;
051:
052:            private HttpServletRequest request = null;
053:
054:            private Map<String, Object> attributes = new HashMap<String, Object>();
055:
056:            public static final String SESSION_KEY = "__SESSION_KEY__";
057:
058:            /**
059:             * 使用 ThreadLocal 将 InvocationContext 和当�线程进行关�
060:             */
061:            static transient ThreadLocal<ActionContext> threadInvocationContext = new ThreadLocal<ActionContext>();
062:
063:            public ActionContext(ServletConfig servletConfig,
064:                    HttpServletRequest request,
065:                    Map<String, String[]> parameterMap,
066:                    Map<String, FileUploaded> fileUploadedMap,
067:                    String actionName, String actionMethodName) {
068:                this .servletConfig = servletConfig;
069:                this .request = request;
070:                this .parameterMap.putAll(parameterMap);
071:                this .fileUploadedMap.putAll(fileUploadedMap);
072:                this .actionName = actionName;
073:                this .actionMethodName = actionMethodName;
074:                this .pageContext = new PageContext();
075:            }
076:
077:            /**
078:             * 得到当�线程绑定的 InvocationContext
079:             */
080:            public static ActionContext getCurrentThreadInvocationContext() {
081:                return threadInvocationContext.get();
082:            }
083:
084:            public void initInvocationContext() {
085:                this .sessionContext = initSessionContext();
086:                threadInvocationContext.set(this );
087:            }
088:
089:            public void disassociateThreadInvocationContext() {
090:                threadInvocationContext.remove();
091:            }
092:
093:            /**
094:             * 使用 request �始化 session context,
095:             * �始化完毕之�,将 session context 关�到当�线程
096:             */
097:            private SessionContext initSessionContext() {
098:                if (request == null) {
099:                    return null;
100:                }
101:                SessionContext sessionContext = (SessionContext) request
102:                        .getSession().getAttribute(SESSION_KEY);
103:                if (sessionContext == null) {
104:                    sessionContext = new SessionContext();
105:                    request.getSession().setAttribute(SESSION_KEY,
106:                            sessionContext);
107:                }
108:                return sessionContext;
109:            }
110:
111:            HttpServletRequest getServletRequest() {
112:                return request;
113:            }
114:
115:            /**
116:             * 销� Session
117:             */
118:            public void destroySessionContext() {
119:                getSessionContext().clearAttributes();
120:                request.getSession().removeAttribute(SESSION_KEY);
121:            }
122:
123:            public String getRequestURI() {
124:                return getServletRequest().getRequestURI();
125:            }
126:
127:            public ServletConfig getServletConfig() {
128:                return servletConfig;
129:            }
130:
131:            public ServletContext getServletContext() {
132:                return servletConfig.getServletContext();
133:            }
134:
135:            void setActionMethod(Method actionMethod) {
136:                this .actionMethod = actionMethod;
137:            }
138:
139:            public Method getActionMethod() {
140:                return actionMethod;
141:            }
142:
143:            public String getActionMethodName() {
144:                return actionMethodName;
145:            }
146:
147:            public String getFullActionMethodName() {
148:                return getActionName() + "." + getActionMethodName();
149:            }
150:
151:            public String getActionName() {
152:                return actionName;
153:            }
154:
155:            public boolean isPost() {
156:                return "POST".equals(getServletRequest().getMethod()
157:                        .toUpperCase());
158:            }
159:
160:            public SessionContext getSessionContext() {
161:                return sessionContext;
162:            }
163:
164:            void setInvocation(Invocation invocation) {
165:                this .invocation = invocation;
166:            }
167:
168:            public Invocation getInvocation() {
169:                return invocation;
170:            }
171:
172:            public PageContext getPageContext() {
173:                return pageContext;
174:            }
175:
176:            public String getParameterValue(String key) {
177:                return parameterMap.get(key)[0];
178:            }
179:
180:            public String[] getParameterValues(String key) {
181:                return parameterMap.get(key);
182:            }
183:
184:            public Map<String, String[]> getParameterMap() {
185:                return parameterMap;
186:            }
187:
188:            public Collection<FileUploaded> getFilesUploaded() {
189:                return fileUploadedMap.values();
190:            }
191:
192:            public FileUploaded getFileUploaded(String fieldname) {
193:                return fileUploadedMap.get(fieldname);
194:            }
195:
196:            public String getRemoteAddress() {
197:                return getServletRequest().getRemoteAddr();
198:            }
199:
200:            public void setAttribute(String key, Object value) {
201:                attributes.put(key, value);
202:            }
203:
204:            public Object getAttribute(String key) {
205:                return attributes.get(key);
206:            }
207:
208:            public boolean constainsKey(String key) {
209:                return attributes.containsKey(key);
210:            }
211:
212:            public boolean removeAttribute(String key) {
213:                return attributes.remove(key) != null;
214:            }
215:
216:            public static void main(String[] args) {
217:
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.