KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > config > ExecutionListenersBeanDefinitionParser


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.config;
17
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.springframework.beans.factory.config.RuntimeBeanReference;
23 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
24 import org.springframework.beans.factory.support.ManagedMap;
25 import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
26 import org.springframework.beans.factory.xml.BeanDefinitionParser;
27 import org.springframework.util.xml.DomUtils;
28 import org.springframework.webflow.execution.factory.ConditionalFlowExecutionListenerLoader;
29 import org.w3c.dom.Element JavaDoc;
30
31 /**
32  * {@link BeanDefinitionParser} for the <code>&lt;execution-listeners&gt;</code>
33  * tag.
34  *
35  * @author Ben Hale
36  */

37 class ExecutionListenersBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
38     
39     // elements and attributes
40

41     private static final String JavaDoc LISTENER_ELEMENT= "listener";
42
43     // properties
44

45     private static final String JavaDoc LISTENERS_PROPERTY = "listeners";
46     
47     private static final String JavaDoc CRITERIA_ATTRIBUTE = "criteria";
48
49     private static final String JavaDoc REF_ATTRIBUTE = "ref";
50
51     protected Class JavaDoc getBeanClass(Element JavaDoc element) {
52         return ConditionalFlowExecutionListenerLoader.class;
53     }
54
55     protected void doParse(Element JavaDoc element, BeanDefinitionBuilder definitionBuilder) {
56         List JavaDoc listenerElements = DomUtils.getChildElementsByTagName(element, LISTENER_ELEMENT);
57         definitionBuilder.addPropertyValue(LISTENERS_PROPERTY, getListenersWithCriteria(listenerElements));
58     }
59
60     /**
61      * Creates a map of listeners with their associated criteria.
62      * @param listeners the list of listener elements from the bean definition
63      * @return a map containing keys that are references to given listeners
64      * and values of string that represent the criteria
65      */

66     private Map JavaDoc getListenersWithCriteria(List JavaDoc listeners) {
67         Map JavaDoc listenersWithCriteria = new ManagedMap(listeners.size());
68         for (Iterator JavaDoc i = listeners.iterator(); i.hasNext();) {
69             Element JavaDoc listenerElement = (Element JavaDoc)i.next();
70             RuntimeBeanReference ref = new RuntimeBeanReference(listenerElement.getAttribute(REF_ATTRIBUTE));
71             String JavaDoc criteria = listenerElement.getAttribute(CRITERIA_ATTRIBUTE);
72             listenersWithCriteria.put(ref, criteria);
73         }
74         return listenersWithCriteria;
75     }
76 }
Popular Tags