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