-
Notifications
You must be signed in to change notification settings - Fork 231
/
ActionTransitionCriteria.java
94 lines (84 loc) · 3 KB
/
ActionTransitionCriteria.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright 2004-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.webflow.engine.support;
import org.springframework.webflow.engine.TransitionCriteria;
import org.springframework.webflow.execution.Action;
import org.springframework.webflow.execution.ActionExecutor;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;
/**
* A transition criteria that will execute an action when tested and return <code>true</code> if the action's result is
* equal to the 'trueEventId', <code>false</code> otherwise.
* <p>
* This effectively adapts an <code>Action</code> to a <code>TransitionCriteria</code>.
*
* @see org.springframework.webflow.execution.Action
* @see org.springframework.webflow.engine.TransitionCriteria
*
* @author Keith Donald
* @author Erwin Vervaet
*/
public class ActionTransitionCriteria implements TransitionCriteria {
/**
* The result event id that should map to a <code>true</code> return value.
*/
private String[] trueEventIds = new String[] { "success", "yes", "true" };
/**
* The action to execute when the criteria is tested, annotated with usage attributes.
*/
private Action action;
/**
* Create action transition criteria delegating to the specified action.
* @param action the action
*/
public ActionTransitionCriteria(Action action) {
this.action = action;
}
/**
* Returns the action result <code>eventIds</code> that should cause this criteria to return true (it will return
* false otherwise). Defaults to "success".
*/
public String[] getTrueEventIds() {
return trueEventIds;
}
/**
* Sets the action result <code>eventIds</code> that should cause this precondition to return true (it will return
* false otherwise).
* @param trueEventIds the true result event IDs
*/
public void setTrueEventIds(String... trueEventIds) {
this.trueEventIds = trueEventIds;
}
/**
* Returns the action wrapped by this object.
* @return the action
*/
protected Action getAction() {
return action;
}
public boolean test(RequestContext context) {
Event result = ActionExecutor.execute(getAction(), context);
return result != null && isTrueEvent(result.getId());
}
private boolean isTrueEvent(String eventId) {
for (String trueEventId : trueEventIds) {
if (trueEventId.equals(eventId)) {
return true;
}
}
return false;
}
}