commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Torrance <greg.torra...@pobox.com>
Subject Re: [configuration] Custom variable interpolation
Date Wed, 23 Nov 2016 21:49:48 GMT
Hi Oliver,

Thanks for the info!

I created a ticket for the documentation inconsistency. I trust it's 
suitable.

    https://issues.apache.org/jira/browse/CONFIGURATION-643

Thanks,
Greg

On 11/23/2016 03:41 PM, Oliver Heger wrote:
> Hi Greg,
>
> Am 23.11.2016 um 00:50 schrieb Greg Torrance:
>> Hi all,
>>
>> I would like to implement a custom variable interpolator that is
>> specific to a Configuration object, but that also supports the standard
>> prefixes (sys, const, env).
>>
>> What I mean by "specific to a Configuration object" is that the custom
>> interpolator needs to know the Configuration to which it is associated
>> in order to produce a valid result for a variable.
>>
>> Say I want to associate a variable "rootDir" with the custom prefix
>> "myPrefix". To use this variable I would specify ${myPrefix:rootDir} in
>> my configuration file. At the code level, though, if I create a
>> Configuration config1, I want "rootDir" for that Configuration to
>> evaluate to "/abc/def". But for Configuration config2, "rootDir" should
>> evaluate to "/ghi/jkl". I assume I will need to have a specific Lookup
>> instance per Configuration, right?
>>
>> I have tried to understand how to do this based on this page
>> (https://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html#Customizing_interpolation),
>> but the information seems to be a bit inaccurate based on v2.1. (For
>> example, it refers to calling the static registerGlobalLookup() method
>> on ConfigurationInterpolator, but this method does not appear to exist.)
> Could you please open a ticket in our bugtracking system [1] when you
> notice inconsistencies in the documentation, so that they can be fixed?
> Thanks in advance!
>
> [1]
> https://commons.apache.org/proper/commons-configuration/issue-tracking.html
>
>> Also, I'm not clear if I should be extending StrLookup, or implementing
>> Lookup. (I was initially using StrLookup, but the
>> ConfigurationInterpolator registerLookup() method requires a Lookup
>> instance.)
> StrLookup is from [lang], to avoid a direct dependency, [configuration]
> uses its own abstraction. But the Lookup interface is so simple that it
> can be easily implemented.
>
>> If I do the following, it seems to allow me create a working custom
>> interpolator. But when I do this, the standard prefixes (sys, const,
>> env) no longer work:
>>
>> ConfigurationInterpolator ci = new ConfigurationInterpolator();
>> ci.registerLookup("myPrefix", new MyLookup()); // implementation of
>> Lookup interface
>> config1.setInterpolator(ci);
> You can try the following:
> config1.getInterpolator().registerLookup( ... );
>
> This should add the new lookup to the existing ones.
>
> Oliver
>
>> Any thoughts on how to implement this using Commons Configuration best
>> practices?
>>
>> Thanks in advance,
>> Greg
>>
>> ---------------------------------------------------------------------
>> 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