Skip to content

Commit 352c2e9

Browse files
committed
WW-3714 Deprecate and migrate ActionInvocation
1 parent ae9dc42 commit 352c2e9

File tree

9 files changed

+309
-153
lines changed

9 files changed

+309
-153
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private ActionContext(org.apache.struts2.ActionContext actualContext) {
4343
super(actualContext.getContextMap());
4444
}
4545

46-
private static ActionContext adapt(org.apache.struts2.ActionContext actualContext) {
46+
static ActionContext adapt(org.apache.struts2.ActionContext actualContext) {
4747
return actualContext != null ? new ActionContext(actualContext) : null;
4848
}
4949

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

Lines changed: 84 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -22,158 +22,95 @@
2222
import com.opensymphony.xwork2.util.ValueStack;
2323

2424
/**
25-
* An {@link ActionInvocation} represents the execution state of an {@link Action}. It holds the Interceptors and the Action instance.
26-
* By repeated re-entrant execution of the <code>invoke()</code> method, initially by the {@link ActionProxy}, then by the Interceptors, the
27-
* Interceptors are all executed, and then the {@link Action} and the {@link Result}.
25+
* {@inheritDoc}
2826
*
29-
* @author Jason Carreira
30-
* @see com.opensymphony.xwork2.ActionProxy
27+
* @deprecated since 6.7.0, use {@link org.apache.struts2.ActionInvocation} instead.
3128
*/
32-
public interface ActionInvocation {
33-
34-
/**
35-
* Get the Action associated with this ActionInvocation.
36-
*
37-
* @return the Action
38-
*/
39-
Object getAction();
40-
41-
/**
42-
* Gets whether this ActionInvocation has executed before.
43-
* This will be set after the Action and the Result have executed.
44-
*
45-
* @return <tt>true</tt> if this ActionInvocation has executed before.
46-
*/
47-
boolean isExecuted();
48-
49-
/**
50-
* Gets the ActionContext associated with this ActionInvocation. The ActionProxy is
51-
* responsible for setting this ActionContext onto the ThreadLocal before invoking
52-
* the ActionInvocation and resetting the old ActionContext afterwards.
53-
*
54-
* @return the ActionContext.
55-
*/
29+
@Deprecated
30+
public interface ActionInvocation extends org.apache.struts2.ActionInvocation {
31+
32+
@Override
5633
ActionContext getInvocationContext();
5734

58-
/**
59-
* Get the ActionProxy holding this ActionInvocation.
60-
*
61-
* @return the ActionProxy.
62-
*/
63-
ActionProxy getProxy();
64-
65-
/**
66-
* If the ActionInvocation has been executed before and the Result is an instance of {@link ActionChainResult}, this method
67-
* will walk down the chain of <code>ActionChainResult</code>s until it finds a non-chain result, which will be returned. If the
68-
* ActionInvocation's result has not been executed before, the Result instance will be created and populated with
69-
* the result params.
70-
*
71-
* @return the result.
72-
* @throws Exception can be thrown.
73-
*/
35+
@Override
7436
Result getResult() throws Exception;
7537

76-
/**
77-
* Gets the result code returned from this ActionInvocation.
78-
*
79-
* @return the result code
80-
*/
81-
String getResultCode();
82-
83-
/**
84-
* Sets the result code, possibly overriding the one returned by the
85-
* action.
86-
*
87-
* <p>
88-
* The "intended" purpose of this method is to allow PreResultListeners to
89-
* override the result code returned by the Action.
90-
* </p>
91-
*
92-
* <p>
93-
* If this method is used before the Action executes, the Action's returned
94-
* result code will override what was set. However the Action could (if
95-
* specifically coded to do so) inspect the ActionInvocation to see that
96-
* someone "upstream" (e.g. an Interceptor) had suggested a value as the
97-
* result, and it could therefore return the same value itself.
98-
* </p>
99-
*
100-
* <p>
101-
* If this method is called between the Action execution and the Result
102-
* execution, then the value set here will override the result code the
103-
* action had returned. Creating an Interceptor that implements
104-
* {@link PreResultListener} will give you this opportunity.
105-
* </p>
106-
*
107-
* <p>
108-
* If this method is called after the Result has been executed, it will
109-
* have the effect of raising an IllegalStateException.
110-
* </p>
111-
*
112-
* @param resultCode the result code.
113-
* @throws IllegalStateException if called after the Result has been executed.
114-
* @see #isExecuted()
115-
*/
116-
void setResultCode(String resultCode);
117-
118-
/**
119-
* Gets the ValueStack associated with this ActionInvocation.
120-
*
121-
* @return the ValueStack
122-
*/
123-
ValueStack getStack();
124-
125-
/**
126-
* Register a {@link PreResultListener} to be notified after the Action is executed and
127-
* before the Result is executed.
128-
*
129-
* <p>
130-
* The ActionInvocation implementation must guarantee that listeners will be called in
131-
* the order in which they are registered.
132-
* </p>
133-
*
134-
* <p>
135-
* Listener registration and execution does not need to be thread-safe.
136-
* </p>
137-
*
138-
* @param listener the listener to add.
139-
*/
140-
void addPreResultListener(PreResultListener listener);
141-
142-
/**
143-
* Invokes the next step in processing this ActionInvocation.
144-
*
145-
* <p>
146-
* If there are more Interceptors, this will call the next one. If Interceptors choose not to short-circuit
147-
* ActionInvocation processing and return their own return code, they will call invoke() to allow the next Interceptor
148-
* to execute. If there are no more Interceptors to be applied, the Action is executed.
149-
* If the {@link ActionProxy#getExecuteResult()} method returns <tt>true</tt>, the Result is also executed.
150-
* </p>
151-
*
152-
* @throws Exception can be thrown.
153-
* @return the return code.
154-
*/
155-
String invoke() throws Exception;
156-
157-
/**
158-
* Invokes only the Action (not Interceptors or Results).
159-
*
160-
* <p>
161-
* This is useful in rare situations where advanced usage with the interceptor/action/result workflow is
162-
* being manipulated for certain functionality.
163-
* </p>
164-
*
165-
* @return the return code.
166-
* @throws Exception can be thrown.
167-
*/
168-
String invokeActionOnly() throws Exception;
169-
170-
/**
171-
* Sets the action event listener to respond to key action events.
172-
*
173-
* @param listener the listener.
174-
*/
175-
void setActionEventListener(ActionEventListener listener);
176-
177-
void init(ActionProxy proxy) ;
38+
static ActionInvocation adapt(org.apache.struts2.ActionInvocation actualInvocation) {
39+
return actualInvocation != null ? new LegacyAdapter(actualInvocation) : null;
40+
}
41+
42+
class LegacyAdapter implements ActionInvocation {
43+
44+
private final org.apache.struts2.ActionInvocation adaptee;
45+
46+
private LegacyAdapter(org.apache.struts2.ActionInvocation adaptee) {
47+
this.adaptee = adaptee;
48+
}
49+
50+
@Override
51+
public Object getAction() {
52+
return adaptee.getAction();
53+
}
54+
55+
@Override
56+
public boolean isExecuted() {
57+
return adaptee.isExecuted();
58+
}
59+
60+
@Override
61+
public ActionContext getInvocationContext() {
62+
return ActionContext.adapt(adaptee.getInvocationContext());
63+
}
64+
65+
@Override
66+
public ActionProxy getProxy() {
67+
return adaptee.getProxy();
68+
}
69+
70+
@Override
71+
public Result getResult() throws Exception {
72+
return Result.adapt(adaptee.getResult());
73+
}
74+
75+
@Override
76+
public String getResultCode() {
77+
return adaptee.getResultCode();
78+
}
79+
80+
@Override
81+
public void setResultCode(String resultCode) {
82+
adaptee.setResultCode(resultCode);
83+
}
84+
85+
@Override
86+
public ValueStack getStack() {
87+
return adaptee.getStack();
88+
}
89+
90+
@Override
91+
public void addPreResultListener(PreResultListener listener) {
92+
adaptee.addPreResultListener(listener);
93+
}
94+
95+
@Override
96+
public String invoke() throws Exception {
97+
return adaptee.invoke();
98+
}
99+
100+
@Override
101+
public String invokeActionOnly() throws Exception {
102+
return adaptee.invokeActionOnly();
103+
}
104+
105+
@Override
106+
public void setActionEventListener(ActionEventListener listener) {
107+
adaptee.setActionEventListener(listener);
108+
}
109+
110+
@Override
111+
public void init(ActionProxy proxy) {
112+
adaptee.init(proxy);
113+
}
114+
}
178115

179116
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,28 @@
2525
*/
2626
@Deprecated
2727
public interface Result extends org.apache.struts2.Result {
28+
29+
default void execute(org.apache.struts2.ActionInvocation invocation) throws Exception {
30+
execute(ActionInvocation.adapt(invocation));
31+
}
32+
33+
void execute(ActionInvocation invocation) throws Exception;
34+
35+
static Result adapt(org.apache.struts2.Result actualResult) {
36+
return actualResult != null ? new LegacyAdapter(actualResult) : null;
37+
}
38+
39+
class LegacyAdapter implements Result {
40+
41+
private final org.apache.struts2.Result adaptee;
42+
43+
private LegacyAdapter(org.apache.struts2.Result adaptee) {
44+
this.adaptee = adaptee;
45+
}
46+
47+
@Override
48+
public void execute(ActionInvocation invocation) throws Exception {
49+
adaptee.execute(ActionInvocation.adapt(invocation));
50+
}
51+
}
2852
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@
1818
*/
1919
package com.opensymphony.xwork2.interceptor;
2020

21+
import com.opensymphony.xwork2.ActionInvocation;
22+
2123
/**
2224
* {@inheritDoc}
2325
*
2426
* @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.Interceptor} instead.
2527
*/
2628
@Deprecated
2729
public interface ConditionalInterceptor extends org.apache.struts2.interceptor.ConditionalInterceptor, Interceptor {
30+
31+
default boolean shouldIntercept(org.apache.struts2.ActionInvocation invocation) {
32+
return shouldIntercept(ActionInvocation.adapt(invocation));
33+
}
34+
35+
boolean shouldIntercept(ActionInvocation invocation);
2836
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@
1818
*/
1919
package com.opensymphony.xwork2.interceptor;
2020

21+
import com.opensymphony.xwork2.ActionInvocation;
22+
2123
/**
2224
* {@inheritDoc}
2325
*
2426
* @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.Interceptor} instead.
2527
*/
2628
@Deprecated
2729
public interface Interceptor extends org.apache.struts2.interceptor.Interceptor {
30+
31+
default String intercept(org.apache.struts2.ActionInvocation invocation) throws Exception {
32+
return intercept(ActionInvocation.adapt(invocation));
33+
}
34+
35+
String intercept(ActionInvocation invocation) throws Exception;
2836
}

0 commit comments

Comments
 (0)