You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by James Mansion <ja...@mansionfamily.plus.com> on 2007/08/04 17:12:22 UTC

problems with configuration

Using configuration 1.4, XP, SunJVM 1.5.0_12

I'm trying to use configuration as a  newbie.

I have in my code:

    DefaultConfigurationBuilder builder = new
DefaultConfigurationBuilder() ;
    builder.setURL(getClass().getResource("standard-config.xml")) ;
    HierarchicalConfiguration cfg =
builder.configurationAt("processor-bean") ;

This fails with:

    java.lang.IllegalArgumentException: Passed in key must select
exactly one node: processor-bean


The standard-config.xml is:

<configuration>
    <!--Load the optional specified config file-->
    <xml fileName="standard-processor.xml" optional="true">
    </xml>
</configuration>

and standard-processor.xml is:

<standard-processor>
    <processor-bean config-class="com.msgware.mwdoc.Processor"
verbose="true">
       <fileLoader config-class="com.msgware.mwdoc.FileLoader">
       </fileLoader>
       <blockInferenceEngine
config-class="com.msgware.BlockInferenceEngine">
       </blockInferenceEngine>
    </processor-bean>
</standard-processor>


Unfortunately the fetchNodeList returns nothing.

If of the configurationAt instead I go:

            Configuration tmp = builder.getConfiguration() ;

            Iterator i = tmp.getKeys() ;

            while (i.hasNext())
            {
                System.out.println("Got key: "+i.next()) ;
            }

Then I get broadly what I had expected:

Got key: processor-bean.fileLoader[@config-class]
Got key: processor-bean.blockInferenceEngine[@config-class]
Got key: processor-bean[@config-class]
Got key: processor-bean[@verbose]

What am I doing wrong?



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


Re: problems with configuration

Posted by Oliver Heger <ol...@oliver-heger.de>.
James Mansion wrote:
> Oliver Heger wrote:
>> Try builder.getConfiguration().configurationAt(...) instead of 
>> builder.configurationAt().
>>
>> Only the getConfiguration() method causes the configuration sources to 
>> be loaded. The object returned here contains all the properties.
>>
> Surely getConfiguration returns a Configuration, which doesn't have a 
> configurationAt() member?

Sorry, you are right. You can either use the overloaded 
getConfiguration() method, which takes a boolean argument, and set this 
argument to true. Or you cast the result of getConfiguration(). Both 
methods returns a CombinedConfiguration object, which is derived from 
HierarchicalConfiguration.

Oliver

> 
> I had to cast to HierachicalConfiguration first.  Now I get 'Property 
> verbose cannot be set!' which does at least suggest that the bean
> is being constructed.  I'll debug to find out why.
> 
> Thanks!
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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


Re: problems with configuration

Posted by James Mansion <ja...@mansionfamily.plus.com>.
Oliver Heger wrote:
> Try builder.getConfiguration().configurationAt(...) instead of 
> builder.configurationAt().
>
> Only the getConfiguration() method causes the configuration sources to 
> be loaded. The object returned here contains all the properties.
>
Surely getConfiguration returns a Configuration, which doesn't have a 
configurationAt() member?

I had to cast to HierachicalConfiguration first.  Now I get 'Property 
verbose cannot be set!' which does at least suggest that the bean
is being constructed.  I'll debug to find out why.

Thanks!


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


Re: problems with configuration

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi James,

James Mansion wrote:
> Using configuration 1.4, XP, SunJVM 1.5.0_12
> 
> I'm trying to use configuration as a  newbie.
> 
> I have in my code:
> 
>    DefaultConfigurationBuilder builder = new
> DefaultConfigurationBuilder() ;
>    builder.setURL(getClass().getResource("standard-config.xml")) ;
>    HierarchicalConfiguration cfg =
> builder.configurationAt("processor-bean") ;

Try builder.getConfiguration().configurationAt(...) instead of 
builder.configurationAt().

Only the getConfiguration() method causes the configuration sources to 
be loaded. The object returned here contains all the properties.

HTH
Oliver

> 
> This fails with:
> 
>    java.lang.IllegalArgumentException: Passed in key must select
> exactly one node: processor-bean
> 
> 
> The standard-config.xml is:
> 
> <configuration>
>    <!--Load the optional specified config file-->
>    <xml fileName="standard-processor.xml" optional="true">
>    </xml>
> </configuration>
> 
> and standard-processor.xml is:
> 
> <standard-processor>
>    <processor-bean config-class="com.msgware.mwdoc.Processor"
> verbose="true">
>       <fileLoader config-class="com.msgware.mwdoc.FileLoader">
>       </fileLoader>
>       <blockInferenceEngine
> config-class="com.msgware.BlockInferenceEngine">
>       </blockInferenceEngine>
>    </processor-bean>
> </standard-processor>
> 
> 
> Unfortunately the fetchNodeList returns nothing.
> 
> If of the configurationAt instead I go:
> 
>            Configuration tmp = builder.getConfiguration() ;
> 
>            Iterator i = tmp.getKeys() ;
> 
>            while (i.hasNext())
>            {
>                System.out.println("Got key: "+i.next()) ;
>            }
> 
> Then I get broadly what I had expected:
> 
> Got key: processor-bean.fileLoader[@config-class]
> Got key: processor-bean.blockInferenceEngine[@config-class]
> Got key: processor-bean[@config-class]
> Got key: processor-bean[@verbose]
> 
> What am I doing wrong?
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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