Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard
 
08aaf3b19060c67249a3f3e206690c260e881713
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
171
172
173
174
175
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;

public class ConfigXML {
	private String businessLogicNode;

	private String portRMI;

	private String serviceRMI;

	private String javaPolicyPath;

	private static String db4oFilename;

	//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 activationDepth;
	
	private int updateDepth;
	
	private int databasePort;
	
	private String user;
	
	private String password;
	
	public int getDatabasePort() {
		return databasePort;
	}

	public String getUser() {
		return user;
	}

	public String getPassword() {
		return password;
	}

	public int getActivationDepth() {
		return activationDepth;
	}

	public int getUpdateDepth() {
		return updateDepth;
	}
	
	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("config.xml"));
			  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);

			  portRMI = getTagValue("portRMI", config);

			  serviceRMI = getTagValue("serviceRMI", config);

			  javaPolicyPath= getTagValue("javaPolicyPath", config);

			  db4oFilename = getTagValue("db4oFilename", 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);

	
			  databaseNode = getTagValue("databaseNode", config);

			  activationDepth=Integer.parseInt(getTagValue("activationDepth", config));

			  updateDepth=Integer.parseInt(getTagValue("updateDepth", 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 config.xml");
		    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 getPortRMI() {
		return portRMI;
	}

	public String getServiceRMI() {
		return serviceRMI;
	}
	public String getDb4oFilename(){
		return db4oFilename;
	}
	public String getJavaPolicyPath(){
		return javaPolicyPath;
	}
	public String getDataBaseOpenMode(){
		return dataBaseOpenMode;
	}

	public String getDatabaseNode() {
		return databaseNode;
	}

}

Commits for RRRRHHHH_CoderuralHousesDB/src/configuration/ConfigXML.java

Diff revisions: vs.
Revision Author Commited Message
08aaf3 ... camjan Wed 20 May, 2015 21:26:51 +0000

Started with the separated DB with the given code