@@ -0,0 +1,2314 @@
+/**%0A * %0A */%0Apackage config;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.nio.charset.Charset;%0Aimport java.util.Map;%0A%0Aimport org.json.simple.JSONObject;%0Aimport org.json.simple.parser.JSONParser;%0Aimport org.json.simple.parser.ParseException;%0A%0A/**%0A * @author Peter Vollmer%0A *%0A */%0Apublic class ConfigManager %7B%0A%0A%09private static ConfigManager instance = null;%0A%09%0A%09/**%0A%09 * %09Parses the config file in JSON format.%0A%09 */%0A%09private final JSONParser parser = new JSONParser();%0A%09%0A%09%0A%09/**%0A%09 * Storage of configuration entries%0A%09 */%0A%09private Map%3CString, Object%3E confMap = null;%0A%09%0A%09%0A%09/**%0A%09 * Construct the ConfigManager for centralize all configurations of the server%0A%09 * %0A%09 * @param configPath%0A%09 * @throws Exception%0A%09 */%0A%09private ConfigManager(String configPath) throws Exception %7B%0A%09%09BufferedReader reader = null;%0A%09%09reader = new BufferedReader(new InputStreamReader(%0A%09%09%09%09%09new FileInputStream(configPath), Charset.forName(%22UTF-8%22)));%0A%09%09JSONObject requestJSON = (JSONObject) parser.parse(reader);%0A%0A%09%09this.confMap = requestJSON;%0A%09%09%0A%09%7D%09%09%0A%0A%09/**%0A%09 * Initialize the config management and construct the configManager.%0A%09 * To do before getInstance%0A%09 * %0A%09 * @param configPath%0A%09 * %09%09%09%0A%09 * @throws Exception%0A%09 */%0A%09public static void Init (String configPath) throws Exception %7B%0A%09%09instance = new ConfigManager(configPath);%0A%09%7D%0A%09%0A%09%0A%09/**%0A%09 * Return the value of a given key or the given defaultValue%0A%09 * %0A%09 * @param key%0A%09 * @param defaultValue%0A%09 * @return value %0A%09 *%09%09%09 of a given key or the given defaultValue%0A%09 */%0A%09public String getEntry(String key, String defaultValue)%7B%0A%09%09String value = null;%0A%09%09if (confMap.containsKey(key))%7B%0A%09%09%09value = (String)confMap.get(key);%0A%09%09%7D else %7B%0A%09%09%09value = defaultValue;%0A%09%09%7D%0A%09%09return value;%0A%09%7D%0A%09%0A%09/**%0A%09 * Returns the value of the given key%0A%09 * %0A%09 * @param key%0A%09 * %09%09%09to give the %0A%09 * @return value (default value is null)%0A%09 */%0A%09public String getEntry (String key)%7B%0A%09%09String value = null;%0A%09%09if (confMap.containsKey(key))%7B%0A%09%09%09value = (String)confMap.get(key);%0A%09%09%7D%0A%09%09return value;%0A%09%7D%0A%09%0A%09%0A%09/**%0A%09 * Return an instance of a constructed ConfigManager. Need Init before.%0A%09 * %0A%09 * %0A%09 * @return instance of ConfigManager%0A%09 */%0A%09public static ConfigManager getInstance()%09%7B%0A%09%09return instance;%0A%09%7D%0A%09%0A%7D%0A

Add the config manager funtionality to the server