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.)
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.)
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);
Any thoughts on how to implement this using Commons Configuration best
practices?
Thanks in advance,
Greg
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org