KickJava   Java API By Example, From Geeks To Geeks.

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


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.MapFactoryBean;
23 import org.springframework.beans.factory.config.TypedStringValue;
24 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
25 import org.springframework.beans.factory.support.ManagedMap;
26 import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
27 import org.springframework.beans.factory.xml.BeanDefinitionParser;
28 import org.springframework.util.StringUtils;
29 import org.springframework.util.xml.DomUtils;
30 import org.springframework.webflow.engine.support.ApplicationViewSelector;
31 import org.w3c.dom.Element JavaDoc;
32
33 /**
34  * {@link BeanDefinitionParser} for the <code>&lt;execution-attributes&gt;</code> tag.
35  *
36  * @author Ben Hale
37  */

38 class ExecutionAttributesBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
39     
40     // elements and attributes
41

42     private static final String JavaDoc ATTRIBUTE_ELEMENT = "attribute";
43
44     private static final String JavaDoc NAME_ATTRIBUTE = "name";
45
46     private static final String JavaDoc TYPE_ATTRIBUTE = "type";
47
48     private static final String JavaDoc VALUE_ATTRIBUTE = "value";
49
50     // properties
51

52     private static final String JavaDoc SOURCE_MAP_PROPERTY = "sourceMap";
53
54     protected Class JavaDoc getBeanClass(Element JavaDoc element) {
55         return MapFactoryBean.class;
56     }
57
58     protected void doParse(Element JavaDoc element, BeanDefinitionBuilder definitionBuilder) {
59         List JavaDoc attributeElements = DomUtils.getChildElementsByTagName(element, ATTRIBUTE_ELEMENT);
60         Map JavaDoc attributeMap = new ManagedMap(attributeElements.size());
61         putAttributes(attributeMap, attributeElements);
62         putSpecialAttributes(attributeMap, element);
63         definitionBuilder.addPropertyValue(SOURCE_MAP_PROPERTY, attributeMap);
64     }
65
66     /**
67      * Add all attributes defined in given list of attribute elements to given map.
68      */

69     private void putAttributes(Map JavaDoc attributeMap, List JavaDoc attributeElements) {
70         for (Iterator JavaDoc i = attributeElements.iterator(); i.hasNext();) {
71             Element JavaDoc attributeElement = (Element JavaDoc)i.next();
72             String JavaDoc type = attributeElement.getAttribute(TYPE_ATTRIBUTE);
73             Object JavaDoc value;
74             if (StringUtils.hasText(type)) {
75                 value = new TypedStringValue(attributeElement.getAttribute(VALUE_ATTRIBUTE), type);
76             } else {
77                 value = attributeElement.getAttribute(VALUE_ATTRIBUTE);
78             }
79             attributeMap.put(attributeElement.getAttribute(NAME_ATTRIBUTE), value);
80         }
81     }
82
83     /**
84      * Add all non-generic (special) attributes defined in given element
85      * to given map.
86      */

87     private void putSpecialAttributes(Map JavaDoc attributeMap, Element JavaDoc element) {
88         putAlwaysRedirectOnPauseAttribute(attributeMap,
89                 DomUtils.getChildElementByTagName(element, ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE));
90     }
91
92     /**
93      * Parse the "alwaysRedirectOnPause" attribute from given element and
94      * add it to given map.
95      */

96     private void putAlwaysRedirectOnPauseAttribute(Map JavaDoc attributeMap, Element JavaDoc element) {
97         if (element != null) {
98             Boolean JavaDoc value = Boolean.valueOf(element.getAttribute(VALUE_ATTRIBUTE));
99             attributeMap.put(ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE, value);
100         }
101     }
102 }
Popular Tags