public abstract class IStoredSettings {\r
\r
protected final Logger logger;\r
+ \r
+ protected final Properties overrides = new Properties();\r
\r
public IStoredSettings(Class<? extends IStoredSettings> clazz) {\r
logger = LoggerFactory.getLogger(clazz);\r
}\r
\r
protected abstract Properties read();\r
+ \r
+ private Properties getSettings() {\r
+ Properties props = read();\r
+ props.putAll(overrides);\r
+ return props;\r
+ }\r
\r
public List<String> getAllKeys(String startingWith) {\r
List<String> keys = new ArrayList<String>();\r
- Properties props = read();\r
+ Properties props = getSettings();\r
if (StringUtils.isEmpty(startingWith)) {\r
keys.addAll(props.stringPropertyNames());\r
} else {\r
}\r
\r
public boolean getBoolean(String name, boolean defaultValue) {\r
- Properties props = read();\r
+ Properties props = getSettings();\r
if (props.containsKey(name)) {\r
String value = props.getProperty(name);\r
if (!StringUtils.isEmpty(value)) {\r
}\r
\r
public int getInteger(String name, int defaultValue) {\r
- Properties props = read();\r
+ Properties props = getSettings();\r
if (props.containsKey(name)) {\r
try {\r
String value = props.getProperty(name);\r
}\r
\r
public String getString(String name, String defaultValue) {\r
- Properties props = read();\r
+ Properties props = getSettings();\r
if (props.containsKey(name)) {\r
String value = props.getProperty(name);\r
if (value != null) {\r
\r
public List<String> getStrings(String name, String separator) {\r
List<String> strings = new ArrayList<String>();\r
- Properties props = read();\r
+ Properties props = getSettings();\r
if (props.containsKey(name)) {\r
String value = props.getProperty(name);\r
strings = StringUtils.getStringsFromValue(value, separator);\r
}\r
return strings;\r
}\r
+ \r
+ public void overrideSetting(String key, String value) {\r
+ overrides.put(key, value);\r
+ }\r
}
\ No newline at end of file