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 | 0 | super(setter, ManagedMap.class); |
32 | 0 | } |
33 | |
|
34 | |
protected Class getBeanClass(Element element) |
35 | |
{ |
36 | 0 | return MapFactoryBean.class; |
37 | |
} |
38 | |
|
39 | |
protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) |
40 | |
{ |
41 | 0 | ManagedMap values = new ManagedMap(); |
42 | 0 | NamedNodeMap attributes = element.getAttributes(); |
43 | 0 | for (int x = 0; x < attributes.getLength(); x++) |
44 | |
{ |
45 | 0 | Attr attribute = (Attr) attributes.item(x); |
46 | 0 | String oldName = SpringXMLUtils.attributeName(attribute); |
47 | |
|
48 | 0 | String name = beanPropertyConfiguration.translateName(oldName); |
49 | 0 | Object value = beanPropertyConfiguration.translateValue(oldName, attribute.getNodeValue()); |
50 | 0 | if (beanPropertyConfiguration.isReference(oldName)) |
51 | |
{ |
52 | 0 | values.put(name, new RuntimeBeanReference(attribute.getNodeValue())); |
53 | |
} |
54 | |
else |
55 | |
{ |
56 | 0 | values.put(name, value); |
57 | |
} |
58 | |
} |
59 | 0 | builder.addPropertyValue("sourceMap", values); |
60 | 0 | builder.addPropertyValue("targetMapClass", super.getBeanClass(element)); |
61 | 0 | postProcess(parserContext, getBeanAssembler(element, builder), element); |
62 | 0 | } |
63 | |
|
64 | |
} |