1
2
3
4
5
6
7 package org.mule.config.spring.parsers.collection;
8
9 import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
10 import org.mule.config.spring.util.SpringXMLUtils;
11
12 import org.springframework.beans.factory.config.MapFactoryBean;
13 import org.springframework.beans.factory.config.RuntimeBeanReference;
14 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
15 import org.springframework.beans.factory.support.ManagedMap;
16 import org.springframework.beans.factory.xml.ParserContext;
17 import org.w3c.dom.Attr;
18 import org.w3c.dom.Element;
19 import org.w3c.dom.NamedNodeMap;
20
21
22
23
24 public class AttributeMapDefinitionParser extends ChildDefinitionParser
25 {
26 public AttributeMapDefinitionParser(String setter)
27 {
28 super(setter, ManagedMap.class);
29 }
30
31 protected Class getBeanClass(Element element)
32 {
33 return MapFactoryBean.class;
34 }
35
36 protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
37 {
38 ManagedMap values = new ManagedMap();
39 NamedNodeMap attributes = element.getAttributes();
40 for (int x = 0; x < attributes.getLength(); x++)
41 {
42 Attr attribute = (Attr) attributes.item(x);
43 String oldName = SpringXMLUtils.attributeName(attribute);
44
45 String name = beanPropertyConfiguration.translateName(oldName);
46 Object value = beanPropertyConfiguration.translateValue(oldName, attribute.getNodeValue());
47 if (beanPropertyConfiguration.isReference(oldName))
48 {
49 values.put(name, new RuntimeBeanReference(attribute.getNodeValue()));
50 }
51 else
52 {
53 values.put(name, value);
54 }
55 }
56 builder.addPropertyValue("sourceMap", values);
57 builder.addPropertyValue("targetMapClass", super.getBeanClass(element));
58 postProcess(parserContext, getBeanAssembler(element, builder), element);
59 }
60
61 }