Click to See Complete Forum and Search --> : Help With LDAP Update


jhomme
September 25th, 2000, 10:29 AM
Hi,
By this time, I am extremely frustrated and stumpped why this code is not working. My goal is to change the givenname attribute's value from Mark to Jim. Here is what I know about the attributes that may be of some value:

The attribute has one element. It is not ordered. When I do a search on it, the givenname definitely has Mark as it's value. I know from the documentation about the set method that it can return without any action performed. That is what is going on here. How can I make this work properly?

Thank you very much in advance.

Jim

public boolean setAttributeValue(
String oU,
String uid,
String attribute,
int index,
String oldValue,
String newValue)
throws IndexOutOfBoundsException, IllegalStateException,
NamingException
{
String[] whichAttributes = {attribute};
Object o = new Object();
try {
NamingEnumeration results = doSearch(
oU,
attribute,
oldValue,
whichAttributes);
if (!results.hasMore()) {
System.out.println("Failed first test.");
return false;
}
SearchResult si = (SearchResult)results.next();
Attributes attrs = si.getAttributes();
NamingEnumeration ae = attrs.getAll();
if (!ae.hasMore()) {
System.out.println("Failed second test.");
return false;
}
Attribute attr = (Attribute)ae.next();

o = attr.set(index, newValue);
System.out.println(o.toString());

return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}

}