commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [configuration] sanity checks
Date Mon, 26 Nov 2007 21:00:09 GMT
Hello Michiel,

when implementing the new interpolatedConfiguration() method of 
AbstractConfiguration I thought about this topic, but could not find a 
really satisfying solution.

Your idea with injecting a special lookup object is interesting. This 
could be an approach.

The only thing I find a bit suspicious is the fact that you call 
getString() for all properties in your checking method. I am not sure, 
but could this cause an exception if the property value is of a 
different data type than string?

Oliver

Michiel Kalkman wrote:
> Hi Oliver,
> Interesting question, did you look into this any further ? If I had to
> say something about it, I guess I would prefer a generic solution.
> However, at the moment this seems to me to be a somewhat theoretical
> exercise.
> 
> I added code for our apps that check whether variable substitution is
> possible for all properties, see below. The idea is to simply replace
> a StrLookup with a proxy to the existing one and throwing exceptions
> when no variable substitution was possible. Note that we're still
> using 1.4 (btw: congrats on 1.5) and also note that it has not been
> tested very much.
> 
> It might be an idea to change setThrowExceptionOnMissing() - using
> similar code as below - such that exceptions are also thrown when
> variables cannot be substituted. However, this would change the
> behaviour of a number of methods, like
> AbstractConfiguration::interpolatedConfiguration() which will possibly
> start throwing exceptions after implementation of this change.
> 
> What do you think ?
> 
> Regards,
> Michiel
> 
> public static List checkVariableSubstitution( final
> AbstractConfiguration abstractConfiguration) {
>   final ConfigurationInterpolator configurationInterpolator =
> abstractConfiguration.getInterpolator();
>   final StrLookup originalStrLookup =
> configurationInterpolator.getDefaultLookup();
> 
>   final StrLookup strLookup = new StrLookup() {
>     public String lookup(String arg0) {
>       final String result = originalStrLookup.lookup( arg0);
> 
>       if( result == null) {
>         throw new ConfigurationRuntimeException( arg0);
>       }
> 
>       return result;
>     }
>   };
> 
>   configurationInterpolator.setDefaultLookup( strLookup);
> 
>   final List list = new ArrayList();
> 
>   final Iterator iterator = abstractConfiguration.getKeys();
>   while( iterator.hasNext()) {
>     final String key = (String) iterator.next();
>     try {
>       abstractConfiguration.getString( key);
>     } catch ( final ConfigurationRuntimeException
> configurationRuntimeException) {
>       list.add( "Variable " +
> configurationRuntimeException.getLocalizedMessage() + " mentioned in
> property "
>         + key + " could not be resolved");
>     }
>   }
> 
>   configurationInterpolator.setDefaultLookup( originalStrLookup);
> 
>   return list;
> }
> 
> 
> 
> On 8/29/07, Oliver Heger <oliver.heger@oliver-heger.de> wrote:
>> Hi Michiel,
>>
>> Michiel Kalkman wrote:
>>> Hi,
>>> Is there any code in configuration which performs sanity checks on a
>>> configuration ? I'm looking for code that checks:
>>> - whether there are unresolved values (i.e. values with ${...} in them)
>>> - whether there are multiple keys with the same value
>>>
>>> after loading the configuration.
>>>
>>> I guess I could make these checks myself, but I think more people
>>> could be interested.
>>>
>>> Thanks,
>>> Michiel
>>>
>> there is no support for such features so far, but I think this is an
>> interesting idea.
>>
>> What would be the best way of providing such checks: as additional
>> methods of the ConfigurationUtils class or as a new dedicated checker class?
>>
>> Patches would be welcome in this area!
>>
>> Oliver
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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


Mime
View raw message