You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "ralph.goers @dslextreme.com" <rg...@apache.org> on 2008/11/07 07:25:06 UTC
[configuration] CombinedConfiguration.getSource()
I don't understand why getSource throws an Exception when a property can be
found in multiple configurations. If the property is not a list or if
escaping is disabled then the value from the first Configuration the key is
found in will be used. Shouldn't an Exception only be thrown when the value
is constructed by merging values from two Configurations? (This only seems
to happen if a String with the escape character is present). I'm writing a
class that extends CombinedConfiguration and I wanted to changed this
behavior so that it works that way but unfortunately findSourceConfiguration
is private instead of protected so I can't reimplement getSource without
also reimplementing findSourceConfiguration.
Re: [configuration] CombinedConfiguration.getSource()
Posted by Ralph Goers <ra...@dslextreme.com>.
Oliver Heger wrote:
>
>
> The getSource() method was added on behalf of CONFIGURATION-215 [1].
> The original request was a bit adapted to come to a more generic
> solution. IIRC the usage scenario was that you have multiple child
> configurations with different name spaces and want to uniquely
> identify the child configuration that added a specific key. If
> multiple child configurations define the key in question, no unique
> source can be identified; hence the exception.
>
> Do you propose making findSourceConfiguration() protected? I did not
> do this in the past because I was not sure whether there would be
> another use case for this method and I wanted to keep the API lean.
> But if you need it, I am not against this change.
>
>
No, I wouldn't necessarily make it protected. It would be a bad idea to
have some classes have the method behave in one manner while in another
it behaves differently.
I ran into this problem because my use cases involve a combined
configuration where all the defaults are in the base configuration and
the first configuration contains values that override the defaults. I
was simply trying to write a unit test that listed the source for each
key to verify my new class was working properly.
I don't want to distract things by going into the details of this (I'll
do that when I submit the code), but in this case getSource seems to be
completely useless as it throws an exception for every key that is
defined in the override file. For the purposes you are suggesting a
better method name would have been getUniqueSource(). For my purposes
adding a getFirstSource() method would make sense. This would never
throw an exception but would either return the first configuration
containing the key or would return null. The only question would be what
to do about Lists. In all my use cases I will be disabling this behavior
as I never want to combine the data from multiple configurations.
Ralph
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [configuration] CombinedConfiguration.getSource()
Posted by Oliver Heger <ol...@oliver-heger.de>.
ralph.goers @dslextreme.com schrieb:
> I don't understand why getSource throws an Exception when a property can be
> found in multiple configurations. If the property is not a list or if
> escaping is disabled then the value from the first Configuration the key is
> found in will be used. Shouldn't an Exception only be thrown when the value
> is constructed by merging values from two Configurations? (This only seems
> to happen if a String with the escape character is present). I'm writing a
> class that extends CombinedConfiguration and I wanted to changed this
> behavior so that it works that way but unfortunately findSourceConfiguration
> is private instead of protected so I can't reimplement getSource without
> also reimplementing findSourceConfiguration.
>
The getSource() method was added on behalf of CONFIGURATION-215 [1]. The
original request was a bit adapted to come to a more generic solution.
IIRC the usage scenario was that you have multiple child configurations
with different name spaces and want to uniquely identify the child
configuration that added a specific key. If multiple child
configurations define the key in question, no unique source can be
identified; hence the exception.
Do you propose making findSourceConfiguration() protected? I did not do
this in the past because I was not sure whether there would be another
use case for this method and I wanted to keep the API lean. But if you
need it, I am not against this change.
Oliver
[1] https://issues.apache.org/jira/browse/CONFIGURATION-215
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org