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) or false (RemoteServer needs to be run first)
32 private boolean businessLogicLocal;
34 //Two possible values: true (if the database is in same node as business logic ) or false (in other case)
35 private boolean databaseLocal;
37 private String databaseNode;
39 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;
72 private static ConfigXML theInstance = new ConfigXML();
77 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
78 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
79 Document doc = dBuilder.parse(new File(configFile));
80 doc.getDocumentElement().normalize();
82 NodeList list = doc.getElementsByTagName("config");
83 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) or false (RemoteServer needs to be run first)
87 String value= ((Element)config.getElementsByTagName("businessLogic").item(0)).getAttribute("local");
88 businessLogicLocal=value.equals("true");
90 businessLogicNode = getTagValue("businessLogicNode", config);
92 businessLogicPort = getTagValue("businessLogicPort", config);
94 businessLogicName = getTagValue("businessLogicName", config);
96 locale = getTagValue("locale", config);
102 dbFilename = getTagValue("dbFilename", config);
104 //Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
105 value= ((Element)config.getElementsByTagName("database").item(0)).getAttribute("local");
106 databaseLocal=value.equals("true");
109 //Two possible values: "open" or "initialize"
110 // dataBaseOpenMode= getTagValue("dataBaseOpenMode", config);
111 dataBaseOpenMode = "open";
113 databaseNode = getTagValue("databaseNode", config);
115 databasePort=Integer.parseInt(getTagValue("databasePort", config));
117 user=getTagValue("user", config);
119 password=getTagValue("password", config);
121 System.out.print("Read from config.xml: ");
122 System.out.print("\t businessLogicLocal="+businessLogicLocal);
123 System.out.print("\t databaseLocal="+databaseLocal);
124 System.out.println("\t dataBaseOpenMode="+dataBaseOpenMode);
126 } catch (Exception e) {
127 System.out.println("Error in ConfigXML.java: problems with "+ configFile);
133 private static String getTagValue(String sTag, Element eElement)
135 NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
136 Node nValue = (Node) nlList.item(0);
138 return nValue.getNodeValue();
142 public static ConfigXML getInstance() {
146 public String getBusinessLogicNode() {
147 return businessLogicNode;
150 public String getBusinessLogicPort() {
151 return businessLogicPort;
154 public String getBusinessLogicName() {
155 return businessLogicName;
158 public String getDbFilename(){
162 public String getDataBaseOpenMode(){
163 return dataBaseOpenMode;
166 public String getDatabaseNode() {