01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
32: FlowExecutionListenerLoader {
33:
34: /**
35: * A shared listener loader instance that returns am empty listener array on each invocation.
36: */
37: public static final FlowExecutionListenerLoader EMPTY_INSTANCE = new StaticFlowExecutionListenerLoader();
38:
39: /**
40: * The listener array to return when {@link #getListeners(FlowDefinition)}
41: * is invoked.
42: */
43: private final FlowExecutionListener[] listeners;
44:
45: /**
46: * Creates a new flow execution listener loader that returns an empty
47: * listener array on each invocation.
48: */
49: private StaticFlowExecutionListenerLoader() {
50: this (new FlowExecutionListener[0]);
51: }
52:
53: /**
54: * Creates a new flow execution listener loader that returns the provided
55: * listener on each invocation.
56: * @param listener the listener
57: */
58: public StaticFlowExecutionListenerLoader(
59: FlowExecutionListener listener) {
60: this (new FlowExecutionListener[] { listener });
61: }
62:
63: /**
64: * Creates a new flow execution listener loader that returns the provided
65: * listener array on each invocation. Clients should not attempt to modify
66: * the passed in array as no deep copy is made.
67: * @param listeners the listener array.
68: */
69: public StaticFlowExecutionListenerLoader(
70: FlowExecutionListener[] listeners) {
71: Assert.notNull(listeners,
72: "The flow execution listener array is required");
73: this .listeners = listeners;
74: }
75:
76: public FlowExecutionListener[] getListeners(
77: FlowDefinition flowDefinition) {
78: return listeners;
79: }
80: }
|