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


001:        /*
002:         * Copyright (c) 2002-2006 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.xwork;
006:
007:        import com.opensymphony.xwork.interceptor.component.ComponentInterceptor;
008:        import com.opensymphony.xwork.util.OgnlValueStack;
009:        import com.opensymphony.xwork.util.TextParseUtil;
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:
013:        import java.util.HashMap;
014:        import java.util.HashSet;
015:        import java.util.Set;
016:
017:        /**
018:         * <!-- START SNIPPET: description -->
019:         *
020:         * This result invokes an entire other action, complete with it's own interceptor stack and result.
021:         *
022:         * <!-- END SNIPPET: description -->
023:         *
024:         * <b>This result type takes the following parameters:</b>
025:         *
026:         * <!-- START SNIPPET: params -->
027:         *
028:         * <ul>
029:         *
030:         * <li><b>actionName (default)</b> - the name of the action that will be chained to</li>
031:         *
032:         * <li><b>namespace</b> - used to determine which namespace the Action is in that we're chaining. If namespace is null,
033:         * this defaults to the current namespace</li>
034:         *
035:         * <li><b>method</b> - used to specify another method on target action to be invoked. 
036:         * If null, this defaults to execute method</li>
037:         * 
038:         * </ul>
039:         *
040:         * <!-- END SNIPPET: params -->
041:         *
042:         * <b>Example:</b>
043:         *
044:         * <pre><!-- START SNIPPET: example -->
045:         * &lt;package name="public" extends="webwork-default"&gt;
046:         *     &lt;!-- Chain creatAccount to login, using the default parameter --&gt;
047:         *     &lt;action name="createAccount" class="..."&gt;
048:         *         &lt;result type="chain"&gt;login&lt;/result&gt;
049:         *     &lt;/action&gt;
050:         *
051:         *     &lt;action name="login" class="..."&gt;
052:         *         &lt;!-- Chain to another namespace --&gt;
053:         *         &lt;result type="chain"&gt;
054:         *             &lt;param name="actionName"&gt;dashboard&lt;/param&gt;
055:         *             &lt;param name="namespace"&gt;/secure&lt;/param&gt;
056:         *         &lt;/result&gt;
057:         *     &lt;/action&gt;
058:         * &lt;/package&gt;
059:         *
060:         * &lt;package name="secure" extends="webwork-default" namespace="/secure"&gt;
061:         *     &lt;action name="dashboard" class="..."&gt;
062:         *         &lt;result&gt;dashboard.jsp&lt;/result&gt;
063:         *     &lt;/action&gt;
064:         * &lt;/package&gt;
065:         * <!-- END SNIPPET: example --></pre>
066:         * 
067:         * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
068:         */
069:        public class ActionChainResult implements  Result {
070:
071:            private static final Log log = LogFactory
072:                    .getLog(ActionChainResult.class);
073:            public static final String DEFAULT_PARAM = "actionName";
074:            private static final String CHAIN_HISTORY = "CHAIN_HISTORY";
075:
076:            private ActionProxy proxy;
077:            private String actionName;
078:
079:            private String namespace;
080:
081:            private String methodName;
082:
083:            public void setActionName(String actionName) {
084:                this .actionName = actionName;
085:            }
086:
087:            public void setNamespace(String namespace) {
088:                this .namespace = namespace;
089:            }
090:
091:            public void setMethod(String method) {
092:                this .methodName = method;
093:            }
094:
095:            public ActionProxy getProxy() {
096:                return proxy;
097:            }
098:
099:            public boolean equals(Object o) {
100:                if (this  == o) {
101:                    return true;
102:                }
103:
104:                if (!(o instanceof  ActionChainResult)) {
105:                    return false;
106:                }
107:
108:                final ActionChainResult actionChainResult = (ActionChainResult) o;
109:
110:                if ((actionName != null) ? (!actionName
111:                        .equals(actionChainResult.actionName))
112:                        : (actionChainResult.actionName != null)) {
113:                    return false;
114:                }
115:
116:                return true;
117:            }
118:
119:            /**
120:             * @param invocation the DefaultActionInvocation calling the action call stack
121:             */
122:            public void execute(ActionInvocation invocation) throws Exception {
123:                // if the finalNamespace wasn't explicitly defined, assume the current one
124:                if (this .namespace == null) {
125:                    this .namespace = invocation.getProxy().getNamespace();
126:                }
127:
128:                OgnlValueStack stack = ActionContext.getContext()
129:                        .getValueStack();
130:                String finalNamespace = TextParseUtil.translateVariables(
131:                        namespace, stack);
132:                String finalActionName = TextParseUtil.translateVariables(
133:                        actionName, stack);
134:                String finalMethodName = this .methodName != null ? TextParseUtil
135:                        .translateVariables(this .methodName, stack)
136:                        : null;
137:
138:                if (isInChainHistory(finalNamespace, finalActionName,
139:                        finalMethodName)) {
140:                    throw new XworkException("infinite recursion detected");
141:                }
142:
143:                addToHistory(finalNamespace, finalActionName, finalMethodName);
144:
145:                HashMap extraContext = new HashMap();
146:                extraContext.put(ActionContext.VALUE_STACK, ActionContext
147:                        .getContext().getValueStack());
148:                extraContext.put(ActionContext.PARAMETERS, ActionContext
149:                        .getContext().getParameters());
150:                extraContext.put(ComponentInterceptor.COMPONENT_MANAGER,
151:                        ActionContext.getContext().get(
152:                                ComponentInterceptor.COMPONENT_MANAGER));
153:                extraContext.put(CHAIN_HISTORY, ActionContext.getContext().get(
154:                        CHAIN_HISTORY));
155:
156:                if (log.isDebugEnabled()) {
157:                    log.debug("Chaining to action " + finalActionName);
158:                }
159:
160:                proxy = ActionProxyFactory.getFactory().createActionProxy(
161:                        finalNamespace, finalActionName, extraContext);
162:                if (null != finalMethodName) {
163:                    proxy.setMethod(finalMethodName);
164:                }
165:                proxy.execute();
166:            }
167:
168:            public int hashCode() {
169:                return ((actionName != null) ? actionName.hashCode() : 0);
170:            }
171:
172:            private boolean isInChainHistory(String namespace,
173:                    String actionName, String methodName) {
174:                Set chainHistory = (Set) ActionContext.getContext().get(
175:                        CHAIN_HISTORY);
176:
177:                if (chainHistory == null) {
178:                    return false;
179:                } else {
180:                    return chainHistory.contains(makeKey(namespace, actionName,
181:                            methodName));
182:                }
183:            }
184:
185:            private void addToHistory(String namespace, String actionName,
186:                    String methodName) {
187:                Set chainHistory = (Set) ActionContext.getContext().get(
188:                        CHAIN_HISTORY);
189:
190:                if (chainHistory == null) {
191:                    chainHistory = new HashSet();
192:                }
193:
194:                ActionContext.getContext().put(CHAIN_HISTORY, chainHistory);
195:
196:                chainHistory.add(makeKey(namespace, actionName, methodName));
197:            }
198:
199:            private String makeKey(String namespace, String actionName,
200:                    String methodName) {
201:                if (null == methodName) {
202:                    return namespace + "/" + actionName;
203:                }
204:
205:                return namespace + "/" + actionName + "!" + methodName;
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.