KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > engine > impl > FlowExecutionListeners


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.impl;
17
18 import org.springframework.webflow.core.collection.AttributeMap;
19 import org.springframework.webflow.core.collection.MutableAttributeMap;
20 import org.springframework.webflow.definition.FlowDefinition;
21 import org.springframework.webflow.definition.StateDefinition;
22 import org.springframework.webflow.execution.Event;
23 import org.springframework.webflow.execution.FlowExecutionException;
24 import org.springframework.webflow.execution.FlowExecutionListener;
25 import org.springframework.webflow.execution.FlowSession;
26 import org.springframework.webflow.execution.RequestContext;
27 import org.springframework.webflow.execution.ViewSelection;
28
29 /**
30  * A helper that aids in publishing events to an array of
31  * <code>FlowExecutionListener</code> objects.
32  *
33  * @see org.springframework.webflow.execution.FlowExecutionListener
34  *
35  * @author Keith Donald
36  * @author Erwin Vervaet
37  */

38 class FlowExecutionListeners {
39
40     /**
41      * The list of listeners that should receive event callbacks during managed
42      * flow executions.
43      */

44     private FlowExecutionListener[] listeners;
45
46     /**
47      * Create a flow execution listener helper that wraps an empty listener
48      * array.
49      */

50     public FlowExecutionListeners() {
51         this(null);
52     }
53
54     /**
55      * Create a flow execution listener helper that wraps the specified listener
56      * array.
57      * @param listeners the listener array
58      */

59     public FlowExecutionListeners(FlowExecutionListener[] listeners) {
60         if (listeners != null) {
61             this.listeners = listeners;
62         }
63         else {
64             this.listeners = new FlowExecutionListener[0];
65         }
66     }
67
68     /**
69      * Returns the wrapped listener array.
70      * @return the listener array
71      */

72     public FlowExecutionListener[] getArray() {
73         return listeners;
74     }
75
76     /**
77      * Returns the size of the listener array.
78      */

79     public int size() {
80         return listeners.length;
81     }
82
83     // methods to fire events to all listeners
84

85     /**
86      * Notify all interested listeners that a request was submitted to the flow
87      * execution.
88      */

89     public void fireRequestSubmitted(RequestContext context) {
90         for (int i = 0; i < listeners.length; i++) {
91             listeners[i].requestSubmitted(context);
92         }
93     }
94
95     /**
96      * Notify all interested listeners that the flow execution finished
97      * processing a request.
98      */

99     public void fireRequestProcessed(RequestContext context) {
100         for (int i = 0; i < listeners.length; i++) {
101             listeners[i].requestProcessed(context);
102         }
103     }
104
105     /**
106      * Notify all interested listeners that a flow execution session is
107      * starting.
108      */

109     public void fireSessionStarting(RequestContext context, FlowDefinition flow, MutableAttributeMap input) {
110         for (int i = 0; i < listeners.length; i++) {
111             listeners[i].sessionStarting(context, flow, input);
112         }
113     }
114
115     /**
116      * Notify all interested listeners that a flow execution session has
117      * started.
118      */

119     public void fireSessionStarted(RequestContext context, FlowSession session) {
120         for (int i = 0; i < listeners.length; i++) {
121             listeners[i].sessionStarted(context, session);
122         }
123     }
124
125     /**
126      * Notify all interested listeners that an event was signaled in the flow
127      * execution.
128      */

129     public void fireEventSignaled(RequestContext context, Event event) {
130         for (int i = 0; i < listeners.length; i++) {
131             listeners[i].eventSignaled(context, event);
132         }
133     }
134
135     /**
136      * Notify all interested listeners that a state is being entered in the flow
137      * execution.
138      */

139     public void fireStateEntering(RequestContext context, StateDefinition nextState) {
140         for (int i = 0; i < listeners.length; i++) {
141             listeners[i].stateEntering(context, nextState);
142         }
143     }
144
145     /**
146      * Notify all interested listeners that a state was entered in the flow
147      * execution.
148      */

149     public void fireStateEntered(RequestContext context, StateDefinition previousState) {
150         for (int i = 0; i < listeners.length; i++) {
151             listeners[i].stateEntered(context, previousState, context.getCurrentState());
152         }
153     }
154
155     /**
156      * Notify all interested listeners that a flow session was paused in the
157      * flow execution.
158      */

159     public void firePaused(RequestContext context, ViewSelection selectedView) {
160         for (int i = 0; i < listeners.length; i++) {
161             listeners[i].paused(context, selectedView);
162         }
163     }
164
165     /**
166      * Notify all interested listeners that the flow execution was resumed.
167      */

168     public void fireResumed(RequestContext context) {
169         for (int i = 0; i < listeners.length; i++) {
170             listeners[i].resumed(context);
171         }
172     }
173
174     /**
175      * Notify all interested listeners that the active flow execution session is
176      * ending.
177      */

178     public void fireSessionEnding(RequestContext context, FlowSession session, MutableAttributeMap output) {
179         for (int i = 0; i < listeners.length; i++) {
180             listeners[i].sessionEnding(context, session, output);
181         }
182     }
183
184     /**
185      * Notify all interested listeners that a flow execution session has ended.
186      */

187     public void fireSessionEnded(RequestContext context, FlowSession session, AttributeMap output) {
188         for (int i = 0; i < listeners.length; i++) {
189             listeners[i].sessionEnded(context, session, output);
190         }
191     }
192
193     /**
194      * Notify all interested listeners that a flow execution threw an exception.
195      */

196     public void fireExceptionThrown(RequestContext context, FlowExecutionException exception) {
197         for (int i = 0; i < listeners.length; i++) {
198             listeners[i].exceptionThrown(context, exception);
199         }
200     }
201 }
Popular Tags