You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Mark Diggory <md...@gmail.com> on 2006/11/30 17:29:39 UTC

[configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

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

Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Mark Diggory <md...@gmail.com>.
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 <ol...@oliver-heger.de> 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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Oliver Heger <ol...@oliver-heger.de>.
I will have a look. Maybe the problem has something to do with the 
conversion of the properties configuration to a hierarchical one?

Oliver

Mark Diggory wrote:
> Actually, your example works for me too, but my real case still doesn't
> heres more detail:
> 
> my instatiation of Configuration looks more like this
> 
> CombinedConfiguration configuration = new CombinedConfiguration();
>> configuration.addConfiguration(
>>                 new PropertiesConfiguration(new
>> File(configProperty).toURL())
>>             );
>>
> 
> My properties file looks like this:
> 
> # DSpace installation directory
>> dspace.dir = /dspace
>> # Example Apache HTTPD configuration
>> # config.template.apache13.conf = ${dspace.dir}/config/httpd.conf
>> config.template.log4j.properties = ${dspace.dir}/config/log4j.properties
>> config.template.log4j-handle-plugin.properties = ${dspace.dir
>> }/config/log4j-handle-plugin.properties
>> config.template.oaicat.properties = 
>> ${dspace.dir}/config/oaicat.properties
>>
> 
> I then go on to do my test:
> 
> 
>>         System.out.println(configuration.getString("dspace.dir"));
>>         System.out.println(configuration.getString("
>> config.template.log4j.properties"));
>>         System.out.println(configuration.getString("
>> config.template.log4j-handle-plugin.properties"));
>>         System.out.println(configuration.getString("
>> config.template.oaicat.properties"));
>>
>>         Configuration subset = configuration.subset("config.template");
>>
>>         this.assertEquals(
>>                     configuration.getString("
>> config.template.log4j.properties"),
>>                     subset.getString("log4j.properties")
>>                     );
>>
>>         this.assertEquals(
>>                 configuration.getString("
>> config.template.log4j-handle-plugin.properties"),
>>                 subset.getString("log4j-handle-plugin.properties")
>>                 );
>>
>>         this.assertEquals(
>>                 
>> configuration.getString("config.template.oaicat.properties
>> "),
>>                 subset.getString("oaicat.properties")
>>                 );
>>
>>
> 
> Thanks,
> Mark
> 
> On 11/30/06, Oliver Heger <ol...@oliver-heger.de> 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: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Oliver Heger <ol...@oliver-heger.de>.
Mark Diggory wrote:

<snip/>
> 
> 
> How does this map into Properties files (it seems to me Properties files
> are kind of like all children do not share the same parent)?
> 
> We'll move eventually to XML format files, but it will take some time to
> transition.
> 
> -Mark
> 

The configurationAt() method and sub node configurations (in contrast to 
subset configurations) are only supported for hierarchical 
configurations. PropertiesConfiguration is no hierarchical 
configuration, so here only the subset() method is available.

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Mark Diggory <md...@gmail.com>.
On 12/3/06, Oliver Heger <ol...@oliver-heger.de> wrote:
>
> I have committed a fix, so subset() should work now, too.


Thanks, I'll start using the next nightly build

The difference between subset() and configurationAt() is that subset()
> allows you to select arbitrary subsets of a configuration's properties
> while the expression passed to configurationAt() must select exactly one
> configuration node.
>
> As an example consider the following configuration for database tables:
>
> <config>
>    <tables>
>      <table>
>        <name>tab1</name>
>        <fields>
>          <field>
>            <name>field1</name>
>            <type>NUMBER</name>
>          </field>
>          <field>
>            ...
>          </field>
>          ...
>        </fields>
>      </table>
>      <table>
>        <name>tab2</name>
>        ...
>      </table>
>      ...
>    </tables>
> </config>
>
> subset() allows you to select properties that need not belong to the
> same parent node, e.g.
> Configuration sub = config.subset("tables.table.fields.field");
>
> This will return a configuration that allows you easy access to all
> defined table fields. Using configurationAt() in contrast requires that
> the passed in key selects exactly one node of the hierarchical
> structure, e.g.
> Configuration sub =
> config.configurationAt("tables.table(0).fields.field(0)");
>
> If you can live with this limitation, using configurationAt() is
> recommended. The returned configuration is far more lightweight.


 How does this map into Properties files (it seems to me Properties files
are kind of like all children do not share the same parent)?

We'll move eventually to XML format files, but it will take some time to
transition.

-Mark

Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Oliver Heger <ol...@oliver-heger.de>.
I have committed a fix, so subset() should work now, too.

The difference between subset() and configurationAt() is that subset() 
allows you to select arbitrary subsets of a configuration's properties 
while the expression passed to configurationAt() must select exactly one 
configuration node.

As an example consider the following configuration for database tables:

<config>
   <tables>
     <table>
       <name>tab1</name>
       <fields>
         <field>
           <name>field1</name>
           <type>NUMBER</name>
         </field>
         <field>
           ...
         </field>
         ...
       </fields>
     </table>
     <table>
       <name>tab2</name>
       ...
     </table>
     ...
   </tables>
</config>

subset() allows you to select properties that need not belong to the 
same parent node, e.g.
Configuration sub = config.subset("tables.table.fields.field");

This will return a configuration that allows you easy access to all 
defined table fields. Using configurationAt() in contrast requires that 
the passed in key selects exactly one node of the hierarchical 
structure, e.g.
Configuration sub = 
config.configurationAt("tables.table(0).fields.field(0)");

If you can live with this limitation, using configurationAt() is 
recommended. The returned configuration is far more lightweight.

I think, the JavaDocs provide more detailed information about when to 
use which method.

Oliver

Mark Diggory wrote:
> Yes, I see it now if I use configurationAt all my tests pass correctly, for
> now I will use configurationAt
> 
> Question: why are there two different methods like this that seem to do
> semantically the same thing? Whats the difference between them?
> 
> On 12/2/06, Oliver Heger <ol...@oliver-heger.de> wrote:
>>
>> Mark,
>>
>> I can now reproduce the problem. In this code fragment you call subset()
>> rather than configurationAt(), and here interpolation fails. I have
>> created a bug report for this problem [1].
>>
>> Thanks
>> Oliver
>>
>> [1] https://issues.apache.org/jira/browse/CONFIGURATION-242
>>
>> Mark Diggory wrote:
>> > Actually, your example works for me too, but my real case still doesn't
>> > heres more detail:
>> >
>> > my instatiation of Configuration looks more like this
>> >
>> > CombinedConfiguration configuration = new CombinedConfiguration();
>> >> configuration.addConfiguration(
>> >>                 new PropertiesConfiguration(new
>> >> File(configProperty).toURL())
>> >>             );
>> >>
>> >
>> > My properties file looks like this:
>> >
>> > # DSpace installation directory
>> >> dspace.dir = /dspace
>> >> # Example Apache HTTPD configuration
>> >> # config.template.apache13.conf = ${dspace.dir}/config/httpd.conf
>> >> config.template.log4j.properties = ${dspace.dir
>> }/config/log4j.properties
>> >> config.template.log4j-handle-plugin.properties = ${dspace.dir
>> >> }/config/log4j-handle-plugin.properties
>> >> config.template.oaicat.properties =
>> >> ${dspace.dir}/config/oaicat.properties
>> >>
>> >
>> > I then go on to do my test:
>> >
>> >
>> >>         System.out.println(configuration.getString("dspace.dir"));
>> >>         System.out.println(configuration.getString("
>> >> config.template.log4j.properties"));
>> >>         System.out.println(configuration.getString("
>> >> config.template.log4j-handle-plugin.properties"));
>> >>         System.out.println(configuration.getString("
>> >> config.template.oaicat.properties"));
>> >>
>> >>         Configuration subset = 
>> configuration.subset("config.template");
>> >>
>> >>         this.assertEquals(
>> >>                     configuration.getString("
>> >> config.template.log4j.properties"),
>> >>                     subset.getString("log4j.properties")
>> >>                     );
>> >>
>> >>         this.assertEquals(
>> >>                 configuration.getString("
>> >> config.template.log4j-handle-plugin.properties"),
>> >>                 subset.getString("log4j-handle-plugin.properties")
>> >>                 );
>> >>
>> >>         this.assertEquals(
>> >>
>> >> configuration.getString("config.template.oaicat.properties
>> >> "),
>> >>                 subset.getString("oaicat.properties")
>> >>                 );
>> >>
>> >>
>> >
>> > Thanks,
>> > Mark
>>
>> <snip/>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Mark Diggory <md...@gmail.com>.
Yes, I see it now if I use configurationAt all my tests pass correctly, for
now I will use configurationAt

Question: why are there two different methods like this that seem to do
semantically the same thing? Whats the difference between them?

On 12/2/06, Oliver Heger <ol...@oliver-heger.de> wrote:
>
> Mark,
>
> I can now reproduce the problem. In this code fragment you call subset()
> rather than configurationAt(), and here interpolation fails. I have
> created a bug report for this problem [1].
>
> Thanks
> Oliver
>
> [1] https://issues.apache.org/jira/browse/CONFIGURATION-242
>
> Mark Diggory wrote:
> > Actually, your example works for me too, but my real case still doesn't
> > heres more detail:
> >
> > my instatiation of Configuration looks more like this
> >
> > CombinedConfiguration configuration = new CombinedConfiguration();
> >> configuration.addConfiguration(
> >>                 new PropertiesConfiguration(new
> >> File(configProperty).toURL())
> >>             );
> >>
> >
> > My properties file looks like this:
> >
> > # DSpace installation directory
> >> dspace.dir = /dspace
> >> # Example Apache HTTPD configuration
> >> # config.template.apache13.conf = ${dspace.dir}/config/httpd.conf
> >> config.template.log4j.properties = ${dspace.dir
> }/config/log4j.properties
> >> config.template.log4j-handle-plugin.properties = ${dspace.dir
> >> }/config/log4j-handle-plugin.properties
> >> config.template.oaicat.properties =
> >> ${dspace.dir}/config/oaicat.properties
> >>
> >
> > I then go on to do my test:
> >
> >
> >>         System.out.println(configuration.getString("dspace.dir"));
> >>         System.out.println(configuration.getString("
> >> config.template.log4j.properties"));
> >>         System.out.println(configuration.getString("
> >> config.template.log4j-handle-plugin.properties"));
> >>         System.out.println(configuration.getString("
> >> config.template.oaicat.properties"));
> >>
> >>         Configuration subset = configuration.subset("config.template");
> >>
> >>         this.assertEquals(
> >>                     configuration.getString("
> >> config.template.log4j.properties"),
> >>                     subset.getString("log4j.properties")
> >>                     );
> >>
> >>         this.assertEquals(
> >>                 configuration.getString("
> >> config.template.log4j-handle-plugin.properties"),
> >>                 subset.getString("log4j-handle-plugin.properties")
> >>                 );
> >>
> >>         this.assertEquals(
> >>
> >> configuration.getString("config.template.oaicat.properties
> >> "),
> >>                 subset.getString("oaicat.properties")
> >>                 );
> >>
> >>
> >
> > Thanks,
> > Mark
>
> <snip/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Oliver Heger <ol...@oliver-heger.de>.
Mark,

I can now reproduce the problem. In this code fragment you call subset() 
rather than configurationAt(), and here interpolation fails. I have 
created a bug report for this problem [1].

Thanks
Oliver

[1] https://issues.apache.org/jira/browse/CONFIGURATION-242

Mark Diggory wrote:
> Actually, your example works for me too, but my real case still doesn't
> heres more detail:
> 
> my instatiation of Configuration looks more like this
> 
> CombinedConfiguration configuration = new CombinedConfiguration();
>> configuration.addConfiguration(
>>                 new PropertiesConfiguration(new
>> File(configProperty).toURL())
>>             );
>>
> 
> My properties file looks like this:
> 
> # DSpace installation directory
>> dspace.dir = /dspace
>> # Example Apache HTTPD configuration
>> # config.template.apache13.conf = ${dspace.dir}/config/httpd.conf
>> config.template.log4j.properties = ${dspace.dir}/config/log4j.properties
>> config.template.log4j-handle-plugin.properties = ${dspace.dir
>> }/config/log4j-handle-plugin.properties
>> config.template.oaicat.properties = 
>> ${dspace.dir}/config/oaicat.properties
>>
> 
> I then go on to do my test:
> 
> 
>>         System.out.println(configuration.getString("dspace.dir"));
>>         System.out.println(configuration.getString("
>> config.template.log4j.properties"));
>>         System.out.println(configuration.getString("
>> config.template.log4j-handle-plugin.properties"));
>>         System.out.println(configuration.getString("
>> config.template.oaicat.properties"));
>>
>>         Configuration subset = configuration.subset("config.template");
>>
>>         this.assertEquals(
>>                     configuration.getString("
>> config.template.log4j.properties"),
>>                     subset.getString("log4j.properties")
>>                     );
>>
>>         this.assertEquals(
>>                 configuration.getString("
>> config.template.log4j-handle-plugin.properties"),
>>                 subset.getString("log4j-handle-plugin.properties")
>>                 );
>>
>>         this.assertEquals(
>>                 
>> configuration.getString("config.template.oaicat.properties
>> "),
>>                 subset.getString("oaicat.properties")
>>                 );
>>
>>
> 
> Thanks,
> Mark

<snip/>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Mark Diggory <md...@gmail.com>.
Actually, your example works for me too, but my real case still doesn't
heres more detail:

my instatiation of Configuration looks more like this

CombinedConfiguration configuration = new CombinedConfiguration();
> configuration.addConfiguration(
>                 new PropertiesConfiguration(new
> File(configProperty).toURL())
>             );
>

My properties file looks like this:

# DSpace installation directory
> dspace.dir = /dspace
> # Example Apache HTTPD configuration
> # config.template.apache13.conf = ${dspace.dir}/config/httpd.conf
> config.template.log4j.properties = ${dspace.dir}/config/log4j.properties
> config.template.log4j-handle-plugin.properties = ${dspace.dir
> }/config/log4j-handle-plugin.properties
> config.template.oaicat.properties = ${dspace.dir}/config/oaicat.properties
>

I then go on to do my test:


>         System.out.println(configuration.getString("dspace.dir"));
>         System.out.println(configuration.getString("
> config.template.log4j.properties"));
>         System.out.println(configuration.getString("
> config.template.log4j-handle-plugin.properties"));
>         System.out.println(configuration.getString("
> config.template.oaicat.properties"));
>
>         Configuration subset = configuration.subset("config.template");
>
>         this.assertEquals(
>                     configuration.getString("
> config.template.log4j.properties"),
>                     subset.getString("log4j.properties")
>                     );
>
>         this.assertEquals(
>                 configuration.getString("
> config.template.log4j-handle-plugin.properties"),
>                 subset.getString("log4j-handle-plugin.properties")
>                 );
>
>         this.assertEquals(
>                 configuration.getString("config.template.oaicat.properties
> "),
>                 subset.getString("oaicat.properties")
>                 );
>
>

Thanks,
Mark

On 11/30/06, Oliver Heger <ol...@oliver-heger.de> 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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()

Posted by Oliver Heger <ol...@oliver-heger.de>.
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org