KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > execution > factory > StaticFlowExecutionListenerLoader


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.execution.factory;
17
18 import org.springframework.util.Assert;
19 import org.springframework.webflow.definition.FlowDefinition;
20 import org.springframework.webflow.execution.FlowExecutionListener;
21
22 /**
23  * A simple flow execution listener loader that simply returns a static listener
24  * array on each invocation. For more elaborate needs see the
25  * {@link ConditionalFlowExecutionListenerLoader}.
26  *
27  * @see ConditionalFlowExecutionListenerLoader
28  *
29  * @author Keith Donald
30  */

31 public final class StaticFlowExecutionListenerLoader implements FlowExecutionListenerLoader {
32
33     /**
34      * A shared listener loader instance that returns am empty listener array on each invocation.
35      */

36     public static final FlowExecutionListenerLoader EMPTY_INSTANCE = new StaticFlowExecutionListenerLoader();
37     
38     /**
39      * The listener array to return when {@link #getListeners(FlowDefinition)}
40      * is invoked.
41      */

42     private final FlowExecutionListener[] listeners;
43
44     /**
45      * Creates a new flow execution listener loader that returns an empty
46      * listener array on each invocation.
47      */

48     private StaticFlowExecutionListenerLoader() {
49         this(new FlowExecutionListener[0]);
50     }
51
52     /**
53      * Creates a new flow execution listener loader that returns the provided
54      * listener on each invocation.
55      * @param listener the listener
56      */

57     public StaticFlowExecutionListenerLoader(FlowExecutionListener listener) {
58         this(new FlowExecutionListener[] { listener });
59     }
60
61     /**
62      * Creates a new flow execution listener loader that returns the provided
63      * listener array on each invocation. Clients should not attempt to modify
64      * the passed in array as no deep copy is made.
65      * @param listeners the listener array.
66      */

67     public StaticFlowExecutionListenerLoader(FlowExecutionListener[] listeners) {
68         Assert.notNull(listeners, "The flow execution listener array is required");
69         this.listeners = listeners;
70     }
71
72     public FlowExecutionListener[] getListeners(FlowDefinition flowDefinition) {
73         return listeners;
74     }
75 }
Popular Tags