You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Don Vawter <do...@vawter.com> on 2005/01/08 08:50:36 UTC

newbie ?, empty config

I am making my first attempt to use the Configuration capabilities and 
am obviously doing something wrong.
The configuration object is not null but isEmpty() returns true.

Any guidance would be greatly appreciated as I struggle up the learning 
curve.

TIA


Here is my config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
  <hierarchicalXml 
fileName="/projects/svnVawter/src/com/vawter/vawter/buttons.xml"/>
</configuration>

and here a code snippet:

  private static final Logger logger = Logger.getLogger(NavBar.class);
        private static  ConfigurationFactory factory=null;
        private static URL configURL = null;
        private static Configuration config=null;
        static{
                try{
                        factory = new ConfigurationFactory();
                        String navfile= 
PropertyHandler.getProperty("navigation.config.file");
                        logger.debug("navigation.config.file is " + 
navfile);
                        if(navfile!=null) {
                            factory.setConfigurationFileName(navfile);
                           Configuration config = 
factory.getConfiguration();

                         logger.debug("configuration factory is "+ config);
                        logger.debug("configuration is empty " + 
config.isEmpty());
.....
and here is the logger:

DEBUG,2005-01-08 
00:31:10,com.vawter.jsptags.NavBar,navigation.config.file is 
/projects/svnVawter/src/com/vawter/vawter/config.xml
DEBUG,2005-01-08 00:31:10,com.vawter.jsptags.NavBar,configuration 
factory is org.apache.commons.configuration.CompositeConfiguration@1d144a4
DEBUG,2005-01-08 00:31:10,com.vawter.jsptags.NavBar,configuration is 
empty true

and finally here is the xml file
don@blackbox:/projects/svnVawter/src/com/vawter/vawter$ cat buttons.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<navigation>
<urlbase>/artisan/</urlbase>
<imagebase>images/</imagebase>
<buttons>
<button>
<name>Home</name>
<url></url>
<caption>Home</caption>
<image>home.png</image>
</button>
<button>
<name>Gallery></name>
<url>gallery.do</url>
<caption>Gallery</caption>
<image>gallery.png</image>
</button>
</buttons>
</navigation>






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


Re: [configuration] newbie ?, empty config

Posted by Don Vawter <do...@vawter.com>.
got it. I have it working with the indices notation. As I suspected I 
misunderstood what the "keys" were. Thanks

Oliver Heger wrote:

> The getKeys() method returns all keys that are assigned at least one 
> value. In your case keys like buttons.button.name or 
> buttons.button.url appear only once in the iteration, but they have 
> multiple values. The call config.getProperty("buttons.button.name") 
> would indeed return a collection with all names defined for buttons.
>
> With the syntax config.getString("buttons.button(0).name") you can 
> directly query the name of the first button. So you can use numeric 
> indices to specify which value you want, but those indices do not 
> appear in the results of getKeys().
>
> HTH
> Oliver

<snip>

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


Re: [configuration] newbie ?, empty config

Posted by Oliver Heger <Ol...@t-online.de>.
The getKeys() method returns all keys that are assigned at least one 
value. In your case keys like buttons.button.name or buttons.button.url 
appear only once in the iteration, but they have multiple values. The 
call config.getProperty("buttons.button.name") would indeed return a 
collection with all names defined for buttons.

With the syntax config.getString("buttons.button(0).name") you can 
directly query the name of the first button. So you can use numeric 
indices to specify which value you want, but those indices do not appear 
in the results of getKeys().

HTH
Oliver

Don Vawter wrote:

> <sigh> One should make sure they have the most current jar before they 
> start coding for that jar</sigh>
> In this particular project I had configuration 1 instead of 2
> When I substituted a properties file for the xml file everything 
> worked so I knew it was finding the files ok.
> I put the new jar (configuration 2)  and I getting closer.  Everything 
> except this:
>
> When I iterate through the keys with:
>
>            if(config instanceof CompositeConfiguration ){
>                    logger.debug("config is CompositeConfiguration");
>                    Iterator it = ((CompositeConfiguration) 
> config).getKeys();
>                    while(it!=null && it.hasNext()){
>                        logger.debug("Next key: " + it.next());
>                    }
>            }
> it shows the first six keys and stops
>
> DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,config is 
> CompositeConfiguration
> DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: imagebase
> DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: urlbase
> DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: 
> buttons.button.image
> DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: 
> buttons.button.url
> DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: 
> buttons.button.name
> DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: 
> buttons.button.caption <why does it stop here>
> DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,configuration 
> factory is org.apache.commons.configuration.CompositeConfiguration@80669d
> ....
>
> I can access the individual properties like I expect to. Perhaps I 
> just don't understand how the getKeys is supposed to work.
>
>
> Oliver Heger wrote:
>
>> Don,
>>
>> on a first glance I can see nothing wrong in your usage of the 
>> configuration API (besides the fact that you declare the config 
>> variable twice: once as static field and once as local variable).
>>
>> Which version of [configuration] do you use?
>>
>> Oh, and remember to prefix the subjects of your mails with the name 
>> of the affected component; otherwise they may be missed by developers.
>>
>> Oliver
>>
>> Don Vawter wrote:
>>
>>> I am making my first attempt to use the Configuration capabilities 
>>> and am obviously doing something wrong.
>>> The configuration object is not null but isEmpty() returns true.
>>>
>>> Any guidance would be greatly appreciated as I struggle up the 
>>> learning curve.
>>>
>>> TIA
>>>
>>>
>>> Here is my config.xml
>>>
>>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>> <configuration>
>>>  <hierarchicalXml 
>>> fileName="/projects/svnVawter/src/com/vawter/vawter/buttons.xml"/>
>>> </configuration>
>>>
>>> and here a code snippet:
>>>
>>>  private static final Logger logger = Logger.getLogger(NavBar.class);
>>>        private static  ConfigurationFactory factory=null;
>>>        private static URL configURL = null;
>>>        private static Configuration config=null;
>>>        static{
>>>                try{
>>>                        factory = new ConfigurationFactory();
>>>                        String navfile= 
>>> PropertyHandler.getProperty("navigation.config.file");
>>>                        logger.debug("navigation.config.file is " + 
>>> navfile);
>>>                        if(navfile!=null) {
>>>                            factory.setConfigurationFileName(navfile);
>>>                           Configuration config = 
>>> factory.getConfiguration();
>>>
>>>                         logger.debug("configuration factory is "+ 
>>> config);
>>>                        logger.debug("configuration is empty " + 
>>> config.isEmpty());
>>> .....
>>> and here is the logger:
>>>
>>> DEBUG,2005-01-08 
>>> 00:31:10,com.vawter.jsptags.NavBar,navigation.config.file is 
>>> /projects/svnVawter/src/com/vawter/vawter/config.xml
>>> DEBUG,2005-01-08 00:31:10,com.vawter.jsptags.NavBar,configuration 
>>> factory is 
>>> org.apache.commons.configuration.CompositeConfiguration@1d144a4
>>> DEBUG,2005-01-08 00:31:10,com.vawter.jsptags.NavBar,configuration is 
>>> empty true
>>>
>>> and finally here is the xml file
>>> don@blackbox:/projects/svnVawter/src/com/vawter/vawter$ cat buttons.xml
>>>
>>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>>> <navigation>
>>> <urlbase>/artisan/</urlbase>
>>> <imagebase>images/</imagebase>
>>> <buttons>
>>> <button>
>>> <name>Home</name>
>>> <url></url>
>>> <caption>Home</caption>
>>> <image>home.png</image>
>>> </button>
>>> <button>
>>> <name>Gallery></name>
>>> <url>gallery.do</url>
>>> <caption>Gallery</caption>
>>> <image>gallery.png</image>
>>> </button>
>>> </buttons>
>>> </navigation>
>>>
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


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


Re: [configuration] newbie ?, empty config

Posted by Don Vawter <do...@vawter.com>.
<sigh> One should make sure they have the most current jar before they 
start coding for that jar</sigh>
In this particular project I had configuration 1 instead of 2
When I substituted a properties file for the xml file everything worked 
so I knew it was finding the files ok.
I put the new jar (configuration 2)  and I getting closer.  Everything 
except this:

When I iterate through the keys with:

            if(config instanceof CompositeConfiguration ){
                    logger.debug("config is CompositeConfiguration");
                    Iterator it = ((CompositeConfiguration) 
config).getKeys();
                    while(it!=null && it.hasNext()){
                        logger.debug("Next key: " + it.next());
                    }
            }
it shows the first six keys and stops

DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,config is 
CompositeConfiguration
DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: imagebase
DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: urlbase
DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: 
buttons.button.image
DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: 
buttons.button.url
DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: 
buttons.button.name
DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,Next key: 
buttons.button.caption <why does it stop here>
DEBUG,2005-01-08 13:19:54,com.vawter.jsptags.NavBar,configuration 
factory is org.apache.commons.configuration.CompositeConfiguration@80669d
....

I can access the individual properties like I expect to. Perhaps I just 
don't understand how the getKeys is supposed to work.


Oliver Heger wrote:

> Don,
>
> on a first glance I can see nothing wrong in your usage of the 
> configuration API (besides the fact that you declare the config 
> variable twice: once as static field and once as local variable).
>
> Which version of [configuration] do you use?
>
> Oh, and remember to prefix the subjects of your mails with the name of 
> the affected component; otherwise they may be missed by developers.
>
> Oliver
>
> Don Vawter wrote:
>
>> I am making my first attempt to use the Configuration capabilities 
>> and am obviously doing something wrong.
>> The configuration object is not null but isEmpty() returns true.
>>
>> Any guidance would be greatly appreciated as I struggle up the 
>> learning curve.
>>
>> TIA
>>
>>
>> Here is my config.xml
>>
>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>> <configuration>
>>  <hierarchicalXml 
>> fileName="/projects/svnVawter/src/com/vawter/vawter/buttons.xml"/>
>> </configuration>
>>
>> and here a code snippet:
>>
>>  private static final Logger logger = Logger.getLogger(NavBar.class);
>>        private static  ConfigurationFactory factory=null;
>>        private static URL configURL = null;
>>        private static Configuration config=null;
>>        static{
>>                try{
>>                        factory = new ConfigurationFactory();
>>                        String navfile= 
>> PropertyHandler.getProperty("navigation.config.file");
>>                        logger.debug("navigation.config.file is " + 
>> navfile);
>>                        if(navfile!=null) {
>>                            factory.setConfigurationFileName(navfile);
>>                           Configuration config = 
>> factory.getConfiguration();
>>
>>                         logger.debug("configuration factory is "+ 
>> config);
>>                        logger.debug("configuration is empty " + 
>> config.isEmpty());
>> .....
>> and here is the logger:
>>
>> DEBUG,2005-01-08 
>> 00:31:10,com.vawter.jsptags.NavBar,navigation.config.file is 
>> /projects/svnVawter/src/com/vawter/vawter/config.xml
>> DEBUG,2005-01-08 00:31:10,com.vawter.jsptags.NavBar,configuration 
>> factory is 
>> org.apache.commons.configuration.CompositeConfiguration@1d144a4
>> DEBUG,2005-01-08 00:31:10,com.vawter.jsptags.NavBar,configuration is 
>> empty true
>>
>> and finally here is the xml file
>> don@blackbox:/projects/svnVawter/src/com/vawter/vawter$ cat buttons.xml
>>
>> <?xml version="1.0" encoding="ISO-8859-1" ?>
>> <navigation>
>> <urlbase>/artisan/</urlbase>
>> <imagebase>images/</imagebase>
>> <buttons>
>> <button>
>> <name>Home</name>
>> <url></url>
>> <caption>Home</caption>
>> <image>home.png</image>
>> </button>
>> <button>
>> <name>Gallery></name>
>> <url>gallery.do</url>
>> <caption>Gallery</caption>
>> <image>gallery.png</image>
>> </button>
>> </buttons>
>> </navigation>
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


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


Re:[configuration] newbie ?, empty config

Posted by Oliver Heger <Ol...@t-online.de>.
Don,

on a first glance I can see nothing wrong in your usage of the 
configuration API (besides the fact that you declare the config variable 
twice: once as static field and once as local variable).

Which version of [configuration] do you use?

Oh, and remember to prefix the subjects of your mails with the name of 
the affected component; otherwise they may be missed by developers.

Oliver

Don Vawter wrote:

> I am making my first attempt to use the Configuration capabilities and 
> am obviously doing something wrong.
> The configuration object is not null but isEmpty() returns true.
>
> Any guidance would be greatly appreciated as I struggle up the 
> learning curve.
>
> TIA
>
>
> Here is my config.xml
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <configuration>
>  <hierarchicalXml 
> fileName="/projects/svnVawter/src/com/vawter/vawter/buttons.xml"/>
> </configuration>
>
> and here a code snippet:
>
>  private static final Logger logger = Logger.getLogger(NavBar.class);
>        private static  ConfigurationFactory factory=null;
>        private static URL configURL = null;
>        private static Configuration config=null;
>        static{
>                try{
>                        factory = new ConfigurationFactory();
>                        String navfile= 
> PropertyHandler.getProperty("navigation.config.file");
>                        logger.debug("navigation.config.file is " + 
> navfile);
>                        if(navfile!=null) {
>                            factory.setConfigurationFileName(navfile);
>                           Configuration config = 
> factory.getConfiguration();
>
>                         logger.debug("configuration factory is "+ 
> config);
>                        logger.debug("configuration is empty " + 
> config.isEmpty());
> .....
> and here is the logger:
>
> DEBUG,2005-01-08 
> 00:31:10,com.vawter.jsptags.NavBar,navigation.config.file is 
> /projects/svnVawter/src/com/vawter/vawter/config.xml
> DEBUG,2005-01-08 00:31:10,com.vawter.jsptags.NavBar,configuration 
> factory is 
> org.apache.commons.configuration.CompositeConfiguration@1d144a4
> DEBUG,2005-01-08 00:31:10,com.vawter.jsptags.NavBar,configuration is 
> empty true
>
> and finally here is the xml file
> don@blackbox:/projects/svnVawter/src/com/vawter/vawter$ cat buttons.xml
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <navigation>
> <urlbase>/artisan/</urlbase>
> <imagebase>images/</imagebase>
> <buttons>
> <button>
> <name>Home</name>
> <url></url>
> <caption>Home</caption>
> <image>home.png</image>
> </button>
> <button>
> <name>Gallery></name>
> <url>gallery.do</url>
> <caption>Gallery</caption>
> <image>gallery.png</image>
> </button>
> </buttons>
> </navigation>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


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