Thanks, this is interesting news, I'll dig deeper into my configuration. And
tray a few other tests. Is there a way to turn interpolation off/on? thanks,
Mark
On 11/30/06, Oliver Heger <[EMAIL PROTECTED]> wrote:
Mark Diggory wrote:
> I'm trying to use variable interpolation in version 1.3 I'm unsure of
the
> behavior with Sub-configurations. I'm wondering if interpolation should
> work
> in these as well (i.e. using the entire configuration to interpolate
> against. For instance if I have
>
> base.dir=/home/foo
>
> test.absolute.dir.x=${base.dir}/mypath
> test.absolute.dir.y=${base.dir}/mypath1
> test.absolute.dir.z=${base.dir}/mypath2
>
> If I call something like:
>
> Configuration config = configuration.configurationAt("test.absolute.dir
");
> for (Iterator iter = config.getKeys(); iter.hasNext();)
> {
> String key = (String) iter.next();
> System.out.println(key + "=" + config.getString(key));
> }
>
> this prints out
>
> x=${base.dir}/mypath
> y=${base.dir}/mypath1
> z=${base.dir}/mypath2
>
> I was naively expecting
>
> x=/home/foo/mypath
> y=/home/foo/mypath1
> z=/home/foo/mypath2
>
> Thoughts?
> Mark
>
Not sure what happens here. Based on your code fragment I added the
following test case to TestSubnodeConfiguration [1]:
public void testInterpolationFromConfigurationAt()
{
parent.addProperty("base.dir", "/home/foo");
parent.addProperty("test.absolute.dir.dir1", "${base.dir
}/path1");
parent.addProperty("test.absolute.dir.dir2", "${base.dir
}/path2");
parent.addProperty("test.absolute.dir.dir3", "${base.dir
}/path3");
Configuration sub = parent.configurationAt("test.absolute.dir");
for(int i = 1; i < 4; i++)
{
assertEquals("Wrong interpolation in parent",
"/home/foo/path" + i, parent.getString("test.absolute.dir.dir" + i));
assertEquals("Wrong interpolation in subnode",
"/home/foo/path" + i, sub.getString("dir" + i));
}
}
and it works. SubnodeConfiguration overloads the interpolate() method
and calls interpolate() on its parent. So the whole key should be
evaluated.
Don't know why you get different results. Do you use special expression
engines or something like that?
Oliver
[1]
http://svn.apache.org/repos/asf/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]