commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Aigner <aig...@adesso.de>
Subject Problem with commons configuration
Date Tue, 15 Mar 2005 13:02:36 GMT
Hello all,

I have a problem with commons configuration. My setting is as follows:

I use the jar commons-configuration-1.0-rc2.jar.

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>

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
_______________________________________________________
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message