2019-10-12 11:19:29 +02:00
|
|
|
package envoy.client;
|
|
|
|
|
2019-10-27 21:40:40 +01:00
|
|
|
import java.io.File;
|
2019-10-12 11:19:29 +02:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Project: <strong>envoy-client</strong><br>
|
|
|
|
* File: <strong>Config.java</strong><br>
|
|
|
|
* Created: <strong>12 Oct 2019</strong><br>
|
|
|
|
*
|
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @since Envoy 0.1
|
|
|
|
*/
|
|
|
|
public class Config {
|
|
|
|
|
|
|
|
private String server;
|
|
|
|
private int port;
|
2019-10-27 21:40:40 +01:00
|
|
|
private File localDB;
|
2019-10-12 11:19:29 +02:00
|
|
|
|
2019-10-12 11:52:29 +02:00
|
|
|
/**
|
2019-10-27 21:40:40 +01:00
|
|
|
* Defaults to the {@code client.properties} file for information.
|
2019-10-12 11:52:29 +02:00
|
|
|
*
|
2019-10-27 21:40:40 +01:00
|
|
|
* @param properties a {@link Properties} object containing information about
|
|
|
|
* the server and port, as well as the path to the local
|
|
|
|
* database
|
|
|
|
* @since Envoy v0.1-alpha
|
2019-10-12 11:52:29 +02:00
|
|
|
*/
|
2019-10-12 11:19:29 +02:00
|
|
|
public void load(Properties properties) {
|
|
|
|
if (properties.containsKey("server")) server = properties.getProperty("server");
|
|
|
|
if (properties.containsKey("port")) port = Integer.parseInt(properties.getProperty("port"));
|
2019-10-27 21:40:40 +01:00
|
|
|
localDB = new File(properties.getProperty("localDB", ".\\localDB"));
|
2019-10-12 11:19:29 +02:00
|
|
|
}
|
|
|
|
|
2019-10-12 11:52:29 +02:00
|
|
|
/**
|
2019-10-27 21:40:40 +01:00
|
|
|
* Sets the server, port and localDB path via command line properties --server /
|
|
|
|
* -s, --port / -p and --localDB / -db.
|
2019-10-12 11:52:29 +02:00
|
|
|
*
|
2019-10-27 21:40:40 +01:00
|
|
|
* @param args the command line arguments to parse
|
|
|
|
* @since Envoy v0.1-alpha
|
2019-10-12 11:52:29 +02:00
|
|
|
*/
|
2019-10-12 11:19:29 +02:00
|
|
|
public void load(String[] args) {
|
|
|
|
for (int i = 0; i < args.length; i++)
|
|
|
|
switch (args[i]) {
|
|
|
|
case "--server":
|
|
|
|
case "-s":
|
|
|
|
server = args[++i];
|
|
|
|
break;
|
|
|
|
case "--port":
|
|
|
|
case "-p":
|
|
|
|
port = Integer.parseInt(args[++i]);
|
|
|
|
break;
|
2019-10-27 21:40:40 +01:00
|
|
|
case "--localDB":
|
|
|
|
case "-db":
|
|
|
|
localDB = new File(args[++i]);
|
2019-10-12 11:19:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 21:40:40 +01:00
|
|
|
public boolean isInitialized() { return server != null && !server.isEmpty() && port > 0 && port < 65566 && localDB != null; }
|
2019-10-12 11:19:29 +02:00
|
|
|
|
|
|
|
public String getServer() { return server; }
|
|
|
|
|
|
|
|
public void setServer(String server) { this.server = server; }
|
|
|
|
|
|
|
|
public int getPort() { return port; }
|
|
|
|
|
|
|
|
public void setPort(int port) { this.port = port; }
|
2019-10-27 21:40:40 +01:00
|
|
|
|
|
|
|
public File getLocalDB() { return localDB; }
|
|
|
|
|
|
|
|
public void setLocalDB(File localDB) { this.localDB = localDB; }
|
2019-10-12 11:19:29 +02:00
|
|
|
}
|