Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 31711 invoked from network); 17 Jun 2009 19:54:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Jun 2009 19:54:23 -0000 Received: (qmail 18275 invoked by uid 500); 17 Jun 2009 19:54:34 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 18179 invoked by uid 500); 17 Jun 2009 19:54:34 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 18138 invoked by uid 99); 17 Jun 2009 19:54:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Jun 2009 19:54:34 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_HELO_PASS,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [212.227.126.187] (HELO moutng.kundenserver.de) (212.227.126.187) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Jun 2009 19:54:23 +0000 Received: from [192.168.178.20] (trir-5d8051cc.pool.einsundeins.de [93.128.81.204]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0MKv1o-1MH1Ct1d9d-000jvn; Wed, 17 Jun 2009 21:54:03 +0200 Message-ID: <4A3949DA.9030308@oliver-heger.de> Date: Wed, 17 Jun 2009 21:54:02 +0200 From: Oliver Heger User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Commons Developers List Subject: Re: [configuration] Merging overrides with defaults References: <34abb48b0906161451h4b61cd2byde322cf73c2cd528@mail.gmail.com> <34abb48b0906161500u4726e4bcn2b261acbcdc6b03c@mail.gmail.com> <34abb48b0906170939k1bd76c13ued98d99214e94558@mail.gmail.com> <34abb48b0906171030w33f45ea7wcbeee8037ea26a0f@mail.gmail.com> In-Reply-To: <34abb48b0906171030w33f45ea7wcbeee8037ea26a0f@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Provags-ID: V01U2FsdGVkX18fVgzebXUD1vl8QwW5dB8H1lJ+iHl+OubJqMR B9ch0jdB24boxS0RVs90tb/eeinzZmJns91JmB8eT0U/JNVhp5 LFHamLh/ZJa/hI05i8Pgg== X-Virus-Checked: Checked by ClamAV on apache.org Alec Swan schrieb: > I wrote the code following the example on > http://commons.apache.org/configuration/userguide-1.2/howto_compositeconfiguration.html > > There is no save() method in CompositeConfiguration. How can I save it? > > Thanks. The merged configuration produced by CompositeConfiguration is only virtual, i.e. there is no physical PropertiesConfiguration containing the merged properties. It lives only in memory and cannot be saved. I am afraid, Commons Configuration does not provide an easy solution for your problem. You can copy the content of the composite configuration into a properties configuration, e.g.: PropertiesConfiguration propConfig = new PropertiesConfiguration(); propConfig.copy(compositeConfig); propConfig.save(someFile); But this will copy only the properties and not the comments or the overall layout. Oliver > > > On Wed, Jun 17, 2009 at 11:23 AM, J�rg Schaible wrote: > >> Alec Swan wrote at Mittwoch, 17. Juni 2009 18:39: >> >>> Thank you for updating the subject, J�rg. >>> >>> I changed the order in which I add defaults and overrides. The following >>> is the new code: >>> >>> // merge overrides with defaults >>> CompositeConfiguration compositeConfig = new >>> CompositeConfiguration(overridingConfig); >>> compositeConfig.addConfiguration(defaultConfig); >>> >>> // convert merged properties to string >>> StringWriter writer = new StringWriter(); >>> overridingConfig.save(writer); >>> >>> defaultConfig contains the following properties: >>> # A property >>> A = 1 >>> # B property >>> B = 2 >>> >>> overridingConfig contains the following properties: >>> B = 3 >>> >>> I expected the merged content written to the writer to contain these >>> properties: >>> # A property >>> A = 1 >>> # B property >>> B = 3 >>> >>> Instead, the merged content written to the writer is the same as the >>> overridingConfig: >>> B = 3 >>> >>> Could anybody tell me what's wrong with my code? >> You saved the overridingConfiguration and not the compositeConfig. >> >> - J�rg >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org >> For additional commands, e-mail: dev-help@commons.apache.org >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org