Moran Ben-David wrote:
Sorry if I did not understand your problem correctly.
Thanks for the reply again, Oliver. Your patience is much appreciated.
Neither of the Configuration implementations so far support suppression
of multiple property values. (Background is the assumption that if a
user defines these values in a configuration file, he/she will probably
later want to access them.)
My reasoning for wanting to disregard the additional values for properties
is that in my project, we are using a set of files to allow developers to
Override property values. This allows us to check-in properties files into
our Source/Version Control system and override with a custom file that isn't
checked in. E.g. our single properties file is default.config:
include = gcm.extension.config
include = log4j.config
include = gcm.config
Both log4j.config and gcm.config are checked in to source control. And we
look to them to provide default values (and comments) for each configuration
property.
However, gcm.extension.config is not checked in. That allows developers or
installations on various machines to alert the configuration just for that
install.
The fact that gcm.extension.config is not checked in allows us to commit our
configuration directory changes without worrying about overriding anyone
else's configuration.
This approach allows us to share a configuration by checking in and
overriding without the risk of affecting others.
But if you only want the first value, can't you simply use one of the
simple getter methods like getString(), getInt() etc.? These methods can
be used on properties with multiple values, too. They then return only
the first value. This also works with interpolation.
Yes I tried that when I explicitly ask for a configuration value. However,
when the AbstractFileConfiguration (I think it's that class) performs the
substitution, it uses the entire multi-value of the property. That
algorithm from what I can tell is not under my control, unless I change the
commons-configuration source code of course.
Maybe I still don't understand your use case fully.
I hope I've done a better job describing it this time. Thanks again!
Moran
Yes, I think, I now understand your use case better.
Configuration's typical solution for this use case is setting up a
ConfigurationFactory. This factory is given an XML configuration
definition file, which lists the configuration sources to include. From
these sources a CompositeConfiguration can be created, which should
exactly have the desired behavior: Properties in the first included
configuration source overwrite properties with the same keys in later
included configuration sources.
So instead of using the include machanism of PropertiesConfiguration you
can use a ConfigurationFactory to manage your combined properties. More
information about this topic and some usage examples can be found in the
howtos:
http://jakarta.apache.org/commons/configuration/howto_configurationfactory.html
I did not test this, but I think, this approach will also work with
interpolation because CompositeConfiguration by inheriting from
AbstractConfiguration is able to correctly resolve the interpolated keys.
I hope this helps you solve your problem.
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]