01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.webflow.engine.support;
17:
18: import java.io.Serializable;
19:
20: import org.springframework.util.Assert;
21: import org.springframework.webflow.engine.TransitionCriteria;
22: import org.springframework.webflow.execution.Event;
23: import org.springframework.webflow.execution.RequestContext;
24:
25: /**
26: * Simple transition criteria that matches on an eventId and nothing else.
27: * Specifically, if the id of the last event that occured equals
28: * {@link #getEventId()} this criteria will return true.
29: *
30: * @see RequestContext#getLastEvent()
31: *
32: * @author Erwin Vervaet
33: * @author Keith Donald
34: */
35: public class EventIdTransitionCriteria implements TransitionCriteria,
36: Serializable {
37:
38: /**
39: * The event id to match.
40: */
41: private String eventId;
42:
43: /**
44: * Whether or not to match case sensitively. Default is true.
45: */
46: private boolean caseSensitive = true;
47:
48: /**
49: * Create a new event id matching criteria object.
50: * @param eventId the event id
51: */
52: public EventIdTransitionCriteria(String eventId) {
53: Assert.hasText(eventId, "The event id is required");
54: this .eventId = eventId;
55: }
56:
57: /**
58: * Returns the event id to match.
59: */
60: public String getEventId() {
61: return eventId;
62: }
63:
64: /**
65: * Set whether or not the event id should be matched in a case sensitve
66: * manner. Defaults to true.
67: */
68: public void setCaseSensitive(boolean caseSensitive) {
69: this .caseSensitive = caseSensitive;
70: }
71:
72: public boolean test(RequestContext context) {
73: Event lastEvent = context.getLastEvent();
74: if (lastEvent == null) {
75: return false;
76: }
77: if (caseSensitive) {
78: return eventId.equals(lastEvent.getId());
79: } else {
80: return eventId.equalsIgnoreCase(lastEvent.getId());
81: }
82: }
83:
84: public String toString() {
85: return "[eventId = '" + eventId + "']";
86: }
87: }
|