Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 17953 invoked from network); 15 Sep 2009 18:54:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Sep 2009 18:54:39 -0000 Received: (qmail 73673 invoked by uid 500); 15 Sep 2009 18:54:38 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 73557 invoked by uid 500); 15 Sep 2009 18:54:38 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 73325 invoked by uid 99); 15 Sep 2009 18:54:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Sep 2009 18:54:38 +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.17.10] (HELO moutng.kundenserver.de) (212.227.17.10) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Sep 2009 18:54:26 +0000 Received: from [192.168.178.20] (trir-5d80363b.pool.mediaWays.net [93.128.54.59]) by mrelayeu.kundenserver.de (node=mrbap2) with ESMTP (Nemesis) id 0MKt72-1MndAC3QsV-000gxI; Tue, 15 Sep 2009 20:54:05 +0200 Message-ID: <4AAFE2CB.1000006@oliver-heger.de> Date: Tue, 15 Sep 2009 20:54:03 +0200 From: Oliver Heger User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Commons Users List Subject: Re: [CONFIGURATION] Help with optional XML file in override section of configuration builder. References: <99e30fe50909140530v679e8cd9jfe7d744f02346f32@mail.gmail.com> <4AAE9B85.3040001@oliver-heger.de> <99e30fe50909150134t1843f2a1q6c80326ffff4709@mail.gmail.com> In-Reply-To: <99e30fe50909150134t1843f2a1q6c80326ffff4709@mail.gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V01U2FsdGVkX1/ACWEVmIgA/fFdc0rMiGYuBYnZ/zpWAyvaC4X k0C+SGVh+UfoHRw3CIhtpLNDimWakgUT4HmEQuT/pB3NzBXymn QivFfaZ+hIOvIKdw7zCxw== X-Virus-Checked: Checked by ClamAV on apache.org Martin Ritchie schrieb: > 2009/9/14 Oliver Heger : >> Martin Ritchie schrieb: >>> Hi, >>> >>> I have been reading the Configuration Builder docs >>> >>> (http://commons.apache.org/configuration/userguide/howto_configurationbuilder.html) >>> and have been trying to get the configuration below to take my >>> optional configuration. >>> However, both the test.config property and the resulting file must >>> exist even though I have marked the config as optional. Can someone >>> with more understanding of commons configuartion take a look at the >>> config below and point out what I've done wrong? >>> >>> Regards >>> Martin >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >> Maybe you can provide a short code fragment demonstrating how you load this >> configuration. What exactly happens, do you get an exception? >> >> Per default, the configuration builder logs an exception if it cannot create >> a configuration marked as optional. But this should not have any further >> consequences. >> >> Oliver > > Hi Oliver, > > I've put the code and errors up here: > http://pastie.org/617143 > > Perhaps I'm misunderstanding quite how the Configuration works. I > would have expected that an optional value would be skipped if it > cannot resolve the variables in the name or the file does not exist. > > If the default behaviour is to create the optional configuration then > I can understand my first exception as I have not defined variable ; > test.config. However I can't understand the second exception occurs > because the file does not exist and so the default behaviour of > creating the file should proceed. > > Thanks again for your help > > Martin > Whether the variable for the file name exists or not is not checked, the configuration always tries to load the file. The second exception is probably caused by your usage of ConfigurationFactory. Try DefaultConfigurationBuilder instead. Its API is very similar to the one of ConfigurationFactory, but it is more powerful and thus it is recommended to use this class. IIRC ConfigurationFactory does not understand the "config-optional" attribute - it only knows the "optional" attribute. Oliver --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org