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