This is an automated email from the ASF dual-hosted git repository.

kusal pushed a commit to branch kusal-depr-apis-4
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 7a05123cd9ec4902dbb9dcd626805f85e4a2b174
Author: Kusal Kithul-Godage <g...@kusal.io>
AuthorDate: Thu Oct 17 15:17:14 2024 +1100

    WW-3714 Deprecate and migrate ActionEventListener
---
 .../opensymphony/xwork2/ActionEventListener.java   | 47 +++++++++++++---------
 .../com/opensymphony/xwork2/ActionInvocation.java  |  7 ++++
 .../apache/struts2}/ActionEventListener.java       | 18 ++++-----
 .../java/org/apache/struts2/ActionInvocation.java  |  1 -
 4 files changed, 44 insertions(+), 29 deletions(-)

diff --git 
a/core/src/main/java/com/opensymphony/xwork2/ActionEventListener.java 
b/core/src/main/java/com/opensymphony/xwork2/ActionEventListener.java
index 00690a7f4..4d2143848 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ActionEventListener.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ActionEventListener.java
@@ -21,24 +21,33 @@ package com.opensymphony.xwork2;
 import com.opensymphony.xwork2.util.ValueStack;
 
 /**
- * Provides hooks for handling key action events
+ * {@inheritDoc}
+ *
+ * @deprecated since 6.7.0, use {@link org.apache.struts2.ActionEventListener} 
instead.
  */
-public interface ActionEventListener {
-    /**
-     * Called after an action has been created. 
-     * 
-     * @param action The action
-     * @param stack The current value stack
-     * @return The action to use
-     */
-    public Object prepare(Object action, ValueStack stack);
-    
-    /**
-     * Called when an exception is thrown by the action
-     * 
-     * @param t The exception/error that was thrown
-     * @param stack The current value stack
-     * @return A result code to execute, can be null
-     */
-    public String handleException(Throwable t, ValueStack stack);
+@Deprecated
+public interface ActionEventListener extends 
org.apache.struts2.ActionEventListener {
+
+    static ActionEventListener adapt(org.apache.struts2.ActionEventListener 
actualListener) {
+        return actualListener != null ? new LegacyAdapter(actualListener) : 
null;
+    }
+
+    class LegacyAdapter implements ActionEventListener {
+
+        private final org.apache.struts2.ActionEventListener adaptee;
+
+        private LegacyAdapter(org.apache.struts2.ActionEventListener adaptee) {
+            this.adaptee = adaptee;
+        }
+
+        @Override
+        public Object prepare(Object action, ValueStack stack) {
+            return adaptee.prepare(action, stack);
+        }
+
+        @Override
+        public String handleException(Throwable t, ValueStack stack) {
+            return adaptee.handleException(t, stack);
+        }
+    }
 }
diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java 
b/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java
index 1d6e34859..56ea6ad6e 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java
@@ -42,6 +42,13 @@ public interface ActionInvocation extends 
org.apache.struts2.ActionInvocation {
 
     void addPreResultListener(PreResultListener listener);
 
+    @Override
+    default void setActionEventListener(org.apache.struts2.ActionEventListener 
listener) {
+        setActionEventListener(ActionEventListener.adapt(listener));
+    }
+
+    void setActionEventListener(ActionEventListener listener);
+
     static ActionInvocation adapt(org.apache.struts2.ActionInvocation 
actualInvocation) {
         return actualInvocation != null ? new LegacyAdapter(actualInvocation) 
: null;
     }
diff --git 
a/core/src/main/java/com/opensymphony/xwork2/ActionEventListener.java 
b/core/src/main/java/org/apache/struts2/ActionEventListener.java
similarity index 78%
copy from core/src/main/java/com/opensymphony/xwork2/ActionEventListener.java
copy to core/src/main/java/org/apache/struts2/ActionEventListener.java
index 00690a7f4..8c01a9a23 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ActionEventListener.java
+++ b/core/src/main/java/org/apache/struts2/ActionEventListener.java
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package com.opensymphony.xwork2;
+package org.apache.struts2;
 
 import com.opensymphony.xwork2.util.ValueStack;
 
@@ -25,20 +25,20 @@ import com.opensymphony.xwork2.util.ValueStack;
  */
 public interface ActionEventListener {
     /**
-     * Called after an action has been created. 
-     * 
+     * Called after an action has been created.
+     *
      * @param action The action
-     * @param stack The current value stack
+     * @param stack  The current value stack
      * @return The action to use
      */
-    public Object prepare(Object action, ValueStack stack);
-    
+    Object prepare(Object action, ValueStack stack);
+
     /**
      * Called when an exception is thrown by the action
-     * 
-     * @param t The exception/error that was thrown
+     *
+     * @param t     The exception/error that was thrown
      * @param stack The current value stack
      * @return A result code to execute, can be null
      */
-    public String handleException(Throwable t, ValueStack stack);
+    String handleException(Throwable t, ValueStack stack);
 }
diff --git a/core/src/main/java/org/apache/struts2/ActionInvocation.java 
b/core/src/main/java/org/apache/struts2/ActionInvocation.java
index 8b789f50d..14e930a50 100644
--- a/core/src/main/java/org/apache/struts2/ActionInvocation.java
+++ b/core/src/main/java/org/apache/struts2/ActionInvocation.java
@@ -19,7 +19,6 @@
 package org.apache.struts2;
 
 import com.opensymphony.xwork2.ActionChainResult;
-import com.opensymphony.xwork2.ActionEventListener;
 import com.opensymphony.xwork2.ActionProxy;
 import com.opensymphony.xwork2.util.ValueStack;
 import org.apache.struts2.interceptor.PreResultListener;

Reply via email to