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