This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch kusal-depr-apis-3 in repository https://gitbox.apache.org/repos/asf/struts.git
commit 352c2e9e18a0844e6258220b673293feac8aabb3 Author: Kusal Kithul-Godage <g...@kusal.io> AuthorDate: Thu Oct 17 14:49:22 2024 +1100 WW-3714 Deprecate and migrate ActionInvocation --- .../com/opensymphony/xwork2/ActionContext.java | 2 +- .../com/opensymphony/xwork2/ActionInvocation.java | 231 ++++++++------------- .../main/java/com/opensymphony/xwork2/Result.java | 24 +++ .../xwork2/interceptor/ConditionalInterceptor.java | 8 + .../xwork2/interceptor/Interceptor.java | 8 + .../apache/struts2}/ActionInvocation.java | 11 +- core/src/main/java/org/apache/struts2/Result.java | 3 - .../interceptor/ConditionalInterceptor.java | 2 +- .../apache/struts2/interceptor/Interceptor.java | 2 +- 9 files changed, 134 insertions(+), 157 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionContext.java b/core/src/main/java/com/opensymphony/xwork2/ActionContext.java index c2a4a39c2..d62da3219 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ActionContext.java +++ b/core/src/main/java/com/opensymphony/xwork2/ActionContext.java @@ -43,7 +43,7 @@ public class ActionContext extends org.apache.struts2.ActionContext { super(actualContext.getContextMap()); } - private static ActionContext adapt(org.apache.struts2.ActionContext actualContext) { + static ActionContext adapt(org.apache.struts2.ActionContext actualContext) { return actualContext != null ? new ActionContext(actualContext) : null; } diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java b/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java index 472f23ea7..6f70f993f 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java +++ b/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java @@ -22,158 +22,95 @@ import com.opensymphony.xwork2.interceptor.PreResultListener; import com.opensymphony.xwork2.util.ValueStack; /** - * An {@link ActionInvocation} represents the execution state of an {@link Action}. It holds the Interceptors and the Action instance. - * By repeated re-entrant execution of the <code>invoke()</code> method, initially by the {@link ActionProxy}, then by the Interceptors, the - * Interceptors are all executed, and then the {@link Action} and the {@link Result}. + * {@inheritDoc} * - * @author Jason Carreira - * @see com.opensymphony.xwork2.ActionProxy + * @deprecated since 6.7.0, use {@link org.apache.struts2.ActionInvocation} instead. */ -public interface ActionInvocation { - - /** - * Get the Action associated with this ActionInvocation. - * - * @return the Action - */ - Object getAction(); - - /** - * Gets whether this ActionInvocation has executed before. - * This will be set after the Action and the Result have executed. - * - * @return <tt>true</tt> if this ActionInvocation has executed before. - */ - boolean isExecuted(); - - /** - * Gets the ActionContext associated with this ActionInvocation. The ActionProxy is - * responsible for setting this ActionContext onto the ThreadLocal before invoking - * the ActionInvocation and resetting the old ActionContext afterwards. - * - * @return the ActionContext. - */ +@Deprecated +public interface ActionInvocation extends org.apache.struts2.ActionInvocation { + + @Override ActionContext getInvocationContext(); - /** - * Get the ActionProxy holding this ActionInvocation. - * - * @return the ActionProxy. - */ - ActionProxy getProxy(); - - /** - * If the ActionInvocation has been executed before and the Result is an instance of {@link ActionChainResult}, this method - * will walk down the chain of <code>ActionChainResult</code>s until it finds a non-chain result, which will be returned. If the - * ActionInvocation's result has not been executed before, the Result instance will be created and populated with - * the result params. - * - * @return the result. - * @throws Exception can be thrown. - */ + @Override Result getResult() throws Exception; - /** - * Gets the result code returned from this ActionInvocation. - * - * @return the result code - */ - String getResultCode(); - - /** - * Sets the result code, possibly overriding the one returned by the - * action. - * - * <p> - * The "intended" purpose of this method is to allow PreResultListeners to - * override the result code returned by the Action. - * </p> - * - * <p> - * If this method is used before the Action executes, the Action's returned - * result code will override what was set. However the Action could (if - * specifically coded to do so) inspect the ActionInvocation to see that - * someone "upstream" (e.g. an Interceptor) had suggested a value as the - * result, and it could therefore return the same value itself. - * </p> - * - * <p> - * If this method is called between the Action execution and the Result - * execution, then the value set here will override the result code the - * action had returned. Creating an Interceptor that implements - * {@link PreResultListener} will give you this opportunity. - * </p> - * - * <p> - * If this method is called after the Result has been executed, it will - * have the effect of raising an IllegalStateException. - * </p> - * - * @param resultCode the result code. - * @throws IllegalStateException if called after the Result has been executed. - * @see #isExecuted() - */ - void setResultCode(String resultCode); - - /** - * Gets the ValueStack associated with this ActionInvocation. - * - * @return the ValueStack - */ - ValueStack getStack(); - - /** - * Register a {@link PreResultListener} to be notified after the Action is executed and - * before the Result is executed. - * - * <p> - * The ActionInvocation implementation must guarantee that listeners will be called in - * the order in which they are registered. - * </p> - * - * <p> - * Listener registration and execution does not need to be thread-safe. - * </p> - * - * @param listener the listener to add. - */ - void addPreResultListener(PreResultListener listener); - - /** - * Invokes the next step in processing this ActionInvocation. - * - * <p> - * If there are more Interceptors, this will call the next one. If Interceptors choose not to short-circuit - * ActionInvocation processing and return their own return code, they will call invoke() to allow the next Interceptor - * to execute. If there are no more Interceptors to be applied, the Action is executed. - * If the {@link ActionProxy#getExecuteResult()} method returns <tt>true</tt>, the Result is also executed. - * </p> - * - * @throws Exception can be thrown. - * @return the return code. - */ - String invoke() throws Exception; - - /** - * Invokes only the Action (not Interceptors or Results). - * - * <p> - * This is useful in rare situations where advanced usage with the interceptor/action/result workflow is - * being manipulated for certain functionality. - * </p> - * - * @return the return code. - * @throws Exception can be thrown. - */ - String invokeActionOnly() throws Exception; - - /** - * Sets the action event listener to respond to key action events. - * - * @param listener the listener. - */ - void setActionEventListener(ActionEventListener listener); - - void init(ActionProxy proxy) ; + static ActionInvocation adapt(org.apache.struts2.ActionInvocation actualInvocation) { + return actualInvocation != null ? new LegacyAdapter(actualInvocation) : null; + } + + class LegacyAdapter implements ActionInvocation { + + private final org.apache.struts2.ActionInvocation adaptee; + + private LegacyAdapter(org.apache.struts2.ActionInvocation adaptee) { + this.adaptee = adaptee; + } + + @Override + public Object getAction() { + return adaptee.getAction(); + } + + @Override + public boolean isExecuted() { + return adaptee.isExecuted(); + } + + @Override + public ActionContext getInvocationContext() { + return ActionContext.adapt(adaptee.getInvocationContext()); + } + + @Override + public ActionProxy getProxy() { + return adaptee.getProxy(); + } + + @Override + public Result getResult() throws Exception { + return Result.adapt(adaptee.getResult()); + } + + @Override + public String getResultCode() { + return adaptee.getResultCode(); + } + + @Override + public void setResultCode(String resultCode) { + adaptee.setResultCode(resultCode); + } + + @Override + public ValueStack getStack() { + return adaptee.getStack(); + } + + @Override + public void addPreResultListener(PreResultListener listener) { + adaptee.addPreResultListener(listener); + } + + @Override + public String invoke() throws Exception { + return adaptee.invoke(); + } + + @Override + public String invokeActionOnly() throws Exception { + return adaptee.invokeActionOnly(); + } + + @Override + public void setActionEventListener(ActionEventListener listener) { + adaptee.setActionEventListener(listener); + } + + @Override + public void init(ActionProxy proxy) { + adaptee.init(proxy); + } + } } diff --git a/core/src/main/java/com/opensymphony/xwork2/Result.java b/core/src/main/java/com/opensymphony/xwork2/Result.java index ccd238751..5d56c13cc 100644 --- a/core/src/main/java/com/opensymphony/xwork2/Result.java +++ b/core/src/main/java/com/opensymphony/xwork2/Result.java @@ -25,4 +25,28 @@ package com.opensymphony.xwork2; */ @Deprecated public interface Result extends org.apache.struts2.Result { + + default void execute(org.apache.struts2.ActionInvocation invocation) throws Exception { + execute(ActionInvocation.adapt(invocation)); + } + + void execute(ActionInvocation invocation) throws Exception; + + static Result adapt(org.apache.struts2.Result actualResult) { + return actualResult != null ? new LegacyAdapter(actualResult) : null; + } + + class LegacyAdapter implements Result { + + private final org.apache.struts2.Result adaptee; + + private LegacyAdapter(org.apache.struts2.Result adaptee) { + this.adaptee = adaptee; + } + + @Override + public void execute(ActionInvocation invocation) throws Exception { + adaptee.execute(ActionInvocation.adapt(invocation)); + } + } } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConditionalInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConditionalInterceptor.java index 40d856f48..83c2bcb3e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ConditionalInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ConditionalInterceptor.java @@ -18,6 +18,8 @@ */ package com.opensymphony.xwork2.interceptor; +import com.opensymphony.xwork2.ActionInvocation; + /** * {@inheritDoc} * @@ -25,4 +27,10 @@ package com.opensymphony.xwork2.interceptor; */ @Deprecated public interface ConditionalInterceptor extends org.apache.struts2.interceptor.ConditionalInterceptor, Interceptor { + + default boolean shouldIntercept(org.apache.struts2.ActionInvocation invocation) { + return shouldIntercept(ActionInvocation.adapt(invocation)); + } + + boolean shouldIntercept(ActionInvocation invocation); } diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java index 87041a269..7e97cd762 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/Interceptor.java @@ -18,6 +18,8 @@ */ package com.opensymphony.xwork2.interceptor; +import com.opensymphony.xwork2.ActionInvocation; + /** * {@inheritDoc} * @@ -25,4 +27,10 @@ package com.opensymphony.xwork2.interceptor; */ @Deprecated public interface Interceptor extends org.apache.struts2.interceptor.Interceptor { + + default String intercept(org.apache.struts2.ActionInvocation invocation) throws Exception { + return intercept(ActionInvocation.adapt(invocation)); + } + + String intercept(ActionInvocation invocation) throws Exception; } diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java b/core/src/main/java/org/apache/struts2/ActionInvocation.java similarity index 94% copy from core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java copy to core/src/main/java/org/apache/struts2/ActionInvocation.java index 472f23ea7..46f1a5b0e 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java +++ b/core/src/main/java/org/apache/struts2/ActionInvocation.java @@ -16,18 +16,21 @@ * specific language governing permissions and limitations * under the License. */ -package com.opensymphony.xwork2; +package org.apache.struts2; +import com.opensymphony.xwork2.ActionChainResult; +import com.opensymphony.xwork2.ActionEventListener; +import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.interceptor.PreResultListener; import com.opensymphony.xwork2.util.ValueStack; /** - * An {@link ActionInvocation} represents the execution state of an {@link Action}. It holds the Interceptors and the Action instance. + * An {@link ActionInvocation} represents the execution state of an {@link com.opensymphony.xwork2.Action}. It holds the Interceptors and the Action instance. * By repeated re-entrant execution of the <code>invoke()</code> method, initially by the {@link ActionProxy}, then by the Interceptors, the - * Interceptors are all executed, and then the {@link Action} and the {@link Result}. + * Interceptors are all executed, and then the {@link Action} and the {@link com.opensymphony.xwork2.Result}. * * @author Jason Carreira - * @see com.opensymphony.xwork2.ActionProxy + * @see ActionProxy */ public interface ActionInvocation { diff --git a/core/src/main/java/org/apache/struts2/Result.java b/core/src/main/java/org/apache/struts2/Result.java index 4dc912772..407994eab 100644 --- a/core/src/main/java/org/apache/struts2/Result.java +++ b/core/src/main/java/org/apache/struts2/Result.java @@ -18,9 +18,6 @@ */ package org.apache.struts2; -import com.opensymphony.xwork2.Action; -import com.opensymphony.xwork2.ActionInvocation; - import java.io.Serializable; /** diff --git a/core/src/main/java/org/apache/struts2/interceptor/ConditionalInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ConditionalInterceptor.java index a6071327c..716b58195 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/ConditionalInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/ConditionalInterceptor.java @@ -18,7 +18,7 @@ */ package org.apache.struts2.interceptor; -import com.opensymphony.xwork2.ActionInvocation; +import org.apache.struts2.ActionInvocation; /** * A marking interface, when implemented allows to conditionally execute a given interceptor diff --git a/core/src/main/java/org/apache/struts2/interceptor/Interceptor.java b/core/src/main/java/org/apache/struts2/interceptor/Interceptor.java index 9c36bde77..7eabb85a8 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/Interceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/Interceptor.java @@ -18,7 +18,7 @@ */ package org.apache.struts2.interceptor; -import com.opensymphony.xwork2.ActionInvocation; +import org.apache.struts2.ActionInvocation; import java.io.Serializable;