KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > support > EventIdTransitionCriteria


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
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, Serializable JavaDoc {
36
37     /**
38      * The event id to match.
39      */

40     private String JavaDoc eventId;
41     
42     /**
43      * Whether or not to match case sensitively. Default is true.
44      */

45     private boolean caseSensitive = true;
46
47     /**
48      * Create a new event id matching criteria object.
49      * @param eventId the event id
50      */

51     public EventIdTransitionCriteria(String JavaDoc eventId) {
52         Assert.hasText(eventId, "The event id is required");
53         this.eventId = eventId;
54     }
55
56     /**
57      * Returns the event id to match.
58      */

59     public String JavaDoc getEventId() {
60         return eventId;
61     }
62     
63     /**
64      * Set whether or not the event id should be matched in a case sensitve
65      * manner. Defaults to true.
66      */

67     public void setCaseSensitive(boolean caseSensitive) {
68         this.caseSensitive = caseSensitive;
69     }
70
71     public boolean test(RequestContext context) {
72         Event lastEvent = context.getLastEvent();
73         if (lastEvent == null) {
74             return false;
75         }
76         if (caseSensitive) {
77             return eventId.equals(lastEvent.getId());
78         }
79         else {
80             return eventId.equalsIgnoreCase(lastEvent.getId());
81         }
82     }
83
84     public String JavaDoc toString() {
85         return "[eventId = '" + eventId + "']";
86     }
87 }
Popular Tags