/** * Loads and returns a {@code Properties} object from the resource specified. * The resource should be located in the current CLASSPATH to be found. * @param propsResource resource string to use to find properties file * @throws IOException if there was an problem loading the properties */ static Properties loadProperties(String propsResource) throws IOException { return loadProperties(propsResource, DEFAULT_CHARSET); }
/** * Loads and returns a {@code Properties} object from the resource specified. * The resource should be located in the current CLASSPATH to be found. * @param propsResource resource string to use to find properties file * @param enc character encoding to use for properties * @throws IOException if there was an problem loading the properties */ static Properties loadProperties(String propsResource, String enc) throws IOException { InputStream is = ConnectionPoolManager.class.getResourceAsStream(propsResource); if (is == null) throw new FileNotFoundException("Unable to find properties file: " + propsResource); Properties props = null; try { props = loadProperties(is, enc); } catch (IOException iox) { logShared.warn("Unable to load the properties file. Make sure " + propsResource + " is in the CLASSPATH.", iox); throw iox; } return props; }
/** * Loads and returns a {@code Properties} object from file. * @param propsFile properties file * @param enc character encoding to use for properties */ private static Properties loadProperties(File propsFile, String enc) throws IOException { if (!propsFile.exists()) throw new FileNotFoundException(propsFile.getAbsolutePath() + " does not exist"); if (propsFile.isDirectory()) throw new IOException("Error accessing properties file - " + propsFile.getAbsolutePath() + " is a directory"); InputStream is = new FileInputStream(propsFile); Properties props = null; try { props = loadProperties(is, enc); } catch (IOException iox) { logShared.warn("Unable to find the properties file " + propsFile.getAbsolutePath(), iox); throw iox; } return props; }
/** * Returns the singleton instance of the {@code ConnectionPoolManager} for the specified properties file. * @param propsFile filename of the properties file to use (path info should not be specified; available CLASSPATH will be searched for the properties file) * @param enc character-encoding to use for reading properties file * @return instance of {@code ConnectionPoolManager} relating to the specified properties file * @throws IOException if there was an problem loading the properties */ public static synchronized ConnectionPoolManager getInstance(String propsFile, String enc) throws IOException { if (propsFile == null) throw new NullPointerException("Invalid value for propsFile specified: null"); String s = propsFile.startsWith("/") ? propsFile : ("/" + propsFile); Object o = managers.get(s); ConnectionPoolManager cpm = (o != null) ? (ConnectionPoolManager)o : null; if (cpm == null || cpm.isReleased()) { Properties props = loadProperties(s, enc); if (props == null) throw new FileNotFoundException("Unable to find properties file: " + propsFile); cpm = new ConnectionPoolManager(props, propsFile); cpm.instanceKey = s; managers.put(cpm.instanceKey, cpm); cpm.fireInstancesChangedEvent(); } return cpm; }
cpm = new ConnectionPoolManager(loadProperties(propsFile, enc), propsFile); cpm.instanceKey = propsFile; managers.put(cpm.instanceKey, cpm);