commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [configuration] XML, DefaultConfigurationBuilder: configurationAt gives different result than fully qualified keys
Date Wed, 24 Jan 2007 20:55:26 GMT
Hi,

maybe this is a typo, but the problem seems to be in the last while() 
loop of your test program:

 >        SubnodeConfiguration c2 =
 > configuration.configurationAt("environments/environment[@name='dvl9']");
 >        Iterator keys2 = c2.getKeys();
 >        while(keys2.hasNext()) {
 >            String next = (String) keys2.next();
 >            System.out.println(next + " = " + 
configuration.getList(next));
 >        }

Instead of
configuration.getList(next);
it should be
c2.getList(next);

I hope this is all!
Oliver

Thorbjørn Ravn Andersen wrote:
> Hi,
> 
> I am trying to migrate to commons configuration for all the usual 
> reasons, but have run into the following problem which I would 
> appreciate if a more knowledgeable person than me would glance at.  I 
> want to migrate a set of property files into a single XML-file to have a 
> more maintainable system, while keeping the code as similar as possible.
> 
> 
> The following code gives me an incorrect result:
> 
>        SubnodeConfiguration c2 = 
> configuration.configurationAt("environments/environment[@name='dvl9']");
> 
> The keys appear to be correct of c2, but the values are all empty.
> This is against SVN of today, as the 1.3 release hits a JIRA.
> 
> -- output --
> 
> 1 configurations:
> environments/environment/env/@name = [server.name, server.type, 
> server.program.lib]
> environments/environment/env/@value = [server, AS/400, 
> /QSYS.LIB/DVEROBJ.LIB/]
> environments/environment/@name = [dvl9]
> -----
> env/@name = []
> env/@value = []
> @name = []
> 
> 
> --  configuration file --
> 
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> 
> <configuration>
>    <header>
>        <result>
>            <expressionEngine
>                
> config-class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine" 
> />
>        </result>
>    </header>
>    <override>
>        <xml config-name="s" fileName="environments.xml"
>            config-at="environments">
>        </xml>
>    </override>
>    <additional>
> 
>        <!-- Configuration declarations that form a union configuration -->
>    </additional>
> </configuration>
> 
> -- environments.xml ----
> 
> <!-- four soft default environments -->
> <environments>
>    <environment name="dvl9">
>        <env name="server.name" value="server" />
>        <env name="server.type" value="AS/400" />
>        <env name="server.program.lib" value="/QSYS.LIB/DVEROBJ.LIB/" />
>    </environment>
> </environments>
> 
> -- code --
> 
> package bad;
> 
> 
> import java.util.Iterator;
> 
> import org.apache.commons.configuration.CombinedConfiguration;
> import org.apache.commons.configuration.ConfigurationException;
> import org.apache.commons.configuration.DefaultConfigurationBuilder;
> import org.apache.commons.configuration.SubnodeConfiguration;
> 
> public class ConfigurationUtils {
>      public CombinedConfiguration getConfiguration() {
>        try {
>            return getConfiguration_();
>        } catch (ConfigurationException e) {
>            throw new RuntimeException("bad configuration", e);
>        }
>    }
>      public CombinedConfiguration getConfiguration_() throws 
> ConfigurationException {
>        DefaultConfigurationBuilder builder = new 
> DefaultConfigurationBuilder();
>        builder.setFileName("config.xml");
>        return builder.getConfiguration(true);
>    }
>      public static void main(String[] args) {
>        CombinedConfiguration configuration = new 
> ConfigurationUtils().getConfiguration();
>        System.out.println(configuration.getNumberOfConfigurations() + " 
> configurations:");
>        Iterator keys = configuration.getKeys();
>        while(keys.hasNext()) {
>            String next = (String) keys.next();
>            System.out.println(next + " = " + configuration.getList(next));
>        }
>        System.out.println("-----");
>        SubnodeConfiguration c2 = 
> configuration.configurationAt("environments/environment[@name='dvl9']");
>        Iterator keys2 = c2.getKeys();
>        while(keys2.hasNext()) {
>            String next = (String) keys2.next();
>            System.out.println(next + " = " + configuration.getList(next));
>        }
>    }
> }
> 
> ==
> I would appreciate any pointers and hints helping me figuring out what I 
> have misunderstood.
> 


---------------------------------------------------------------------
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