KickJava   Java API By Example, From Geeks To Geeks.

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


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.Arrays JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.LinkedList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.springframework.core.style.StylerUtils;
24 import org.springframework.webflow.execution.Action;
25 import org.springframework.webflow.execution.RequestContext;
26
27 /**
28  * An ordered, typed list of actions, mainly for use internally by flow artifacts
29  * that can execute groups of actions.
30  *
31  * @see Flow#getStartActionList()
32  * @see Flow#getEndActionList()
33  * @see State#getEntryActionList()
34  * @see ActionState#getActionList()
35  * @see TransitionableState#getExitActionList()
36  * @see ViewState#getRenderActionList()
37  *
38  * @author Keith Donald
39  */

40 public class ActionList {
41
42     /**
43      * The lists of actions.
44      */

45     private List JavaDoc actions = new LinkedList JavaDoc();
46
47     /**
48      * Add an action to this list.
49      * @param action the action to add
50      * @return true if this list's contents changed as a result of the add
51      * operation
52      */

53     public boolean add(Action action) {
54         return actions.add(action);
55     }
56
57     /**
58      * Add a collection of actions to this list.
59      * @param actions the actions to add
60      * @return true if this list's contents changed as a result of the add
61      * operation
62      */

63     public boolean addAll(Action[] actions) {
64         if (actions == null) {
65             return false;
66         }
67         return this.actions.addAll(Arrays.asList(actions));
68     }
69
70     /**
71      * Tests if the action is in this list.
72      * @param action the action
73      * @return true if the action is contained in this list, false otherwise
74      */

75     public boolean contains(Action action) {
76         return actions.contains(action);
77     }
78
79     /**
80      * Remove the action instance from this list.
81      * @param action the action to add
82      * @return true if this list's contents changed as a result of the remove
83      * operation
84      */

85     public boolean remove(Action action) {
86         return actions.remove(action);
87     }
88
89     /**
90      * Returns the size of this action list.
91      * @return the action list size.
92      */

93     public int size() {
94         return actions.size();
95     }
96
97     /**
98      * Returns the action in this list at the provided index.
99      * @param index the action index
100      * @return the action the action
101      */

102     public Action get(int index) throws IndexOutOfBoundsException JavaDoc {
103         return (Action)actions.get(index);
104     }
105
106     /**
107      * Returns the action in this list at the provided index, exposing it as an
108      * annotated action. This allows clients to access specific properties about
109      * a target action instance if they exist.
110      * @return the action, as an annotated action
111      */

112     public AnnotatedAction getAnnotated(int index) throws IndexOutOfBoundsException JavaDoc {
113         Action action = get(index);
114         if (action instanceof AnnotatedAction) {
115             return (AnnotatedAction)action;
116         }
117         else {
118             // wrap the action; no annotations will be available
119
return new AnnotatedAction(action);
120         }
121     }
122
123     /**
124      * Returns an iterator over this action list.
125      */

126     public Iterator JavaDoc iterator() {
127         return actions.iterator();
128     }
129
130     /**
131      * Convert this list to a typed action array.
132      * @return the action list, as a typed array
133      */

134     public Action[] toArray() {
135         return (Action[])actions.toArray(new Action[actions.size()]);
136     }
137
138     /**
139      * Returns the list of actions in this list as a typed annotated action
140      * array. This is a convenience method allowing clients to access properties
141      * about an action if they exist.
142      * @return the annotated action list, as a typed array
143      */

144     public AnnotatedAction[] toAnnotatedArray() {
145         AnnotatedAction[] annotatedActions = new AnnotatedAction[actions.size()];
146         for (int i = 0; i < size(); i++) {
147             annotatedActions[i] = getAnnotated(i);
148         }
149         return annotatedActions;
150     }
151
152     /**
153      * Executes the actions contained within this action list. Simply iterates
154      * over each action and calls execute. Action result events are ignored.
155      * @param context the action execution request context
156      */

157     public void execute(RequestContext context) {
158         Iterator JavaDoc it = actions.iterator();
159         while (it.hasNext()) {
160             ActionExecutor.execute((Action)it.next(), context);
161         }
162     }
163
164     public String JavaDoc toString() {
165         return StylerUtils.style(actions);
166     }
167 }
Popular Tags