commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (Oliver Heger)
Subject [configuration]Read configurations from URLs
Date Thu, 06 Nov 2003 16:36:11 GMT
I have added a patch to bugzilla which implemnets some new features for 
[configuration]. In this posting I will add some comments related to 
changes in file loading (to keep things handy I will send another 
posting with comments about other areas the patch affects).

As we have already discussed it is problematic that ConfigurationFactory 
and some other classes can only load their data from files. I have now 
added support for loading from URLs. Unfortunately I had to change a 
bunch of classes to achieve this.

At first I had to introduce a new interface BasePathLoader which defines 
the setBasePath() and getBasePath() methods. This was necessary because 
not all affected classes extend BasePathConfiguration and the 
ConfigurationFactory must somehow be able to set the base path. 
BasePathConfiguration now implements this interface.

In classes that load data from files (namely DOM4JConfiguration and 
PropertiesConfiguration) there was some doublicated code for evaluating 
the base path and determining the full path of the file to load. I 
refactored this code into a new method getURL() of ConfigurationUtils (I 
think this is a good place for it) and adapted it to support URLs, too.

It is a bit tricky to maintain full backwards compatibility. My 
implementation (the new getURL() method) interprets the base path (which 
is simply a String) as either a URL or a file path. The same is true for 
the supplied file name. So old applications (including all unit tests) 
will still work: the method finds out that no valid URLs are passed and 
then constructs a file object with the full path. If valid URLs are 
provided, they are used to locate the data to load. In any case a URL is 
returned. The mentioned configuration classes were changed to load their 
data from a URL rather than a FileInputStream.

Finally a word about relative file names used for ConfigurationFactory: 
ConfigurationFactory uses the current directory "." as a base path if no 
other is specified. So relative file names in the XML file processed by 
this class are resolved relative to the current directory if not 
specified otherwise. In my opinion this is a bit strange because I would 
expect the file names to be relative to the location of this XML file. 
Especially if the XML is loaded from a URL, the current directory surely 
makes no sense. Do you think this should be changed?

My actual implementation uses the following strategy to deal with this 
problem: To be backwards compatible the current directory is the default 
value for the base path. But if ConfigurationFactory should load its XML 
definition file from a URL and no specific base path was set, the URL 
itself becomes the base path and file names in the definition file are 
resolved relative to this URL.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message