1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.module.xml.config; |
11 | |
|
12 | |
import org.mule.api.config.MuleProperties; |
13 | |
import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser; |
14 | |
import org.mule.config.spring.parsers.generic.OrphanDefinitionParser; |
15 | |
import org.mule.module.xml.util.NamespaceManager; |
16 | |
|
17 | |
import java.util.HashMap; |
18 | |
import java.util.Map; |
19 | |
|
20 | |
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
21 | |
import org.springframework.beans.factory.xml.ParserContext; |
22 | |
import org.w3c.dom.Element; |
23 | |
import org.w3c.dom.Node; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class NamespaceManagerDefinitionParser extends OrphanDefinitionParser |
29 | |
{ |
30 | |
public NamespaceManagerDefinitionParser() |
31 | |
{ |
32 | 0 | super(NamespaceManager.class, true); |
33 | 0 | } |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
@Override |
46 | |
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) |
47 | |
{ |
48 | 0 | Map<String, String> ns = new HashMap<String, String>(); |
49 | |
|
50 | 0 | for (int i = 0; i < element.getParentNode().getAttributes().getLength(); i++) |
51 | |
{ |
52 | 0 | Node node = element.getParentNode().getAttributes().item(i); |
53 | 0 | String prefix = node.getNodeName(); |
54 | 0 | if (prefix.startsWith("xmlns")) |
55 | |
{ |
56 | 0 | if (prefix.indexOf(":") > 0) |
57 | |
{ |
58 | 0 | prefix = prefix.substring(prefix.indexOf(":") + 1); |
59 | |
} |
60 | |
else |
61 | |
{ |
62 | 0 | prefix = ""; |
63 | |
} |
64 | 0 | ns.put(prefix, node.getNodeValue()); |
65 | |
} |
66 | |
} |
67 | 0 | builder.addPropertyValue("configNamespaces", ns); |
68 | |
|
69 | |
|
70 | 0 | element.setAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_ID, MuleProperties.OBJECT_MULE_NAMESPACE_MANAGER); |
71 | |
|
72 | 0 | super.doParse(element, parserContext, builder); |
73 | 0 | } |
74 | |
|
75 | |
@Override |
76 | |
public String getBeanName(Element element) |
77 | |
{ |
78 | 0 | return MuleProperties.OBJECT_MULE_NAMESPACE_MANAGER; |
79 | |
} |
80 | |
} |