When you get an entry object, chances are you want to handle attribute
values as objects. The OpenDJ LDAP SDK provides the
Entry.parseAttribute() method and an
AttributeParser with methods for a variety of attribute
value types. You can use these methods to get attribute values as
objects.
// Use Kirsten Vaughan's credentials and her entry.
String name = "uid=kvaughan,ou=People,dc=example,dc=com";
char[] password = "bribery".toCharArray();
connection.bind(name, password);
// Make sure we have a timestamp to play with.
updateEntry(connection, name, "description");
// Read Kirsten's entry.
final SearchResultEntry entry = connection.readEntry(name,
"cn", "objectClass", "hasSubordinates", "numSubordinates",
"isMemberOf", "modifyTimestamp");
// Get the entry DN and some attribute values as objects.
DN dn = entry.getName();
Set<String> cn = entry.parseAttribute("cn").asSetOfString("");
Set<AttributeDescription> objectClasses =
entry.parseAttribute("objectClass").asSetOfAttributeDescription();
boolean hasChildren = entry.parseAttribute("hasSubordinates").asBoolean();
int numChildren = entry.parseAttribute("numSubordinates").asInteger(0);
Set<DN> groups = entry
.parseAttribute("isMemberOf")
.usingSchema(Schema.getDefaultSchema()).asSetOfDN();
Calendar timestamp = entry
.parseAttribute("modifyTimestamp")
.asGeneralizedTime().toCalendar();
// Do something with the objects.
// ...
For a complete example in context, see ParseAttributes.java, one of the OpenDJ LDAP SDK examples.

