Saturday, March 29, 2008

LDAP EOF Adaptor

A word of warning if you're working with LDAP/JNDI and creating EOModels on them. LDAP supports multi-value attributes, which means you could have, for instance, multiple "uid"'s (Apple provides for multiple "short names", for instance). In your EOModel, you should be careful about how you define the types of these values. If there is one value, it will return a String. If there are multiple values, it will return an NSArray, so you should declare the value type to be "java.lang.Object" and check for what you're getting back when you call the method.

1 comment:

Lionel said...

About LDAP an WO, I use it a lot. Here is how I work with multi-valued attributes.


public NSArray objectClass() {
Object o = storedValueForKey("objectClass");
if (o instanceof NSArray)
return (NSArray)o;
else if (o instanceof String)
return new NSArray ((String)o);
return NSArray.EmptyArray;
}

public void setObjectClass(NSArray value) {
takeStoredValueForKey(value, "objectClass");
}

public void awakeFromInsertion(EOEditingContext ec) {
super.awakeFromInsertion(ec);
logger.debug ("awakeFromInsertion "+this.uid());
NSArray objectClass = new NSArray (new String[] {"top", "person", "organizationalPerson", "inetOrgPerson"});
setObjectClass(objectClass);
}