Source Code Cross Referenced for ActionAutowiringInterceptor.java in  » J2EE » webwork-2.2.6 » com » opensymphony » xwork » spring » interceptor » 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 » webwork 2.2.6 » com.opensymphony.xwork.spring.interceptor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:
006:        package com.opensymphony.xwork.spring.interceptor;
007:
008:        import com.opensymphony.xwork.ActionContext;
009:        import com.opensymphony.xwork.ActionInvocation;
010:        import com.opensymphony.xwork.interceptor.AroundInterceptor;
011:        import com.opensymphony.xwork.spring.SpringObjectFactory;
012:        import org.apache.commons.logging.Log;
013:        import org.apache.commons.logging.LogFactory;
014:        import org.springframework.beans.BeansException;
015:        import org.springframework.context.ApplicationContext;
016:        import org.springframework.context.ApplicationContextAware;
017:        import org.springframework.web.context.WebApplicationContext;
018:
019:        /**
020:         * <!-- START SNIPPET: description -->
021:         * TODO: Give a description of the Interceptor.
022:         * <!-- END SNIPPET: description -->
023:         *
024:         * <!-- START SNIPPET: parameters -->
025:         * TODO: Describe the paramters for this Interceptor.
026:         * <!-- END SNIPPET: parameters -->
027:         *
028:         * <!-- START SNIPPET: extending -->
029:         * TODO: Discuss some possible extension of the Interceptor.
030:         * <!-- END SNIPPET: extending -->
031:         *
032:         * <pre>
033:         * <!-- START SNIPPET: example -->
034:         * &lt;!-- TODO: Describe how the Interceptor reference will effect execution --&gt;
035:         * &lt;action name="someAction" class="com.examples.SomeAction"&gt;
036:         *      TODO: fill in the interceptor reference.
037:         *     &lt;interceptor-ref name=""/&gt;
038:         *     &lt;result name="success"&gt;good_result.ftl&lt;/result&gt;
039:         * &lt;/action&gt;
040:         * <!-- END SNIPPET: example -->
041:         * </pre>
042:         * 
043:         * Autowires action classes to Spring beans.  The strategy for autowiring the beans can be configured
044:         * by setting the parameter on the interceptor.  Actions that need access to the <code>ActionContext</code>
045:         * can implements the <code>ApplicationContextAware</code> interface.  The context will also be placed on
046:         * the action context under the APPLICATION_CONTEXT attribute.
047:         *
048:         * @author Simon Stewart
049:         * @author Eric Hauser
050:         */
051:        public class ActionAutowiringInterceptor extends AroundInterceptor
052:                implements  ApplicationContextAware {
053:            private static final Log log = LogFactory
054:                    .getLog(ActionAutowiringInterceptor.class);
055:
056:            public static final String APPLICATION_CONTEXT = "com.opensymphony.xwork.spring.interceptor.ActionAutowiringInterceptor.applicationContext";
057:
058:            private boolean initialized = false;
059:            private ApplicationContext context;
060:            private SpringObjectFactory factory;
061:            private Integer autowireStrategy;
062:
063:            /**
064:             * @param autowireStrategy
065:             */
066:            public void setAutowireStrategy(Integer autowireStrategy) {
067:                this .autowireStrategy = autowireStrategy;
068:            }
069:
070:            /**
071:             * @param dispatcher
072:             * @param result
073:             * @throws Exception
074:             */
075:            protected void after(ActionInvocation dispatcher, String result)
076:                    throws Exception {
077:                // Empty
078:            }
079:
080:            /**
081:             * Looks for the <code>ApplicationContext</code> under the attribute that the Spring listener sets in
082:             * the servlet context.  The configuration is done the first time here instead of in init() since the
083:             * <code>ActionContext</code> is not available during <code>Interceptor</code> initialization.
084:             * <p/>
085:             * Autowires the action to Spring beans and places the <code>ApplicationContext</code>
086:             * on the <code>ActionContext</code>
087:             * <p/>
088:             * TODO Should this check to see if the <code>SpringObjectFactory</code> has already been configured
089:             * instead of instantiating a new one?  Or is there a good reason for the interceptor to have it's own
090:             * factory?
091:             *
092:             * @param invocation
093:             * @throws Exception
094:             */
095:            protected void before(ActionInvocation invocation) throws Exception {
096:                if (!initialized) {
097:                    ApplicationContext applicationContext = (ApplicationContext) ActionContext
098:                            .getContext()
099:                            .getApplication()
100:                            .get(
101:                                    WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
102:
103:                    if (applicationContext == null) {
104:                        log
105:                                .warn("ApplicationContext could not be found.  Action classes will not be autowired.");
106:                    } else {
107:                        setApplicationContext(applicationContext);
108:                        factory = new SpringObjectFactory();
109:                        factory.setApplicationContext(getApplicationContext());
110:                        if (autowireStrategy != null) {
111:                            factory.setAutowireStrategy(autowireStrategy
112:                                    .intValue());
113:                        }
114:                    }
115:                    initialized = true;
116:                }
117:
118:                if (factory == null)
119:                    return;
120:
121:                Object bean = invocation.getAction();
122:                factory.autoWireBean(bean);
123:
124:                ActionContext.getContext().put(APPLICATION_CONTEXT, context);
125:            }
126:
127:            /**
128:             * @param applicationContext
129:             * @throws BeansException
130:             */
131:            public void setApplicationContext(
132:                    ApplicationContext applicationContext)
133:                    throws BeansException {
134:                context = applicationContext;
135:            }
136:
137:            /**
138:             * @return context
139:             */
140:            protected ApplicationContext getApplicationContext() {
141:                return context;
142:            }
143:
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.