1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring.parsers; |
8 | |
|
9 | |
import org.mule.config.spring.parsers.assembly.BeanAssembler; |
10 | |
import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration; |
11 | |
import org.mule.config.spring.parsers.assembly.configuration.ReusablePropertyConfiguration; |
12 | |
import org.mule.config.spring.parsers.assembly.configuration.TempWrapperPropertyConfiguration; |
13 | |
import org.mule.config.spring.util.SpringXMLUtils; |
14 | |
import org.mule.util.StringUtils; |
15 | |
|
16 | |
import org.springframework.beans.factory.config.BeanDefinition; |
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 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public abstract class AbstractHierarchicalDefinitionParser extends AbstractMuleBeanDefinitionParser |
33 | |
{ |
34 | |
|
35 | 0 | private ReusablePropertyConfiguration targetPropertyConfiguration = |
36 | |
new ReusablePropertyConfiguration( |
37 | |
new TempWrapperPropertyConfiguration(beanPropertyConfiguration, false)); |
38 | 0 | private BeanDefinition forcedParent = null; |
39 | |
|
40 | |
public PropertyConfiguration getTargetPropertyConfiguration() |
41 | |
{ |
42 | 0 | return targetPropertyConfiguration; |
43 | |
} |
44 | |
|
45 | |
protected String getParentBeanName(Element element) |
46 | |
{ |
47 | 0 | return ((Element) element.getParentNode()).getAttribute(ATTRIBUTE_NAME); |
48 | |
} |
49 | |
|
50 | |
public BeanDefinition getParentBeanDefinition(Element element) |
51 | |
{ |
52 | 0 | if (null != forcedParent) |
53 | |
{ |
54 | 0 | return forcedParent; |
55 | |
} |
56 | |
else |
57 | |
{ |
58 | 0 | String parentBean = getParentBeanName(element); |
59 | 0 | if (StringUtils.isBlank(parentBean)) |
60 | |
{ |
61 | 0 | throw new IllegalStateException("No parent for " + SpringXMLUtils.elementToString(element)); |
62 | |
} |
63 | 0 | return getRegistry().getBeanDefinition(parentBean); |
64 | |
} |
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
protected BeanAssembler getBeanAssembler(Element element, BeanDefinitionBuilder bean) |
75 | |
{ |
76 | 0 | BeanDefinition target = getParentBeanDefinition(element); |
77 | 0 | return getBeanAssemblerFactory().newBeanAssembler( |
78 | |
beanPropertyConfiguration, bean, targetPropertyConfiguration, target); |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
protected BeanAssembler getOrphanBeanAssembler(Element element, BeanDefinitionBuilder bean) |
90 | |
{ |
91 | 0 | return super.getBeanAssembler(element, bean); |
92 | |
} |
93 | |
|
94 | |
public void forceParent(BeanDefinition parent) |
95 | |
{ |
96 | 0 | forcedParent = parent; |
97 | 0 | } |
98 | |
|
99 | |
protected void preProcess(Element element) |
100 | |
{ |
101 | 0 | super.preProcess(element); |
102 | 0 | targetPropertyConfiguration.reset(); |
103 | 0 | } |
104 | |
|
105 | |
|
106 | |
protected void postProcess(ParserContext context, BeanAssembler assembler, Element element) |
107 | |
{ |
108 | 0 | super.postProcess(context, assembler, element); |
109 | 0 | forcedParent = null; |
110 | 0 | } |
111 | |
|
112 | |
} |