commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mansour Al Akeel <mansour.alak...@gmail.com>
Subject Prefix for combined configuration
Date Sat, 09 Apr 2016 04:07:35 GMT
Hello,

I am trying to load multiple sources into a CombinedConfiguration
object. However, I need to access each property using a prefix.
For example, a property that resides in "global.xml" needs to be
accessed with a unique prefix:

glob:this.is.a.global.property.

And a property that is loaded from "case.properties", needs to be
accessed with the prefix:

case:another.case.specific.property

I can extend CombinedConfiguration and override the getters, or create
a map. But if it's possible out of the box, it will save me sometime.
So here's my sample code:

        Parameters params = new Parameters();

        URL url =
ConfigurationManager.class.getClassLoader().getResource("META-INF/global.xml");
        URL url2 =
ConfigurationManager.class.getClassLoader().getResource("META-INF/case.properties");

        FileBasedConfigurationBuilder<XMLConfiguration> globBuilder =
new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class);
        globBuilder = globBuilder.configure(params.xml().setURL(url));

        FileBasedConfigurationBuilder<PropertiesConfiguration>
testBuilder = new
FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class);
        testBuilder.configure(params.properties().setURL(url2));

        CombinedConfiguration cc = new CombinedConfiguration();

        // cc.setExpressionEngine(new XPathExpressionEngine());

        cc.addConfiguration(globBuilder.getConfiguration(), null, "global:");
        cc.addConfiguration(testBuilder.getConfiguration(), null, "case:");

        config = ConfigurationUtils.unmodifiableConfiguration(cc);


This is working great so far, as I can do:

global:.this.is.a.global

Please note the dot in the dotted notation, between the prefix and the
property name. It will be nice if I there is an easy way to remove it,
so that I can do "global:this.is.a.global.property".

Any advice ?


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