1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.jdbc.config;
12
13 import org.mule.config.spring.parsers.PreProcessor;
14 import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration;
15 import org.mule.config.spring.util.SpringXMLUtils;
16 import org.mule.util.StringUtils;
17
18 import org.w3c.dom.Attr;
19 import org.w3c.dom.Element;
20 import org.w3c.dom.NamedNodeMap;
21
22 public class CheckDatabaseOrUrl implements PreProcessor
23 {
24 @Override
25 public void preProcess(PropertyConfiguration config, Element element)
26 {
27 boolean urlAttributePresent = false;
28 boolean databaseAttributePresent = false;
29
30 NamedNodeMap attributes = element.getAttributes();
31 for (int i = 0; i < attributes.getLength(); i++)
32 {
33 String attributeName = SpringXMLUtils.attributeName((Attr) attributes.item(i));
34 if (StringUtils.equalsIgnoreCase(attributeName, "url"))
35 {
36 urlAttributePresent = true;
37 }
38 else if (StringUtils.equalsIgnoreCase(attributeName, "database"))
39 {
40 databaseAttributePresent = true;
41 }
42 }
43
44 if (urlAttributePresent && databaseAttributePresent)
45 {
46 throw new IllegalStateException("Either \"url\" or \"database\" can be configured, not both");
47 }
48 }
49 }