commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Torrance <>
Subject [configuration] Custom variable interpolation
Date Tue, 22 Nov 2016 23:50:31 GMT
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 

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.)

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 

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

Any thoughts on how to implement this using Commons Configuration best 

Thanks in advance,

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

View raw message