Provide a constructor that allows the class loader used to load the properties

files to be supplied. I'm amazed I haven't needed this sooner. Clearly I
haven't been doing enough class loader jockeying in the last decade.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2581 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2009-06-30 21:28:56 +00:00
parent 999c17a4fb
commit 2f35801566
+23 -15
View File
@@ -89,22 +89,18 @@ public class Config
*/
public Config (String path)
{
// first load up our default prefs
_props = new Properties();
_props = loadProperties(path, getClass().getClassLoader(), new Properties());
}
try {
// append the file suffix onto the path
String ppath = path + PROPS_SUFFIX;
// load the properties file
ConfigUtil.loadProperties(ppath, getClass().getClassLoader(), _props);
} catch (FileNotFoundException fnfe) {
log.debug("No properties file found to back config", "path", path);
} catch (IOException ioe) {
log.warning("Unable to load configuration", "path", path, "ioe", ioe);
}
/**
* Constructs a new config object which will obtain configuration information from the
* specified properties bundle.
*
* @param loader the classloader to use to locate the properties file.
*/
public Config (String path, ClassLoader loader)
{
_props = loadProperties(path, loader, new Properties());
}
/**
@@ -407,6 +403,18 @@ public class Config
return matches.iterator();
}
protected static Properties loadProperties (String path, ClassLoader loader, Properties props)
{
try {
ConfigUtil.loadProperties(path + PROPS_SUFFIX, loader, props);
} catch (FileNotFoundException fnfe) {
log.debug("No properties file found to back config", "path", path);
} catch (IOException ioe) {
log.warning("Unable to load configuration", "path", path, "ioe", ioe);
}
return props;
}
protected void enumerateKeys (HashSet<String> keys)
{
Enumeration<?> defkeys = _props.propertyNames();