1 19 package org.lucane.server; 20 21 import javax.xml.parsers.*; 22 23 import org.lucane.common.Logging; 24 import org.w3c.dom.*; 25 26 27 30 public class ServerConfig 31 { 32 private int port = 9115; 34 35 private boolean sslEnabled = false; 36 private int sslPort = 9116; 37 private String sslPassword = "password"; 38 39 private String dbDriver = null; 40 private String dbUrl = null; 41 private String dbLogin = null; 42 private String dbPassword = ""; 43 private String dbLayer = null; 44 45 private int dbPoolInitialSize = 0; 46 private int dbPoolMaxActive = 8; 47 private int dbPoolMaxIdle = 8; 48 private int dbPoolMinIdle = 0; 49 private int dbPoolMaxWait = -1; 50 51 private String storeBackend = "database"; 52 private String authenticatorClass = "org.lucane.server.auth.DefaultAuthenticator"; 53 54 59 public ServerConfig(String filename) 60 throws Exception 61 { 62 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 63 64 Document document = builder.parse(filename); 65 66 Node node = document.getFirstChild(); 68 while(node != null && node.getNodeType() != Node.ELEMENT_NODE) 69 node = node.getNextSibling(); 70 71 if(node == null || !node.getNodeName().equals("lucane-server")) 72 throw new Exception ("root element is different from 'lucane-server'"); 73 74 this.port = Integer.parseInt(node.getAttributes().getNamedItem("port").getNodeValue()); 75 76 node = node.getFirstChild(); 77 while(node != null) 78 { 79 if(node.getNodeType() == Node.ELEMENT_NODE) 80 { 81 if(node.getNodeName().equals("ssl")) 82 handleSSL(node); 83 else if(node.getNodeName().equals("database")) 84 handleDatabase(node); 85 else if(node.getNodeName().equals("store")) 86 handleStore(node); 87 else if(node.getNodeName().equals("authenticator")) 88 handleAuthenticator(node); 89 else 90 Logging.getLogger().warning("unexepected node : " + node.getNodeName()); 91 } 92 node = node.getNextSibling(); 93 } 94 } 95 96 101 private void handleSSL(Node node) 102 { 103 NamedNodeMap attrs = node.getAttributes(); 104 this.sslEnabled = Boolean.valueOf(attrs.getNamedItem("enabled").getNodeValue()).booleanValue(); 105 this.sslPort = Integer.parseInt(attrs.getNamedItem("port").getNodeValue()); 106 this.sslPassword = attrs.getNamedItem("password").getNodeValue(); 107 } 108 109 114 private void handleDatabase(Node node) 115 { 116 node = node.getFirstChild(); 117 while(node != null) 118 { 119 if(node.getNodeType() == Node.ELEMENT_NODE) 120 { 121 if(node.getNodeName().equals("jdbc")) 122 { 123 this.dbDriver = node.getAttributes().getNamedItem("driver").getNodeValue(); 124 this.dbUrl = node.getAttributes().getNamedItem("url").getNodeValue(); 125 this.dbLogin = node.getAttributes().getNamedItem("login").getNodeValue(); 126 this.dbPassword = node.getAttributes().getNamedItem("password").getNodeValue(); 127 } 128 else if(node.getNodeName().equals("dblayer")) 129 this.dbLayer = node.getAttributes().getNamedItem("class").getNodeValue(); 130 else if(node.getNodeName().equals("pool")) 131 { 132 this.dbPoolInitialSize = Integer.parseInt(node.getAttributes().getNamedItem("initialSize").getNodeValue()); 133 this.dbPoolMaxActive = Integer.parseInt(node.getAttributes().getNamedItem("maxActive").getNodeValue()); 134 this.dbPoolMaxIdle = Integer.parseInt(node.getAttributes().getNamedItem("maxIdle").getNodeValue()); 135 this.dbPoolMinIdle = Integer.parseInt(node.getAttributes().getNamedItem("minIdle").getNodeValue()); 136 this.dbPoolMaxWait = Integer.parseInt(node.getAttributes().getNamedItem("maxWait").getNodeValue()); 137 } 138 else 139 Logging.getLogger().warning("unexepected node : " + node.getNodeName()); 140 } 141 node = node.getNextSibling(); 142 } 143 } 144 145 150 private void handleStore(Node node) 151 { 152 this.storeBackend = node.getAttributes().getNamedItem("backend").getNodeValue(); 153 } 154 155 160 private void handleAuthenticator(Node node) 161 { 162 this.authenticatorClass = node.getAttributes().getNamedItem("class").getNodeValue(); 163 } 164 165 167 172 public int getPort() 173 { 174 return this.port; 175 } 176 177 182 public boolean isSslEnabled() 183 { 184 return this.sslEnabled; 185 } 186 187 192 public int getSslPort() 193 { 194 return this.sslPort; 195 } 196 197 202 protected String getSslPassword() 203 { 204 return this.sslPassword; 205 } 206 207 212 public String getDbDriver() 213 { 214 return this.dbDriver; 215 } 216 217 222 public String getDbUrl() 223 { 224 return this.dbUrl; 225 } 226 227 232 public String getDbLogin() 233 { 234 return this.dbLogin; 235 } 236 237 242 public String getDbPassword() 243 { 244 return this.dbPassword; 245 } 246 247 252 public String getDbLayer() 253 { 254 return this.dbLayer; 255 } 256 257 262 public int getDbPoolInitialSize() 263 { 264 return this.dbPoolInitialSize; 265 } 266 267 272 public int getDbPoolMaxActive() 273 { 274 return this.dbPoolMaxActive; 275 } 276 277 282 public int getDbPoolMaxIdle() 283 { 284 return this.dbPoolMaxIdle; 285 } 286 287 292 public int getDbPoolMinIdle() 293 { 294 return this.dbPoolMinIdle; 295 } 296 297 303 public long getDbPoolMaxWait() 304 { 305 return this.dbPoolMaxWait; 306 } 307 308 314 public String getStoreBackend() 315 { 316 return this.storeBackend; 317 } 318 319 324 public String getAuthenticatorClass() 325 { 326 return this.authenticatorClass; 327 } 328 } | Popular Tags |