commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kfir Shay <kfir.s...@gmail.com>
Subject Re: Configuration
Date Tue, 17 Jan 2006 19:50:48 GMT
Hi Borut,

take another look at the java doc for CompositeConfiguration
http://jakarta.apache.org/commons/configuration/apidocs/org/apache/commons/configuration/CompositeConfiguration.html

The method getConfiguration only take int argument so your example line -
CompositeConfiguration config = getConfiguration("configuration.xml");
simply won't work.

Also even if I create a CompositeConfiguration object manually using the
getConfiguration method will return a Configuration object which means that
doing something like this (this is your example)
XMLPropertiesConfiguration xc = (XMLPropertiesConfiguration)
config.getConfiguration(2);
will throw a class cast exception.


I am not trying to pick or anything but it seems like what you told me
doesn't work.

Thanks,
Kfir S.


On 1/17/06, Borut Bolčina <bob@najdi.si> wrote:
>
> Hello,
>
> if you want to have access to several configuration files from one place,
> then you should use
> CompositeConfiguration config = getConfiguration("configuration.xml");
>
> In configuration.xml you enumerate the config files you intend to use
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <configuration>
>   <properties fileName="Some.properties"/>
>   <properties fileName="Another.properties"/>
>   <xml filename="YetAnotherProperties.xml"/>
> </configuration>
>
> In the above case you can access values in all three property files
> through the same method calls, like
> valueOfTypeLong = config.getLong("someKey", 300000);
> valueOfTypeString = config.getString("anotherKey", "default value if this
> key not present");
>
> If you want values from XML configuration file (YetAnotherProperties.xml)
> then you (for example):
> List<String> keywords = config.getList("blogs.keyword");
>
> You will get a collection of all values (value1, anotherValue) if XML
> config looks like
> <feeds>
>     <news>
>         <keyword>http://www.aaa.com/feeds/12.xml</keyword>
>         <keyword>http://www.bbb.com/feeds/16.xml</keyword>
>         <keyword>http://www.ccc.com/feeds/18.xml</keyword>
>     </news>
>     <blogs>
>         <keyword>value1</keyword>
>         <keyword>anotherValue</keyword>
>     </blogs>
> </feeds>
>
> Now, if you want an explicit configuration out of CompositeConfiguration
> then you can by
> PropertiesConfiguration pc = (PropertiesConfiguration)
> config.getConfiguration(0);
> or
> XMLPropertiesConfiguration xc = (XMLPropertiesConfiguration)
> config.getConfiguration(2);
> if using the above configuration.xml file.
>
> Hope this helps,
> Borut
>
> On 17.1.2006 5:26, Kfir Shay wrote:
>
> Hi,
>
> I am a bit confused about the documentation inconsistencies in the commons
> configuration package.
>
> In the "ConfigurationFactory Howto" document in the section called "The
> configuration definition file" it is stated that the xml element creates an
> instance of XMLConfiguration:
> "The xml element can be used to load XML configuration files. It also uses
> the fileName attribute to determine the name of the file to load and creates
> an instance of XMLConfiguration."  Yet earlier in the "Accessing properties"
> section it is stated that ConfigurationFactory only return a configuration
> object via the getConfiguration()  method: "Whatever way we used to load the
> configuration factory, we should now have a Configuration object that was
> returned by the factory's getConfiguration()  method. This object is
> actually an instance of the CompositeConfiguration class"
>
> c\Currently my configuration consist of only one xml file but I want to use
> the ConfigurationFactory and leverage the config.xml file for the case that
> more configuration files will be added in the future (most probably all will
> be in xml format) but at the same time I need to get a XMLConfiguration
> object not the more general Configuration object can someone please clarify
> how to achieve this.
>
> This is my first post to the list, I hope some of you will take the time to
> give me an answer.
>
> Thanks,
> Kfir S.
> AIM:kingink24
> Email: kfir.shay@gmail.com
>
>
> --
> [image: bLOG] <http://www.delo.si/blog/borutb/>
> --
> Naključna *izjava tedna* iz tednika Mladina:
>
Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message