From 2f358015667a8be93214ae5a7ff79990d4f20a8b Mon Sep 17 00:00:00 2001 From: samskivert Date: Tue, 30 Jun 2009 21:28:56 +0000 Subject: [PATCH] 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 --- src/java/com/samskivert/util/Config.java | 38 ++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/java/com/samskivert/util/Config.java b/src/java/com/samskivert/util/Config.java index 65464fc7..9c3fbf5e 100644 --- a/src/java/com/samskivert/util/Config.java +++ b/src/java/com/samskivert/util/Config.java @@ -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 keys) { Enumeration defkeys = _props.propertyNames();