commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()
Date Sun, 03 Dec 2006 21:15:26 GMT
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 <oliver.heger@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


Mime
View raw message