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 | |
private Class mapClass; |
30 | |
private String name; |
31 | 0 | private boolean dynamicName = false; |
32 | |
|
33 | |
public OrphanMapDefinitionParser(Class mapClass) |
34 | 0 | { |
35 | 0 | this.mapClass = mapClass; |
36 | 0 | dynamicName = true; |
37 | 0 | } |
38 | |
|
39 | |
public OrphanMapDefinitionParser(Class mapClass, String name) |
40 | 0 | { |
41 | 0 | this.mapClass = mapClass; |
42 | 0 | this.name = name; |
43 | 0 | } |
44 | |
|
45 | |
protected Class getBeanClass(Element element) |
46 | |
{ |
47 | 0 | return MapFactoryBean.class; |
48 | |
} |
49 | |
|
50 | |
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) |
51 | |
{ |
52 | 0 | Map parsedMap = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition()); |
53 | 0 | builder.addPropertyValue("sourceMap", parsedMap); |
54 | 0 | builder.addPropertyValue("targetMapClass", mapClass.getName()); |
55 | 0 | getBeanAssembler(element, builder).setBeanFlag(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE); |
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
protected void preProcess(Element element) |
61 | |
{ |
62 | 0 | super.preProcess(element); |
63 | 0 | if (dynamicName) |
64 | |
{ |
65 | 0 | name = null; |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException |
71 | |
{ |
72 | 0 | return name; |
73 | |
} |
74 | |
} |