--- .\src\main\java\org\castor\core\util\Configuration.java 2007-10-04 11:15:24.000000000 -0500 +++ .\src\main\java\org\castor\core\util\Configuration.java 2009-01-28 16:06:29.113830900 -0600 @@ -56,7 +56,9 @@ /** Parent configuration. */ private final Configuration _parent; - /** Properties map. */ + /** Properties maps. */ + private static final Map defaultPropertiesMap = new HashMap(); + private static final Map userPropertiesMap = new HashMap(); private final Map _map = new HashMap(); //-------------------------------------------------------------------------- @@ -130,18 +132,33 @@ * @param filename Name of the configuration file. */ protected void loadDefaultProperties(final String path, final String filename) { - Properties properties = new Properties(); + final String fullFilePath = path + filename; - // Get detault configuration from the Castor JAR. - boolean inCastorJar = loadFromClassPath(properties, path + filename); - - // Get overriding configuration from the Java library directory, ignore if not - // found. If found merge existing properties. - boolean inJavaLibDir = loadFromJavaHome(properties, filename); - - // Couldn't find configuration in Castor jar nor Java library directory. - if (!inCastorJar && !inJavaLibDir) { - throw new ConfigurationException("Failed to load configuration: " + filename); + // Attempt to load default properties from map (cache) + Properties properties; + synchronized(defaultPropertiesMap) + { + properties = (Properties)defaultPropertiesMap.get(fullFilePath); + + if (properties == null) + { + properties = new Properties(); + + // Get detault configuration from the Castor JAR. + boolean inCastorJar = loadFromClassPath(properties, fullFilePath); + + // Get overriding configuration from the Java library directory, ignore if not + // found. If found merge existing properties. + boolean inJavaLibDir = loadFromJavaHome(properties, filename); + + // Couldn't find configuration in Castor jar nor Java library directory. + if (!inCastorJar && !inJavaLibDir) { + throw new ConfigurationException("Failed to load configuration: " + filename); + } + + // Cache the default properties + defaultPropertiesMap.put(fullFilePath, properties); + } } _map.putAll(properties); @@ -158,15 +175,28 @@ * * @param filename Name of the configuration file. */ - protected void loadUserProperties(final String filename) { - Properties properties = new Properties(); - - // Get common configuration from the classpath root, ignore if not found. - boolean onClasspathRoot = loadFromClassPath(properties, "/" + filename); - - // If not found on classpath root, either it doesn't exist, or "." is not part of - // the classpath, try looking at local working directory. - if (!onClasspathRoot) { loadFromWorkingDirectory(properties, filename); } + protected void loadUserProperties(final String filename) { + Properties properties; + synchronized(userPropertiesMap) + { + // Attempt to load user properties from map (cache) + properties = (Properties)userPropertiesMap.get(filename); + + if (properties == null) + { + properties = new Properties(); + + // Get common configuration from the classpath root, ignore if not found. + boolean onClasspathRoot = loadFromClassPath(properties, "/" + filename); + + // If not found on classpath root, either it doesn't exist, or "." is not part of + // the classpath, try looking at local working directory. + if (!onClasspathRoot) { loadFromWorkingDirectory(properties, filename); } + + // Cache the user properties + userPropertiesMap.put(filename, properties); + } + } _map.putAll(properties); }