commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <heg...@med.uni-marburg.de>
Subject Re: Problem with commons configuration
Date Tue, 15 Mar 2005 13:46:29 GMT
Stefan Aigner wrote:

> Hello all,
> 
> I have a problem with commons configuration. My setting is as follows:
> 
> I use the jar commons-configuration-1.0-rc2.jar.

Does this really read 1.0-rc2 (I am asking because the latest version is 
1.1-rc2)?

> 
> My config files are as follows:
> 
> File config.xml:
> 
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> 
> <configuration>
>     <system/>
>     <xml fileName="my-properties.xml" />
> </configuration>

If 1.0-rc2 is the correct version number, try to replace the <xml 
fileName="..."/> by a <hierarchicalXml fileName="..."/>. This should do 
the trick.

In the newer versions of configuration both <xml> and <hierarchicalXml> 
behave the same way.

HTH
Oliver

> 
> File my-properties.xml:
> 
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> 
> <configuration>
> 
>     <service-configuration>
>  
>                 <service className="...">
>                         <service-config>...</service-config>
>                         <service-factory>...</service-factory>
>                 </service>
> 
>                 <service className="...">
>                         <service-config>...</service-config>
>                         <service-factory>...</service-factory>
>                 </service>
>  
>         </service-configuration>
> 
> </configuration>
> 
> Both config files are in the classpath.
> 
> 
> Code to load the Configuration:
> 
>         ConfigurationFactory factory = 
>             new ConfigurationFactory("config.xml");
>         org.apache.commons.configuration.Configuration commonsConfig = 
> null;
>         try {
>             commonsConfig = factory.getConfiguration();
>  
>         } catch (ConfigurationException e) {
>            ...
>         }
> 
> The following code works fine:
> 
>         String serviceClassName = 
>             config.getString("service-configuration.service[@className]");
>         String serviceConfig = 
>  config.getString("service-configuration.service.service-config");
>         String serviceFactory = 
>  config.getString("service-configuration.service.service-factory");
> 
> After executing this code, the three variables above contain the 
> appropriate String values from the first 'service' element in the 
> my-properties.xml file.
> 
> Now, when I execute the following code to get a property from the second 
> 'service' element as described in the documentation, the value of the 
> String 'serviceConfigName' is null.
> 
>         String serviceConfigName = (String)
>  
> commonsConfig.getProperty("service-configuration.service(1).service-config");
> 
> What am I doing wrong here?
> 
> Any suggestions are highly appreciated.
> 
> Stefan
> _________________________________________________
> 
> Stefan Aigner . adesso AG . Ehrenbergstrasse 20 . 10245 Berlin
> 
> tel.:  +49-30-7262033-42     mobil:  +49-178-2808102
> fax:  +49-30-7262033-99     email:  aigner@adesso.de
> 
>                                http://www.adesso.de
> _______________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message