1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.parsers.processors; |
12 | |
|
13 | |
import org.mule.config.spring.parsers.PostProcessor; |
14 | |
import org.mule.config.spring.parsers.assembly.BeanAssembler; |
15 | |
import org.mule.config.spring.parsers.assembly.BeanAssemblerFactory; |
16 | |
import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration; |
17 | |
import org.mule.config.spring.util.SpringXMLUtils; |
18 | |
|
19 | |
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; |
20 | |
import org.springframework.beans.factory.xml.ParserContext; |
21 | |
import org.w3c.dom.Element; |
22 | |
import org.w3c.dom.Node; |
23 | |
import org.w3c.dom.NodeList; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public abstract class AbstractChildElementIterator implements PostProcessor |
45 | |
{ |
46 | |
|
47 | |
private BeanAssemblerFactory beanAssemblerFactory; |
48 | |
private PropertyConfiguration configuration; |
49 | |
|
50 | |
public AbstractChildElementIterator(BeanAssemblerFactory beanAssemblerFactory, PropertyConfiguration configuration) |
51 | 0 | { |
52 | 0 | this.beanAssemblerFactory = beanAssemblerFactory; |
53 | 0 | this.configuration = configuration; |
54 | 0 | } |
55 | |
|
56 | |
public void postProcess(ParserContext context, BeanAssembler assembler, Element element) |
57 | |
{ |
58 | 0 | NodeList children = element.getChildNodes(); |
59 | 0 | for (int i = 0; i < children.getLength(); ++i) |
60 | |
{ |
61 | 0 | Node child = children.item(i); |
62 | 0 | if (child.getNodeType() == Node.ELEMENT_NODE) |
63 | |
{ |
64 | 0 | processChildElement(context, assembler, element, (Element) child); |
65 | |
} |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
protected void processChildElement(ParserContext context, BeanAssembler assembler, Element parent, Element child) |
70 | |
{ |
71 | 0 | Object childBean = null; |
72 | 0 | if (SpringXMLUtils.isBeansNamespace(child) |
73 | |
|| SpringXMLUtils.isLocalName(child, BeanDefinitionParserDelegate.REF_ELEMENT)) |
74 | |
{ |
75 | 0 | childBean = context.getDelegate().parsePropertySubElement(child, null); |
76 | |
} |
77 | |
else |
78 | |
{ |
79 | 0 | childBean = context.getDelegate().parseCustomElement(child, |
80 | |
assembler.getBean().getBeanDefinition()); |
81 | |
} |
82 | 0 | BeanAssembler targetAssembler = beanAssemblerFactory.newBeanAssembler(null, null, configuration, |
83 | |
assembler.getBean().getRawBeanDefinition()); |
84 | 0 | insertBean(targetAssembler, childBean, parent, child); |
85 | 0 | } |
86 | |
|
87 | |
protected abstract void insertBean(BeanAssembler targetAssembler, Object childBean, Element parent, Element child); |
88 | |
|
89 | |
} |