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