KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > TransitionSet


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;
17
18 import java.util.Iterator JavaDoc;
19 import java.util.LinkedList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.springframework.core.style.StylerUtils;
23 import org.springframework.webflow.core.collection.CollectionUtils;
24 import org.springframework.webflow.execution.RequestContext;
25
26 /**
27  * A typed set of transitions for use internally by artifacts that can
28  * apply transition execution logic.
29  *
30  * @see TransitionableState#getTransitionSet()
31  * @see Flow#getGlobalTransitionSet()
32  *
33  * @author Keith Donald
34  */

35 public class TransitionSet {
36
37     /**
38      * The set of transitions.
39      */

40     private List JavaDoc transitions = new LinkedList JavaDoc();
41
42     /**
43      * Add a transition to this set.
44      * @param transition the transition to add
45      * @return true if this set's contents changed as a result of the add
46      * operation
47      */

48     public boolean add(Transition transition) {
49         if (contains(transition)) {
50             return false;
51         }
52         return transitions.add(transition);
53     }
54
55     /**
56      * Add a collection of transition instances to this set.
57      * @param transitions the transitions to add
58      * @return true if this set's contents changed as a result of the add
59      * operation
60      */

61     public boolean addAll(Transition[] transitions) {
62         return CollectionUtils.addAllNoDuplicates(this.transitions, transitions);
63     }
64
65     /**
66      * Tests if this transition is in this set.
67      * @param transition the transition
68      * @return true if the transition is contained in this set, false otherwise
69      */

70     public boolean contains(Transition transition) {
71         return transitions.contains(transition);
72     }
73
74     /**
75      * Remove the transition instance from this set.
76      * @param transition the transition to remove
77      * @return true if this list's contents changed as a result of the remove
78      * operation
79      */

80     public boolean remove(Transition transition) {
81         return transitions.remove(transition);
82     }
83
84     /**
85      * Returns the size of this transition set.
86      * @return the exception handler set size
87      */

88     public int size() {
89         return transitions.size();
90     }
91
92     /**
93      * Convert this set to a typed transition array.
94      * @return the transition set as a typed array
95      */

96     public Transition[] toArray() {
97         return (Transition[])transitions.toArray(new Transition[transitions.size()]);
98     }
99
100     /**
101      * Returns a list of the supported transitional criteria used to match
102      * transitions in this state.
103      * @return the list of transitional criteria
104      */

105     public TransitionCriteria[] getTransitionCriterias() {
106         TransitionCriteria[] criterias = new TransitionCriteria[transitions.size()];
107         int i = 0;
108         Iterator JavaDoc it = transitions.iterator();
109         while (it.hasNext()) {
110             criterias[i++] = ((Transition)it.next()).getMatchingCriteria();
111         }
112         return criterias;
113     }
114
115     /**
116      * Gets a transition for given flow execution request context. The first
117      * matching transition will be returned.
118      * @param context a flow execution context
119      * @return the transition, or null if no transition matches
120      */

121     public Transition getTransition(RequestContext context) {
122         Iterator JavaDoc it = transitions.iterator();
123         while (it.hasNext()) {
124             Transition transition = (Transition)it.next();
125             if (transition.matches(context)) {
126                 return transition;
127             }
128         }
129         return null;
130     }
131
132     /**
133      * Returns whether or not this list has a transition that will fire for
134      * given flow execution request context.
135      * @param context a flow execution context
136      */

137     public boolean hasMatchingTransition(RequestContext context) {
138         return getTransition(context) != null;
139     }
140
141     public String JavaDoc toString() {
142         return StylerUtils.style(transitions);
143     }
144 }
Popular Tags