You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "DECOKER, Lydie (Lydie)" <de...@alcatel-lucent.com> on 2007/05/03 14:26:07 UTC
getProperty method for XMLConfiguration - Bug?
Hello,
I just started to use common configuration package today (version 1.4).
I am using it to read an XML configuration files. Looking the user
documentation, I used the getProperty method to read the below section
from XML:
<IncomingGateways>
<IncomingGateway>
<QueueName QueueType="Queue">QueueName3</QueueName>
<ConnectionFactory>myConnectionFactory</ConnectionFactory>
</IncomingGateway>
<IncomingGateway>
<QueueName QueueType="Queue">QueueName4</QueueName>
<ConnectionFactory>myConnectionFactory</ConnectionFactory>
</IncomingGateway>
</IncomingGateways>
As I do not know the number of IncomingGateway elements, it helps a lot.
But if I only have one IncomingGateway element, it does not work.
The way I did it is as follows:
Object prop = config.getProperty(key);
if (prop instanceof Collection) {
// Get the number of gateways to be defined
int nbGateway = ((Collection)prop).size();
System.out.println("Number of gateway: " + nbGateway);
.....
}
Did I miss something?
Regards,
Lydie
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: getProperty method for XMLConfiguration - Bug?
Posted by Oliver Heger <ol...@oliver-heger.de>.
DECOKER, Lydie (Lydie) wrote:
> Should not the getProperty works with one or more elements?
>
> Lydie
getProperty() simply returns the raw value of the queried property
without doing any conversion. If the property has multiple values, a
collection with all these values is returned; if there is only one
value, this single value object will be the result.
So your condition if(prop instanceof Collection) won't work in this
case. getList() however will always return a list. If there is only a
single value, a list with one element will be created.
HTH
Oliver
>
> -----Original Message-----
> From: Emmanuel Bourg [mailto:ebourg@apache.org]
> Sent: Thursday, May 03, 2007 17:37
> To: Jakarta Commons Users List
> Subject: Re: getProperty method for XMLConfiguration - Bug?
>
> Hi,
>
> Did you try with the getList() method instead ?
>
> Emmanuel Bourg
>
>
> DECOKER, Lydie (Lydie) a écrit :
>> Hello,
>>
>> I just started to use common configuration package today (version 1.4).
>> I am using it to read an XML configuration files. Looking the user
>> documentation, I used the getProperty method to read the below section
>> from XML:
>>
>> <IncomingGateways>
>> <IncomingGateway>
>> <QueueName QueueType="Queue">QueueName3</QueueName>
>>
>> <ConnectionFactory>myConnectionFactory</ConnectionFactory>
>> </IncomingGateway>
>> <IncomingGateway>
>> <QueueName QueueType="Queue">QueueName4</QueueName>
>>
>> <ConnectionFactory>myConnectionFactory</ConnectionFactory>
>> </IncomingGateway>
>> </IncomingGateways>
>>
>> As I do not know the number of IncomingGateway elements, it helps a lot.
>> But if I only have one IncomingGateway element, it does not work.
>>
>> The way I did it is as follows:
>>
>> Object prop = config.getProperty(key); if (prop instanceof Collection)
>> {
>> // Get the number of gateways to be defined
>> int nbGateway = ((Collection)prop).size();
>> System.out.println("Number of gateway: " + nbGateway); .....
>> }
>>
>> Did I miss something?
>>
>> Regards,
>>
>> Lydie
>>
>> ---------------------------------------------------------------------
>> 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: getProperty method for XMLConfiguration - Bug?
Posted by "DECOKER, Lydie (Lydie)" <de...@alcatel-lucent.com>.
Should not the getProperty works with one or more elements?
Lydie
-----Original Message-----
From: Emmanuel Bourg [mailto:ebourg@apache.org]
Sent: Thursday, May 03, 2007 17:37
To: Jakarta Commons Users List
Subject: Re: getProperty method for XMLConfiguration - Bug?
Hi,
Did you try with the getList() method instead ?
Emmanuel Bourg
DECOKER, Lydie (Lydie) a écrit :
> Hello,
>
> I just started to use common configuration package today (version 1.4).
> I am using it to read an XML configuration files. Looking the user
> documentation, I used the getProperty method to read the below section
> from XML:
>
> <IncomingGateways>
> <IncomingGateway>
> <QueueName QueueType="Queue">QueueName3</QueueName>
>
> <ConnectionFactory>myConnectionFactory</ConnectionFactory>
> </IncomingGateway>
> <IncomingGateway>
> <QueueName QueueType="Queue">QueueName4</QueueName>
>
> <ConnectionFactory>myConnectionFactory</ConnectionFactory>
> </IncomingGateway>
> </IncomingGateways>
>
> As I do not know the number of IncomingGateway elements, it helps a lot.
> But if I only have one IncomingGateway element, it does not work.
>
> The way I did it is as follows:
>
> Object prop = config.getProperty(key); if (prop instanceof Collection)
> {
> // Get the number of gateways to be defined
> int nbGateway = ((Collection)prop).size();
> System.out.println("Number of gateway: " + nbGateway); .....
> }
>
> Did I miss something?
>
> Regards,
>
> Lydie
>
> ---------------------------------------------------------------------
> 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: getProperty method for XMLConfiguration - Bug?
Posted by Emmanuel Bourg <eb...@apache.org>.
Hi,
Did you try with the getList() method instead ?
Emmanuel Bourg
DECOKER, Lydie (Lydie) a écrit :
> Hello,
>
> I just started to use common configuration package today (version 1.4).
> I am using it to read an XML configuration files. Looking the user
> documentation, I used the getProperty method to read the below section
> from XML:
>
> <IncomingGateways>
> <IncomingGateway>
> <QueueName QueueType="Queue">QueueName3</QueueName>
>
> <ConnectionFactory>myConnectionFactory</ConnectionFactory>
> </IncomingGateway>
> <IncomingGateway>
> <QueueName QueueType="Queue">QueueName4</QueueName>
>
> <ConnectionFactory>myConnectionFactory</ConnectionFactory>
> </IncomingGateway>
> </IncomingGateways>
>
> As I do not know the number of IncomingGateway elements, it helps a lot.
> But if I only have one IncomingGateway element, it does not work.
>
> The way I did it is as follows:
>
> Object prop = config.getProperty(key);
> if (prop instanceof Collection) {
> // Get the number of gateways to be defined
> int nbGateway = ((Collection)prop).size();
> System.out.println("Number of gateway: " + nbGateway);
> .....
> }
>
> Did I miss something?
>
> Regards,
>
> Lydie
>
> ---------------------------------------------------------------------
> 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