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