5 import javax.xml.parsers.DocumentBuilder;
6 import javax.xml.parsers.DocumentBuilderFactory;
8 import org.w3c.dom.Document;
9 import org.w3c.dom.Element;
10 import org.w3c.dom.Node;
11 import org.w3c.dom.NodeList;
14 * It provides the configuration data from the "resources/config.xml" XML file
16 public class ConfigXML {
18 private String configFile = "src/main/resources/config.xml";
20 private String businessLogicNode;
22 private String businessLogicPort;
24 private String businessLogicName;
26 private static String dbFilename;
28 // Two possible values: "open" or "initialize"
29 private String dataBaseOpenMode;
31 // Two possible values: true (no instance of RemoteServer needs to be launched)
32 // or false (RemoteServer needs to be run first)
33 private boolean businessLogicLocal;
35 // Two possible values: true (if the database is in same node as business logic
36 // ) or false (in other case)
37 private boolean databaseLocal;
39 private String databaseNode;
41 private int databasePort;
45 private String password;
47 private String locale;
49 public String getLocale() {
53 public int getDatabasePort() {
57 public String getUser() {
61 public String getPassword() {
65 public boolean isDatabaseLocal() {
69 public boolean isBusinessLogicLocal() {
70 return businessLogicLocal;
73 private static ConfigXML theInstance = new ConfigXML();
78 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
79 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
80 Document doc = dBuilder.parse(new File(configFile));
81 doc.getDocumentElement().normalize();
83 NodeList list = doc.getElementsByTagName("config");
84 Element config = (Element) list.item(0); // list.item(0) is a Node that is an Element
86 // Two possible values: true (no instance of RemoteServer needs to be launched)
87 // or false (RemoteServer needs to be run first)
88 String value = ((Element) config.getElementsByTagName("businessLogic").item(0)).getAttribute("local");
89 businessLogicLocal = value.equals("true");
91 businessLogicNode = getTagValue("businessLogicNode", config);
93 businessLogicPort = getTagValue("businessLogicPort", config);
95 businessLogicName = getTagValue("businessLogicName", config);
97 locale = getTagValue("locale", config);
99 dbFilename = getTagValue("dbFilename", config);
101 // Two possible values: true (no instance of RemoteServer needs to be launched)
102 // or false (RemoteServer needs to be run first)
103 value = ((Element) config.getElementsByTagName("database").item(0)).getAttribute("local");
104 databaseLocal = value.equals("true");
106 // Two possible values: "open" or "initialize"
107 // dataBaseOpenMode= getTagValue("dataBaseOpenMode", config);
108 dataBaseOpenMode = "open";
110 databaseNode = getTagValue("databaseNode", config);
112 databasePort = Integer.parseInt(getTagValue("databasePort", config));
114 user = getTagValue("user", config);
116 password = getTagValue("password", config);
118 System.out.print("Read from config.xml: ");
119 System.out.print("\t businessLogicLocal=" + businessLogicLocal);
120 System.out.print("\t databaseLocal=" + databaseLocal);
121 System.out.println("\t dataBaseOpenMode=" + dataBaseOpenMode);
123 } catch (Exception e) {
124 System.out.println("Error in ConfigXML.java: problems with " + configFile);
130 private static String getTagValue(String sTag, Element eElement) {
131 NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
132 Node nValue = nlList.item(0);
134 return nValue.getNodeValue();
138 public static ConfigXML getInstance() {
142 public String getBusinessLogicNode() {
143 return businessLogicNode;
146 public String getBusinessLogicPort() {
147 return businessLogicPort;
150 public String getBusinessLogicName() {
151 return businessLogicName;
154 public String getDbFilename() {
158 public String getDataBaseOpenMode() {
159 return dataBaseOpenMode;
162 public String getDatabaseNode() {