Using LdapTemplate in Spring LDAP, I have this code:
Object object=null;
try{
String dn = "cn=readers,ou=groups,dc=mycompany, dc=com";
object = this.ldapTemplate.lookup(dn);
} catch(final NameNotFoundException e){
// create Object
}
But since I've read my Joshua Bloch I know that exceptions should not be used for control flow. Is there a way to look up a dn to see if it exists without throwing an exception if it doesn't? There must be, but I can't find it. I'm looking for code that works like this (or similar):
String dn = "cn=readers,ou=groups,dc=mycompany, dc=com";
Object object=this.ldapTemplate.someMethod(dn);
if(object==null){
// create Object
}
Can anybody help?
BTW: just looking at the JavaDoc won't help. None of the methods that throw NameNotFoundException
say so in the JavaDocs.