You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Syed Mudassir <sy...@gaiatv.in> on 2015/03/04 13:31:17 UTC

Read Attribute with Multiple Values

Hi.
   I am using apache directory api in my java program to interact with 
ldap server.
   Upon performing successful search,  I am able to get the Entry object.
   But the Entry object has a method getAttributes() which will return a 
collection of Attribute.
   If an Attribute contains multiple values, how can I fetch all those 
values?
   Presently, I see only method get() which will fetch just the first value.
-- 

Re: Read Attribute with Multiple Values

Posted by Syed Mudassir <sy...@gaiatv.in>.
I found the solution.  Invoking the iterator() on Attribute gives all 
the values.

On Wednesday 04 March 2015 06:01 PM, Syed Mudassir wrote:
> Hi.
>   I am using apache directory api in my java program to interact with 
> ldap server.
>   Upon performing successful search,  I am able to get the Entry object.
>   But the Entry object has a method getAttributes() which will return 
> a collection of Attribute.
>   If an Attribute contains multiple values, how can I fetch all those 
> values?
>   Presently, I see only method get() which will fetch just the first 
> value.
> -- 


Re: Read Attribute with Multiple Values

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 04/03/15 13:31, Syed Mudassir a écrit :
> Hi.
>    I am using apache directory api in my java program to interact with ldap server.
>    Upon performing successful search,  I am able to get the Entry object.
>    But the Entry object has a method getAttributes() which will return a 
> collection of Attribute.
>    If an Attribute contains multiple values, how can I fetch all those values?
>    Presently, I see only method get() which will fetch just the first value.
> -- 
You have to use the iterator(). The best way to do that is :

Attribute myAttribute = entry.get( "MyAttribute" );

for ( Value<?> value : myAttribute )
{
    // do what you need to do with your value
}

or :

Iterator<Value<?>> iterator = myAttribute.iterator();

while ( iterator.hasNext() )
{
    Value<?> value = iterator.next();
    // ...
}

which is a bit more verbose.