1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.config.spring.parsers.collection; |
11 | |
|
12 | |
import org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate; |
13 | |
import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser; |
14 | |
|
15 | |
import java.util.Map; |
16 | |
|
17 | |
import org.springframework.beans.factory.BeanDefinitionStoreException; |
18 | |
import org.springframework.beans.factory.config.MapFactoryBean; |
19 | |
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
20 | |
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
21 | |
import org.springframework.beans.factory.xml.ParserContext; |
22 | |
import org.w3c.dom.Element; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class OrphanMapDefinitionParser extends AbstractMuleBeanDefinitionParser |
28 | |
{ |
29 | |
protected Class mapClass; |
30 | |
protected String name; |
31 | |
protected boolean attributeName; |
32 | 0 | protected boolean dynamicName = false; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public OrphanMapDefinitionParser(Class mapClass) |
40 | 0 | { |
41 | 0 | this.mapClass = mapClass; |
42 | 0 | dynamicName = true; |
43 | 0 | } |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public OrphanMapDefinitionParser(Class mapClass, String name) |
52 | 0 | { |
53 | 0 | this.mapClass = mapClass; |
54 | 0 | this.name = name; |
55 | 0 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public OrphanMapDefinitionParser(Class mapClass, String name, boolean attributeName) |
66 | 0 | { |
67 | 0 | this.mapClass = mapClass; |
68 | 0 | this.name = name; |
69 | 0 | this.attributeName = attributeName; |
70 | 0 | } |
71 | |
|
72 | |
protected Class getBeanClass(Element element) |
73 | |
{ |
74 | 0 | return MapFactoryBean.class; |
75 | |
} |
76 | |
|
77 | |
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) |
78 | |
{ |
79 | 0 | Map parsedMap = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition()); |
80 | 0 | builder.addPropertyValue("sourceMap", parsedMap); |
81 | 0 | builder.addPropertyValue("targetMapClass", mapClass.getName()); |
82 | 0 | getBeanAssembler(element, builder).setBeanFlag(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE); |
83 | 0 | } |
84 | |
|
85 | |
@Override |
86 | |
|
87 | |
protected void preProcess(Element element) |
88 | |
{ |
89 | 0 | super.preProcess(element); |
90 | 0 | if (dynamicName) |
91 | |
{ |
92 | 0 | name = null; |
93 | |
} |
94 | 0 | } |
95 | |
|
96 | |
@java.lang.Override |
97 | |
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException |
98 | |
{ |
99 | 0 | if(attributeName) |
100 | |
{ |
101 | 0 | return element.getAttribute(name); |
102 | |
} |
103 | 0 | return name; |
104 | |
} |
105 | |
} |