You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ri...@atradius.com on 2006/03/28 12:23:40 UTC

Commons configuration: Filename and namespace.

Hi All,

 

Question on commons configuration. I have asked this before as part of
another thread...but afraid the question will get lost... so do excuse.

 

One thing I wanted to add to my wish list for commons config is to have the
concept of using a file name as a namespace.

 

For instance if I were to use ConfigurationFactory and I wanted to retrieve
all the configuration information from a particular configuration file
(.xml, .properties etc), there is nothing directly supported (pls correct me
if I am wrong). 

 

I am currently loading individual files to get information from a specific
file... not very elegant. What I would like is to have filenames being
stored as a namespace (of sorts), it would allow us to - 

 

-----------------

Configuration config = configFactory.getConfiguration();

Configuration fileXConfig = config.getConfiguration(fileXName); // loads the
config info stored in file X only.

-----------------

 

Does this go against the philosophy of the ConfigurationFactory?? I have
tried to reason it out and I don't think it does...

 

Any ideas or thoughts?

 

Thanks folks!

 

Rishi

 

 

 

 

 



------------------------------------------------------------------------------------------------------------
This message is intended for the addressee or its representative only. 
Any form of unauthorized use, publication, reproduction, copying or 
disclosure of the content of this e-mail is not permitted. If you are 
not the intended recipient of this e-mail message and its contents, 
please notify the sender immediately and delete this message and 
all its attachments subsequently.


Re: Commons configuration: Filename and namespace.

Posted by Oliver Heger <he...@med.uni-marburg.de>.
Rishikesh.Mallesh@atradius.com wrote:
> Hi All,
> 
>  
> 
> Question on commons configuration. I have asked this before as part of
> another thread...but afraid the question will get lost... so do excuse.
> 
>  
> 
> One thing I wanted to add to my wish list for commons config is to have the
> concept of using a file name as a namespace.
> 
>  
> 
> For instance if I were to use ConfigurationFactory and I wanted to retrieve
> all the configuration information from a particular configuration file
> (.xml, .properties etc), there is nothing directly supported (pls correct me
> if I am wrong). 
> 
>  
> 
> I am currently loading individual files to get information from a specific
> file... not very elegant. What I would like is to have filenames being
> stored as a namespace (of sorts), it would allow us to - 
> 
>  
> 
> -----------------
> 
> Configuration config = configFactory.getConfiguration();
> 
> Configuration fileXConfig = config.getConfiguration(fileXName); // loads the
> config info stored in file X only.
> 
> -----------------
> 
>  
> 
> Does this go against the philosophy of the ConfigurationFactory?? I have
> tried to reason it out and I don't think it does...
> 
>  
> 
> Any ideas or thoughts?
> 
>  
> 
> Thanks folks!
> 
>  
> 
> Rishi
> 

The Configuration object returned by ConfigurationFactory can be casted 
to a CompositeConfiguration. This class allows you to access the 
contained configurations based on a numeric index.

You could do something like that:

CompositeConfiguration cc = (CompositeConfiguration) 
factory.getConfiguration();
Configuration configXML = cc.getConfiguration(0);

The configurations are in the order as they were declared in the 
configuration definition file for the factory.

As a future enhancement it is planed to support names for 
configurations. So you could write something like the following in the 
configuration definition file:

<configuration>
   <properties id="myMprops" fileName="..."/>
   <xml id="myXml" fileName="..."/>
</configuration>

and then ask the CompositeConfiguration for a contained configuration by 
name:

Configuration myProps = cc.getConfiguration("myProps");

Oliver

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