commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henning P. Schmiedehausen" <...@intermeta.de>
Subject Re: [configuration] File locator
Date Wed, 08 Dec 2004 10:01:39 GMT
Emmanuel Bourg <smanux@lfjr.net> writes:

>Here is a quick attempt at implementing the Locator strategy discussed 
>earlier. Feel free to comment :)

[...]
>     /**
>      * Creates and loads the configuration from the specified file.
>      *
>+     * @param fileName The name of the file to load.
>+     *
>+     * @throws ConfigurationException Error while loading the file
>+     * @since 1.1
>+     */
>+    public AbstractFileConfiguration(String fileName, Locator locator) throws ConfigurationException
>+    {
>+        this(locator.locate(null, fileName));
>+    }

I don't like this. Yet another C'tor. We shouldn't add C'tors, we
should deprecate AbstractFileConfiguration(String) and force people to
use the locators directly. What is wrong with

Configuration conf = new PropertiesConfiguration(new ClassPathLocator().locate(null, "torque.properties"));

and ClassPathLocator implemented as 

public class ClassPathLocator implements Locator {
  public URL locate(...) {...}
}

I hate adding "convenience constructors". They always come back to
haunt you.

>+
>+    /**
>+     * Creates and loads the configuration from the specified file.
>+     *
>      * @param file The file to load.
>      * @throws ConfigurationException Error while loading the file
>      * @since 1.1
>@@ -149,9 +164,21 @@
>      */
>     public void load(String fileName) throws ConfigurationException
>     {
>+        load(fileName, LocatorUtils.getDefaultLocator());
>+    }

Same here. Deprecate all load(...) except load(URL ...) and let the
locator implementations do the translation from file to URL.

>+
>+    /**
>+     * Locate the specified file and load the configuration.
>+     *
>+     * @param fileName the name of the file loaded
>+     *
>+     * @throws ConfigurationException
>+     */
>+    public void load(String fileName, Locator locator) throws ConfigurationException
>+    {
>         try
>         {
>-            URL url = ConfigurationUtils.locate(basePath, fileName);
>+            URL url = locator.locate(basePath, fileName);
>             load(url);
>         }
>         catch (ConfigurationException e)

Same here. The idea of the locators is to _reduce_ code. Not add new
methods.

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

What is more important to you...
   [ ] Product Security
or [ ] Quality of Sales and Marketing Support
              -- actual question from a Microsoft customer survey

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message