commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Moran Ben-David" <>
Subject RE: [configuration] Property Substitution Policy
Date Wed, 24 Aug 2005 17:28:58 GMT
Hi guys,

Thanks again for inspecting this problem with me and hashing out my various
options.  I have taken the liberty of making some modifications to 2 classes
in Commons Configuration (attached) in order to get it to do what I wanted.

Is it possible to contribute this to Commons Configuration?  I've tried to
do a good job in this code change by providing the test case.  I plan to use
commons configuration for as long as I can think and would hate to have to
make this change for every new version I get.

The summary of these changes is that I added a Boolean flag to tell the
interpolation algorithm whether to substitute using the entire multi-valued
property or just the first value.  I.e., an if statement determining whether
getString or getPoroperty are used.  I added a test case for this in what I
think is the appropriate place.

My exact changes are as follows: test case for making sure flag switches
behaviour properly.

	public void testMultiValuedPropertyInterpolation() throws Exception
		config.setProperty("multi", "value1");
		config.addProperty("multi", "value2");
		config.setProperty("interpolated", "${multi}");
		String expectedValue = "value1";	
		expectedValue = "" + config.getProperty("multi");
	} added flag

	 * Determines whether all values of a property are used or just 
	 *the first when 
	 * substituting tokens.
	private boolean interpolateAllValues = true; the if statement in interpolateHelper() to
use getString or getProperty:

	Object value;
	if (isInterpolateAllValues())
		value = getProperty(variable);
		value = getString(variable);
	} setter and getter for flag:

	public void setInterpolateAllValues(boolean b)
		this.interpolateAllValues = b;

	public boolean isInterpolateAllValues()
		return interpolateAllValues;

> -----Original Message-----
> From: Emmanuel Bourg []
> Sent: Tuesday, August 23, 2005 8:49 AM
> To: Jakarta Commons Users List
> Subject: Re: [configuration] Property Substitution Policy
> Hi Moran,
> Moran Ben-David wrote:
> > I was actually trying to get the substitution to only use the 1st value
> in a
> > multi-valued property.  For example, a file like
> >
> > 	V1 = value1
> > 	V1 = value2
> > 	Myprop = ${V1}
> >
> > Would result in a configuration having
> >
> > 	Myprop = value1
> >
> > This way, when I do config.getString("Myprop") I'd get "value1" and not
> > "[value1, value2]".
> I tend to agree on this, the interpolated value should be a scalar, this
> would be consistent with the getString() method called on a multi-valued
> property.
> However regarding your use case I agree with Oliver, using a
> CompositeConfiguration is the right solution. You can build it
> programatically, or use the ConfigurationFactory with a configuration
> descriptor.
> Emmanuel Bourg
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View raw message