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]
Date Mon, 02 Mar 2015 20:45:03 GMT


Am 02.03.2015 um 10:53 schrieb Velladurai Pandian, Ashok Kumar:
> I have a hierarchy of property files which are available in various folders in my file
system. The file names are same but the folders are named based on the base group and specific
group id and.
> 
> I have a requirement of creating group based configurations of all the available property
files. Based on the user login I need load their respective group and if not available at
that level it would go to the base group and get the key.
> 
> I am trying use the MultiFileConfigurationBuilder<http://commons.apache.org/proper/commons-configuration/xref/org/apache/commons/configuration2/builder/combined/MultiFileConfigurationBuilder.html>
and trying to set the pattern to combine the configurations. To the pattern I would set the
group id and get the configuration and merge with that of the base group.
> 
> But the pattern does not seem to be working. Is it possible to load and merge the configurations
just only using the config.xml files?
> 
> Please let me know if you have a better approach.
> 
> Parameters params = new Parameters();
>            MultiFileBuilderParameters multiParam = params.multiFile().setFilePattern("${GROUP_ID}/
app_settings.properties").setManagedBuilderParameters(params.fileBased().setBasePath("C:/a_container/MyApp/"));
>            MultiFileConfigurationBuilder<PropertiesConfiguration> builder = new
MultiFileConfigurationBuilder(
>                      PropertiesConfiguration.class).configure(multiParam);
>      Map<String, Object> params1 = new HashedMap<String, Object>();
>            params1.put("GROUP_ID", "987987");
>            builder.setParameters(params1);
>            Configuration conf = builder.getConfiguration();
>            sopAllKeys((FileBasedConfiguration) conf);

The problem is that the variable in the file pattern cannot access
parameters passed to the builder. It is interpreted by the typical
interpolation mechanisms used by configuration objects (refer to
http://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html#Variable_Interpolation).

Maybe you can solve your problem with Java system properties. Set the
name of the directory as a specific system property and reference the
same property in your expression with the "sys" prefix (e.g.
${sys:mySystemProperty}). There is an example which embeds a multi file
configuration into a DynamicCombinedConfiguration also using system
variables to load the correct configuration files:

http://commons.apache.org/proper/commons-configuration/userguide/howto_multitenant.html#Sample_Configuration

HTH
Oliver

> 
> Regards,
> Ashok
> 
> _____________
> The information contained in this message is proprietary and/or confidential. If you
are not the intended recipient, please: (i) delete the message and all copies; (ii) do not
disclose, distribute or use the message in any manner; and (iii) notify the sender immediately.
In addition, please be aware that any message addressed to our domain is subject to archiving
and review by persons other than the intended recipient. Thank you.
> 

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


Mime
View raw message