1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.config.spring.util; |
8 | |
|
9 | |
import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser; |
10 | |
import org.mule.util.StringUtils; |
11 | |
import org.mule.util.XMLUtils; |
12 | |
|
13 | |
import org.apache.commons.logging.Log; |
14 | |
import org.apache.commons.logging.LogFactory; |
15 | |
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; |
16 | |
import org.w3c.dom.Element; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | 0 | public class SpringXMLUtils extends XMLUtils |
23 | |
{ |
24 | |
|
25 | 0 | private static final Log logger = LogFactory.getLog(SpringXMLUtils.class); |
26 | |
|
27 | |
public static final String MULE_DEFAULT_NAMESPACE = "http://www.mulesoft.org/schema/mule/core"; |
28 | |
public static final String MULE_NAMESPACE_PREFIX = "http://www.mulesoft.org/schema/mule/"; |
29 | |
|
30 | |
public static boolean isMuleNamespace(Element element) |
31 | |
{ |
32 | 0 | String ns = element.getNamespaceURI(); |
33 | 0 | return ns != null && ns.startsWith(MULE_NAMESPACE_PREFIX); |
34 | |
} |
35 | |
|
36 | |
public static boolean isBeansNamespace(Element element) |
37 | |
{ |
38 | 0 | String ns = element.getNamespaceURI(); |
39 | 0 | return ns != null && ns.equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI); |
40 | |
} |
41 | |
|
42 | |
public static String getNameOrId(Element element) |
43 | |
{ |
44 | 0 | String id = element.getAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_ID); |
45 | 0 | String name = element.getAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME); |
46 | 0 | if (StringUtils.isBlank(id)) |
47 | |
{ |
48 | 0 | if (StringUtils.isBlank(name)) |
49 | |
{ |
50 | 0 | return ""; |
51 | |
} |
52 | |
else |
53 | |
{ |
54 | 0 | return name; |
55 | |
} |
56 | |
} |
57 | |
else |
58 | |
{ |
59 | 0 | if (!StringUtils.isBlank(name) && !name.equals(id)) |
60 | |
{ |
61 | 0 | logger.warn("Id (" + id + ") and name (" + name + ") differ for " + elementToString(element)); |
62 | |
} |
63 | 0 | return id; |
64 | |
} |
65 | |
} |
66 | |
|
67 | |
} |