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 super(NamespaceManager.class, true);
33 }
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 Map<String, String> ns = new HashMap<String, String>();
49
50 for (int i = 0; i < element.getParentNode().getAttributes().getLength(); i++)
51 {
52 Node node = element.getParentNode().getAttributes().item(i);
53 String prefix = node.getNodeName();
54 if (prefix.startsWith("xmlns"))
55 {
56 if (prefix.indexOf(":") > 0)
57 {
58 prefix = prefix.substring(prefix.indexOf(":") + 1);
59 }
60 else
61 {
62 prefix = "";
63 }
64 ns.put(prefix, node.getNodeValue());
65 }
66 }
67 builder.addPropertyValue("configNamespaces", ns);
68
69
70 element.setAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_ID, MuleProperties.OBJECT_MULE_NAMESPACE_MANAGER);
71
72 super.doParse(element, parserContext, builder);
73 }
74
75 @Override
76 public String getBeanName(Element element)
77 {
78 return MuleProperties.OBJECT_MULE_NAMESPACE_MANAGER;
79 }
80 }