Skip to content

Commit 272c2e7

Browse files
committed
WW-3714 Deprecate and migrate PreResultListener
1 parent 60095a6 commit 272c2e7

File tree

4 files changed

+76
-14
lines changed

4 files changed

+76
-14
lines changed

core/src/main/java/com/opensymphony/xwork2/ActionInvocation.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public interface ActionInvocation extends org.apache.struts2.ActionInvocation {
3535
@Override
3636
Result getResult() throws Exception;
3737

38+
@Override
39+
default void addPreResultListener(org.apache.struts2.interceptor.PreResultListener listener) {
40+
addPreResultListener(PreResultListener.adapt(listener));
41+
}
42+
43+
void addPreResultListener(PreResultListener listener);
44+
3845
static ActionInvocation adapt(org.apache.struts2.ActionInvocation actualInvocation) {
3946
return actualInvocation != null ? new LegacyAdapter(actualInvocation) : null;
4047
}

core/src/main/java/com/opensymphony/xwork2/interceptor/PreResultListener.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,35 @@
2121
import com.opensymphony.xwork2.ActionInvocation;
2222

2323
/**
24-
* PreResultListeners may be registered with an {@link ActionInvocation} to get a callback after the
25-
* {@link com.opensymphony.xwork2.Action} has been executed but before the {@link com.opensymphony.xwork2.Result}
26-
* is executed.
24+
* {@inheritDoc}
2725
*
28-
* @author Jason Carreira
26+
* @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.PreResultListener} instead.
2927
*/
30-
public interface PreResultListener {
31-
32-
/**
33-
* This callback method will be called after the {@link com.opensymphony.xwork2.Action} execution and
34-
* before the {@link com.opensymphony.xwork2.Result} execution.
35-
*
36-
* @param invocation the action invocation
37-
* @param resultCode the result code returned by the action (eg. <code>success</code>).
38-
*/
28+
@Deprecated
29+
public interface PreResultListener extends org.apache.struts2.interceptor.PreResultListener {
30+
31+
@Override
32+
default void beforeResult(org.apache.struts2.ActionInvocation invocation, String resultCode) {
33+
beforeResult(ActionInvocation.adapt(invocation), resultCode);
34+
}
35+
3936
void beforeResult(ActionInvocation invocation, String resultCode);
4037

38+
static PreResultListener adapt(org.apache.struts2.interceptor.PreResultListener actualListener) {
39+
return actualListener != null ? new LegacyAdapter(actualListener) : null;
40+
}
41+
42+
class LegacyAdapter implements PreResultListener {
43+
44+
private final org.apache.struts2.interceptor.PreResultListener adaptee;
45+
46+
private LegacyAdapter(org.apache.struts2.interceptor.PreResultListener adaptee) {
47+
this.adaptee = adaptee;
48+
}
49+
50+
@Override
51+
public void beforeResult(ActionInvocation invocation, String resultCode) {
52+
adaptee.beforeResult(invocation, resultCode);
53+
}
54+
}
4155
}

core/src/main/java/org/apache/struts2/ActionInvocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import com.opensymphony.xwork2.ActionChainResult;
2222
import com.opensymphony.xwork2.ActionEventListener;
2323
import com.opensymphony.xwork2.ActionProxy;
24-
import com.opensymphony.xwork2.interceptor.PreResultListener;
2524
import com.opensymphony.xwork2.util.ValueStack;
25+
import org.apache.struts2.interceptor.PreResultListener;
2626

2727
/**
2828
* An {@link ActionInvocation} represents the execution state of an {@link com.opensymphony.xwork2.Action}. It holds the Interceptors and the Action instance.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.struts2.interceptor;
20+
21+
import org.apache.struts2.ActionInvocation;
22+
23+
/**
24+
* PreResultListeners may be registered with an {@link ActionInvocation} to get a callback after the
25+
* {@link com.opensymphony.xwork2.Action} has been executed but before the {@link com.opensymphony.xwork2.Result}
26+
* is executed.
27+
*
28+
* @author Jason Carreira
29+
*/
30+
public interface PreResultListener {
31+
32+
/**
33+
* This callback method will be called after the {@link com.opensymphony.xwork2.Action} execution and
34+
* before the {@link com.opensymphony.xwork2.Result} execution.
35+
*
36+
* @param invocation the action invocation
37+
* @param resultCode the result code returned by the action (eg. <code>success</code>).
38+
*/
39+
void beforeResult(ActionInvocation invocation, String resultCode);
40+
41+
}

0 commit comments

Comments
 (0)