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;
13 public class ConfigXML {
14 private String businessLogicNode;
16 private String portRMI;
18 private String serviceRMI;
20 private String javaPolicyPath;
22 private static String db4oFilename;
24 //Two possible values: "open" or "initialize"
25 private String dataBaseOpenMode;
27 //Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
28 private boolean businessLogicLocal;
30 //Two possible values: true (if the database is in same node as business logic ) or false (in other case)
31 private boolean databaseLocal;
33 private String databaseNode;
35 private int activationDepth;
37 private int updateDepth;
39 private int databasePort;
43 private String password;
45 public int getDatabasePort() {
49 public String getUser() {
53 public String getPassword() {
57 public int getActivationDepth() {
58 return activationDepth;
61 public int getUpdateDepth() {
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("config.xml"));
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 portRMI = getTagValue("portRMI", config);
94 serviceRMI = getTagValue("serviceRMI", config);
96 javaPolicyPath= getTagValue("javaPolicyPath", config);
98 db4oFilename = getTagValue("db4oFilename", config);
100 //Two possible values: true (no instance of RemoteServer needs to be launched) or false (RemoteServer needs to be run first)
101 value= ((Element)config.getElementsByTagName("database").item(0)).getAttribute("local");
102 databaseLocal=value.equals("true");
105 //Two possible values: "open" or "initialize"
106 dataBaseOpenMode= getTagValue("dataBaseOpenMode", config);
109 databaseNode = getTagValue("databaseNode", config);
111 activationDepth=Integer.parseInt(getTagValue("activationDepth", config));
113 updateDepth=Integer.parseInt(getTagValue("updateDepth", config));
116 databasePort=Integer.parseInt(getTagValue("databasePort", config));
118 user=getTagValue("user", config);
120 password=getTagValue("password", config);
122 System.out.print("Read from config.xml: ");
123 System.out.print("\t businessLogicLocal="+businessLogicLocal);
124 System.out.print("\t databaseLocal="+databaseLocal);
125 System.out.println("\t dataBaseOpenMode="+dataBaseOpenMode);
127 } catch (Exception e) {
128 System.out.println("Error in ConfigXML.java: problems with config.xml");
137 private static String getTagValue(String sTag, Element eElement)
139 NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
140 Node nValue = (Node) nlList.item(0);
142 return nValue.getNodeValue();
146 public static ConfigXML getInstance() {
150 public String getBusinessLogicNode() {
151 return businessLogicNode;
154 public String getPortRMI() {
158 public String getServiceRMI() {
161 public String getDb4oFilename(){
164 public String getJavaPolicyPath(){
165 return javaPolicyPath;
167 public String getDataBaseOpenMode(){
168 return dataBaseOpenMode;
171 public String getDatabaseNode() {