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 Re: Prefix for combined configuration
Date Sat, 09 Apr 2016 23:09:55 GMT
Oliver,
In fact , this is exactly what I ended up doing, implementing
ExpressionEngine and I think in fact this is the proper way to do it.
However, I am facing some issues, doing it cleanly, because I am
extending DefaultConfigurationKey. Unfortunately, the keyBuffer
(StringBuilder) is private, and can not access it from the child
class. The only way is to copy/paste everything in
DefaultConfigurationKey.

After all, I think I am on the right track.
Thank you a lot.


On Sat, Apr 9, 2016 at 2:45 PM, Oliver Heger
<oliver.heger@oliver-heger.de> wrote:
> Hi Mansour,
>
> Am 09.04.2016 um 06:07 schrieb Mansour Al Akeel:
>> 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".
>
> When a prefix is provided when adding a configuration to a
> CombinedConfiguration, internal node structures are created that
> correspond to this prefix. Resolving of such keys therefore requires a
> dot (or separator) behind the prefix because the nodes with
> configuration data are actually child nodes of the prefix node. This is
> how it works internally.
>
> Maybe the following trick could be an option: You could create your own
> ExpressionEngine implementation that delegates to another
> ExpressionEngine instance. In the implementation of the query() method
> you modify the passed in key by replacing the first ":" by ":." and then
> invoke the wrapped engine. I guess this should achieve what you want and
> is pretty straight-forward.
>
> Oliver
>
>>
>> Any advice ?
>>
>>
>> Thank you.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

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


Mime
View raw message