Git Repository Public Repository

ISBets21MAUBRY

URLs

Copy to Clipboard
 
cbae1464e51d90bc80afc97083afd6462fd3c54f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package configuration;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * It provides the configuration data from the "resources/config.xml" XML file
 */
public class ConfigXML {
	
	private String configFile = "src/main/resources/config.xml";
		
	private String businessLogicNode;

	private String businessLogicPort;

	private String businessLogicName;
	
	private static String dbFilename;

	//Two possible values: "open" or "initialize"
	private String dataBaseOpenMode;

	//Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
	private boolean businessLogicLocal;

	//Two possible values: true (if the database is in same node as business logic ) or false (in other case)
	private boolean databaseLocal;
	
	private String databaseNode;
	
	private int databasePort;
	

	
	private String user;
	
	private String password;
	
	private String locale;

	public String getLocale() {
		return locale;
	}
	
	public int getDatabasePort() {
		return databasePort;
	}

	public String getUser() {
		return user;
	}

	public String getPassword() {
		return password;
	}
	
	public boolean isDatabaseLocal() {
		return databaseLocal;
	}

	public boolean isBusinessLogicLocal() {
		return businessLogicLocal;
	}
	private static ConfigXML theInstance = new ConfigXML();

	private ConfigXML(){
		
		  try {
			  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
			  Document doc = dBuilder.parse(new File(configFile));
			  doc.getDocumentElement().normalize();

			  NodeList list = doc.getElementsByTagName("config");
			  Element config = (Element) list.item(0); // list.item(0) is a Node that is an Element

			  
				//Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
			  String value= ((Element)config.getElementsByTagName("businessLogic").item(0)).getAttribute("local");
			  businessLogicLocal=value.equals("true");

			  businessLogicNode = getTagValue("businessLogicNode", config);

			  businessLogicPort = getTagValue("businessLogicPort", config);

			  businessLogicName = getTagValue("businessLogicName", config);
			  
			  locale = getTagValue("locale", config);

			  
			  
				

			  dbFilename = getTagValue("dbFilename", config);

				//Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
			  value= ((Element)config.getElementsByTagName("database").item(0)).getAttribute("local");
			  databaseLocal=value.equals("true");
			  
			  
			  //Two possible values: "open" or "initialize"
			 // dataBaseOpenMode= getTagValue("dataBaseOpenMode", config);
			  dataBaseOpenMode = "open";
	
			  databaseNode = getTagValue("databaseNode", config);
			  
			  databasePort=Integer.parseInt(getTagValue("databasePort", config));
				
			  user=getTagValue("user", config);
				
			  password=getTagValue("password", config);

			  System.out.print("Read from config.xml: ");
			  System.out.print("\t businessLogicLocal="+businessLogicLocal);
			  System.out.print("\t databaseLocal="+databaseLocal);
			  System.out.println("\t dataBaseOpenMode="+dataBaseOpenMode); 
					  
		  } catch (Exception e) {
			System.out.println("Error in ConfigXML.java: problems with "+ configFile);
		    e.printStackTrace();
		  }		
		
	}

	private static String getTagValue(String sTag, Element eElement)
	 {
		  NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
		  Node nValue = (Node) nlList.item(0);

		  return nValue.getNodeValue();

	 }
	
	public static ConfigXML getInstance() {
		return theInstance;
	}

	public String getBusinessLogicNode() {
		return businessLogicNode;
	}

	public String getBusinessLogicPort() {
		return businessLogicPort;
	}

	public String getBusinessLogicName() {
		return businessLogicName;
	}
	
	public String getDbFilename(){
		return dbFilename;
	}

	public String getDataBaseOpenMode(){
		return dataBaseOpenMode;
	}

	public String getDatabaseNode() {
		return databaseNode;
	}

}

Commits for ISBets21MAUBRYeclipse-workspace/ISBets21BRYMAUJONUNA/src/main/java/configuration/ConfigXML.java

Diff revisions: vs.
Revision Author Commited Message
cbae14 ... porkipig Thu 04 Mar, 2021 10:33:41 +0000

VersiĆ³n del proyecto de Apuestas tras la iteraciĆ³n 1