1 16 package org.springframework.webflow.config; 17 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 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 ; 32 33 38 class ExecutionAttributesBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { 39 40 42 private static final String ATTRIBUTE_ELEMENT = "attribute"; 43 44 private static final String NAME_ATTRIBUTE = "name"; 45 46 private static final String TYPE_ATTRIBUTE = "type"; 47 48 private static final String VALUE_ATTRIBUTE = "value"; 49 50 52 private static final String SOURCE_MAP_PROPERTY = "sourceMap"; 53 54 protected Class getBeanClass(Element element) { 55 return MapFactoryBean.class; 56 } 57 58 protected void doParse(Element element, BeanDefinitionBuilder definitionBuilder) { 59 List attributeElements = DomUtils.getChildElementsByTagName(element, ATTRIBUTE_ELEMENT); 60 Map attributeMap = new ManagedMap(attributeElements.size()); 61 putAttributes(attributeMap, attributeElements); 62 putSpecialAttributes(attributeMap, element); 63 definitionBuilder.addPropertyValue(SOURCE_MAP_PROPERTY, attributeMap); 64 } 65 66 69 private void putAttributes(Map attributeMap, List attributeElements) { 70 for (Iterator i = attributeElements.iterator(); i.hasNext();) { 71 Element attributeElement = (Element )i.next(); 72 String type = attributeElement.getAttribute(TYPE_ATTRIBUTE); 73 Object 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 87 private void putSpecialAttributes(Map attributeMap, Element element) { 88 putAlwaysRedirectOnPauseAttribute(attributeMap, 89 DomUtils.getChildElementByTagName(element, ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE)); 90 } 91 92 96 private void putAlwaysRedirectOnPauseAttribute(Map attributeMap, Element element) { 97 if (element != null) { 98 Boolean value = Boolean.valueOf(element.getAttribute(VALUE_ATTRIBUTE)); 99 attributeMap.put(ApplicationViewSelector.ALWAYS_REDIRECT_ON_PAUSE_ATTRIBUTE, value); 100 } 101 } 102 } | Popular Tags |