Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 4516 invoked from network); 31 Mar 2011 19:00:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Mar 2011 19:00:44 -0000 Received: (qmail 30650 invoked by uid 500); 31 Mar 2011 19:00:44 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 30592 invoked by uid 500); 31 Mar 2011 19:00:43 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 30584 invoked by uid 99); 31 Mar 2011 19:00:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Mar 2011 19:00:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Mar 2011 19:00:42 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id B32F18C00A for ; Thu, 31 Mar 2011 19:00:05 +0000 (UTC) Date: Thu, 31 Mar 2011 19:00:05 +0000 (UTC) From: "Fabien Nisol (JIRA)" To: issues@commons.apache.org Message-ID: <2095124881.25360.1301598005730.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <175039108.21818.1301509205714.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (CONFIGURATION-441) CompositeConfiguration does not resolve referenced properties correctly MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CONFIGURATION-441?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13014142#comment-13014142 ] Fabien Nisol commented on CONFIGURATION-441: -------------------------------------------- I think overriding the _interpolate(Object)_ and _getProperty(String key)_ on CompositeConfiguration like this should do the trick: {code} /** * Read property from underlying composite * * @param key key to use for mapping * * @return object associated with the given configuration key. */ public Object getProperty(String key) { Object value = null; for (Iterator i = configList.iterator(); i.hasNext();) { Configuration config = (Configuration) i.next(); if (config.containsKey(key)) { value = config.getProperty(key); } } if(value==null) return null; else return interpolate(value); } ... /** * Read property from underlying composite * * @param key key to use for mapping * * @return object associated with the given configuration key. */ public Object getProperty(String key) { Object value = null; for (Iterator i = configList.iterator(); i.hasNext();) { Configuration config = (Configuration) i.next(); if (config.containsKey(key)) { value = config.getProperty(key); } } if(value==null) return null; else return interpolate(value); } {code} > CompositeConfiguration does not resolve referenced properties correctly > ----------------------------------------------------------------------- > > Key: CONFIGURATION-441 > URL: https://issues.apache.org/jira/browse/CONFIGURATION-441 > Project: Commons Configuration > Issue Type: Bug > Components: Interpolation > Affects Versions: 1.5 > Environment: all > Reporter: Fabien Nisol > > Imagine a composite configuration consisting of > config_x : configuration one > property.one=one > property.two=two > config_y : configuration two > property.one.ref=${property.one} > When getProperty() is called on a CompositeConfiguration, property interpolation does not work if a property in config_x refers to a property in config_y, in the example, property.one.ref won't translate into "one" > This seems to be caused by the getProperty() implementation of CompositeConfiguration > {code:title=CompositeConfiguration.getProperty(String)} > /** > * Read property from underlying composite > * > * @param key key to use for mapping > * > * @return object associated with the given configuration key. > */ > public Object getProperty(String key) > { > Configuration firstMatchingConfiguration = null; > for (Iterator i = configList.iterator(); i.hasNext();) > { > Configuration config = (Configuration) i.next(); > if (config.containsKey(key)) > { > firstMatchingConfiguration = config; > break; > } > } > if (firstMatchingConfiguration != null) > { > return firstMatchingConfiguration.getProperty(key); > } > else > { > return null; > } > } > {code} > The methods finds the first configuration containing the key, and delegates the call to that particular configuration. > A possible fix would be to try interpolation against every configuration until an interpolation succeed. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira