DECAFFMEYER MATHIEU wrote:
[3/20/07 10:41:15:811 CET] 7aa91043 WebGroup      E SRVE0026E: [Servlet
Error]-[Controller]: java.lang.ClassCastException:
org.apache.commons.configuration.HierarchicalConfiguration


conf = factory.getConfiguration();
compconf = (CompositeConfiguration) conf;
xmlConf = (XMLConfiguration) compconf.getConfiguration(0);

Trying to follow your tips but now I have this class cast exception,
my factory looks like this :

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
        <additional>
                <xml fileName="ress/ApplicationConfig.xml"/>
        </additional>
</configuration>

__________________________________

   Math

ConfigurationFactory takes all configurations defined in an <additional> section and combines them to a single HierarchicalConfiguration. This is the reason for your ClassCastException. If you remove the <additional> tags and define the XMLConfiguration in the top level, you should be able to access it in the described way.

Alternatively you can give the DefaultConfigurationBuilder (introduced with Configuration 1.3) a try. This class provides a slightly richer API. It is fully described in the user guide.

Oliver


-----Original Message-----
From: Oliver Heger [mailto:[EMAIL PROTECTED] Sent: Monday, March 19, 2007 9:47 PM
To: Jakarta Commons Users List
Subject: Re: get an XMLConfig. from ConfigurationFactory

*****  This message comes from the Internet Network *****

DECAFFMEYER MATHIEU wrote:
Hi,

I am using this snippet of code to get dynamically the configuration settings of my app. :

URL url =
        Thread.currentThread().getContextClassLoader().getResource(
                "ress/config.xml");
ConfigurationFactory factory =* **new* ConfigurationFactory();
factory.setConfigurationURL(url);
Configuration conf =* null*;
*try* {
        conf = factory.getConfiguration();
}* catch* (ConfigurationException e) {
        e.printStackTrace();
}


The problem here is that I am trying to get an XMLConfiguration and
not
a Configuraton object,
to do operations on the configuration file itself (change the
settings),
which is an XML file.

any tips on how to get an XMLConfiguration from a the ConfigurationFactory ?

Thank u !

*__________________________________*

*   Matt*////

You can cast the Configuration object you obtain from the factory to a CompositeConfiguration. This class provides the getConfiguration(int index) method, which gives you access to the child configurations. The XMLConfiguration you have loaded using the factory will be one of those.

HTH
Oliver


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



============================================
Internet communications are not secure and therefore Fortis Banque Luxembourg 
S.A. does not accept legal responsibility for the contents of this message. The 
information contained in this e-mail is confidential and may be legally 
privileged. It is intended solely for the addressee. If you are not the 
intended recipient, any disclosure, copying, distribution or any action taken 
or omitted to be taken in reliance on it, is prohibited and may be unlawful. 
Nothing in the message is capable or intended to create any legally binding 
obligations on either party and it is not intended to provide legal advice.
============================================


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to