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) public Config (String path)
{ {
// first load up our default prefs _props = loadProperties(path, getClass().getClassLoader(), new Properties());
_props = new Properties(); }
try { /**
// append the file suffix onto the path * Constructs a new config object which will obtain configuration information from the
String ppath = path + PROPS_SUFFIX; * specified properties bundle.
*
// load the properties file * @param loader the classloader to use to locate the properties file.
ConfigUtil.loadProperties(ppath, getClass().getClassLoader(), _props); */
public Config (String path, ClassLoader loader)
} catch (FileNotFoundException fnfe) { {
log.debug("No properties file found to back config", "path", path); _props = loadProperties(path, loader, new Properties());
} catch (IOException ioe) {
log.warning("Unable to load configuration", "path", path, "ioe", ioe);
}
} }
/** /**
@@ -407,6 +403,18 @@ public class Config
return matches.iterator(); 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) protected void enumerateKeys (HashSet<String> keys)
{ {
Enumeration<?> defkeys = _props.propertyNames(); Enumeration<?> defkeys = _props.propertyNames();