Novell is now a part of Micro Focus

I am trying to query two attributes from...

Articles and Tips: qna

01 Sep 2003


Q.

I am trying to query two attributes from an LDAP query: (1) a cn, and (2) a network address. I understand that the networkAddress attribute is returned as an array reference. However, the following code won't let me treat this apparent array(attrib) as anything but a string (see the error below):

java.lang.ClassCastException: java.lang.String

//code used
for (NamingEnumeration enum =
   attrs.getAll(); enum.hasMore();) {
Attribute attrib =
   (Attribute)enum.next();

if(attrib.getID().equalsIgnoreCase("networkAddress") )
   {
   Object thisAddress=attrib.get();

//fails here
   Vector vO=(Vector)thisAddress;
   }

How can I get at elements of something which will only be treated as a string?

A.

Your modified code will look as follows:

if(attrib.getID().equalsIgnoreCase("networkAddress") )
{
NamingEnumeration ne = attrib.getAll();

while(ne.hasMore())
String attribVal = (String) ne.next();

}

* Originally published in Novell AppNotes


Disclaimer

The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.

© Copyright Micro Focus or one of its affiliates