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