KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
19 import java.util.Set JavaDoc;
20
21 import org.springframework.core.CollectionFactory;
22 import org.springframework.util.Assert;
23 import org.springframework.webflow.definition.FlowDefinition;
24 import org.springframework.webflow.execution.FlowExecutionListener;
25
26 /**
27  * A holder that holds a listener plus a set of criteria defining the flows in
28  * which that listener applies.
29  * <p>
30  * This is an internal helper class used by the {@link ConditionalFlowExecutionListenerLoader}.
31  *
32  * @see ConditionalFlowExecutionListenerLoader
33  *
34  * @author Keith Donald
35  */

36 class ConditionalFlowExecutionListenerHolder {
37
38     /**
39      * The held listener.
40      */

41     private FlowExecutionListener listener;
42
43     /**
44      * The listener criteria set.
45      */

46     private Set JavaDoc criteriaSet = CollectionFactory.createLinkedSetIfPossible(3);
47
48     /**
49      * Create a new conditional flow execution listener holder.
50      * @param listener the listener to hold
51      */

52     public ConditionalFlowExecutionListenerHolder(FlowExecutionListener listener) {
53         Assert.notNull(listener, "The listener is required");
54         this.listener = listener;
55     }
56
57     /**
58      * Returns the held listener.
59      */

60     public FlowExecutionListener getListener() {
61         return listener;
62     }
63
64     /**
65      * Add given criteria.
66      */

67     public void add(FlowExecutionListenerCriteria criteria) {
68         criteriaSet.add(criteria);
69     }
70
71     /**
72      * Remove given criteria. If not present, does nothing.
73      */

74     public void remove(FlowExecutionListenerCriteria criteria) {
75         criteriaSet.remove(criteria);
76     }
77
78     /**
79      * Are there any criteria registered?
80      */

81     public boolean isCriteriaSetEmpty() {
82         return criteriaSet.isEmpty();
83     }
84
85     /**
86      * Determines if the listener held by this holder applies to the specified
87      * flow definition. Will do a logical OR between the registered criteria.
88      * @param flowDefinition the flow
89      * @return true if yes, false otherwise
90      */

91     public boolean listenerAppliesTo(FlowDefinition flowDefinition) {
92         Iterator JavaDoc it = criteriaSet.iterator();
93         while (it.hasNext()) {
94             FlowExecutionListenerCriteria criteria = (FlowExecutionListenerCriteria)it.next();
95             if (criteria.appliesTo(flowDefinition)) {
96                 return true;
97             }
98         }
99         return false;
100     }
101 }
Popular Tags