You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Lesaint Sébastien <le...@ginerativ.com> on 2005/04/06 10:43:41 UTC

[Configuration] CompositeConfiguration.getNumberOfConfigurations( ) question

Hello,

 

I'm using a CompositeConfiguration instance and I add two configurations to
it in my program.

I'm quite surprised to see that method
CompositeConfiguration.getNumberOfConfigurations() returns 3.

I guess the method counts the in memory configuration.

 

Do you think it is relevant to take the in memory configuration into
account?

If so, I guess it should be documented, isn't it? (it is not the case at the
moment)

 

Regards,

 

Seb' (who is sincerely graceful to all people involved in Jakarta commons
since it saved him lots of work)


Re: [Configuration] save() not working?

Posted by Jamie Guillemette <JM...@hotmail.com>.
The display is :

file:/C:/Documents%20and%20Settings/JMGuillemette/My%20Documents/Workspace/Config/ConfigDemo/bin/sample.properties

jamie


The file it self is not in a jar.. but it might be at distribution time... 
hence why i was perfering to use URL for referencing the file.


----- Original Message ----- 
From: "Emmanuel Bourg" <eb...@apache.org>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Wednesday, April 06, 2005 1:30 PM
Subject: Re: [Configuration] save() not working?


> Where is located the sample.properties file ? Inside a JAR ? Could you 
> show us the URL displayed by System.out.println(url) ?
>
> Emmanuel Bourg
>
>
> Jamie Guillemette wrote:
>> In follow up to my message of this morning here is some sample code.
>>
>> [code]
>>
>> /*
>> * Created on Apr 6, 2005
>> */
>> package com.wirednorth.configdemo;
>> import java.net.URL;
>>
>> import org.apache.commons.configuration.Configuration;
>> import org.apache.commons.configuration.ConfigurationException;
>> import org.apache.commons.configuration.PropertiesConfiguration;
>>
>> /**
>> * @author JMGuillemette
>> */
>> public class ConfigDemo {
>>
>> public ConfigDemo(){
>>
>> }
>>
>> public void runDemo()throws ConfigurationException{
>>  URL url = this.getClass().getResource("/sample.properties");
>>  System.out.println(url);
>>  PropertiesConfiguration config = new PropertiesConfiguration(url);
>>  String firstName = config.getString("name.first");
>>  System.out.println(firstName);
>>  config.setProperty("name.first","newName");
>>  config.save();
>> }
>>
>> public static void main(String[] args)throws Exception{
>>  ConfigDemo demo = new ConfigDemo();
>>  demo.runDemo();
>>
>> }
>>
>>
>>
>> }
>> [/code]
>>
>> the properties files it self looks like this...
>>
>> [file]
>> name.first = jamie
>>
>> name.last = guillemette
>>
>> city = london
>>
>> prov = ontario
>>
>> [/file]
>>
>> if you run this code.. you would expect the first run through to product 
>> "jamie"on the console.. and the next one to produce "newName"... instead 
>> what i get is "jamie" every time.
>>
>> Thanks again for all you help everyone :)
>>
>>
>>
>> J.
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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] save() not working?

Posted by Emmanuel Bourg <eb...@apache.org>.
Where is located the sample.properties file ? Inside a JAR ? Could you 
show us the URL displayed by System.out.println(url) ?

Emmanuel Bourg


Jamie Guillemette wrote:
> In follow up to my message of this morning here is some sample code.
> 
> [code]
> 
> /*
> * Created on Apr 6, 2005
> */
> package com.wirednorth.configdemo;
> import java.net.URL;
> 
> import org.apache.commons.configuration.Configuration;
> import org.apache.commons.configuration.ConfigurationException;
> import org.apache.commons.configuration.PropertiesConfiguration;
> 
> /**
> * @author JMGuillemette
> */
> public class ConfigDemo {
> 
> public ConfigDemo(){
> 
> }
> 
> public void runDemo()throws ConfigurationException{
>  URL url = this.getClass().getResource("/sample.properties");
>  System.out.println(url);
>  PropertiesConfiguration config = new PropertiesConfiguration(url);
>  String firstName = config.getString("name.first");
>  System.out.println(firstName);
>  config.setProperty("name.first","newName");
>  config.save();
> }
> 
> public static void main(String[] args)throws Exception{
>  ConfigDemo demo = new ConfigDemo();
>  demo.runDemo();
> 
> }
> 
> 
> 
> }
> [/code]
> 
> the properties files it self looks like this...
> 
> [file]
> name.first = jamie
> 
> name.last = guillemette
> 
> city = london
> 
> prov = ontario
> 
> [/file]
> 
> if you run this code.. you would expect the first run through to product 
> "jamie"on the console.. and the next one to produce "newName"... instead 
> what i get is "jamie" every time.
> 
> Thanks again for all you help everyone :)
> 
> 
> 
> J.
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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


[Configuration] save() not working?

Posted by Jamie Guillemette <JM...@hotmail.com>.
In follow up to my message of this morning here is some sample code.

[code]

/*
 * Created on Apr 6, 2005
 */
package com.wirednorth.configdemo;
import java.net.URL;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * @author JMGuillemette
 */
public class ConfigDemo {

 public ConfigDemo(){

 }

 public void runDemo()throws ConfigurationException{
  URL url = this.getClass().getResource("/sample.properties");
  System.out.println(url);
  PropertiesConfiguration config = new PropertiesConfiguration(url);
  String firstName = config.getString("name.first");
  System.out.println(firstName);
  config.setProperty("name.first","newName");
  config.save();
 }

 public static void main(String[] args)throws Exception{
  ConfigDemo demo = new ConfigDemo();
  demo.runDemo();

 }



}
[/code]

the properties files it self looks like this...

[file]
name.first = jamie

name.last = guillemette

city = london

prov = ontario

[/file]

if you run this code.. you would expect the first run through to product 
"jamie"on the console.. and the next one to produce "newName"... instead 
what i get is "jamie" every time.

Thanks again for all you help everyone :)



J.





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


Re: [Configuration] CompositeConfiguration.getNumberOfConfigurations( ) question

Posted by Eric Pugh <ep...@opensourceconnections.com>.
Thats a good point..  However, sometimes you actually want to get back 
the memory configuration...   although, I guess that is mostly in the 
unit tests when you want to do whitebox testing..  From an external 
perspective, it does make sense that you would get back 2 
configurations only!

Eric

On Apr 6, 2005, at 4:43 AM, Lesaint Sébastien wrote:

> Hello,
>
>
>
> I'm using a CompositeConfiguration instance and I add two 
> configurations to
> it in my program.
>
> I'm quite surprised to see that method
> CompositeConfiguration.getNumberOfConfigurations() returns 3.
>
> I guess the method counts the in memory configuration.
>
>
>
> Do you think it is relevant to take the in memory configuration into
> account?
>
> If so, I guess it should be documented, isn't it? (it is not the case 
> at the
> moment)
>
>
>
> Regards,
>
>
>
> Seb' (who is sincerely graceful to all people involved in Jakarta 
> commons
> since it saved him lots of work)
>


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