From 5b6ba8527ed94f0d8875c723f20b70baa8f32d00 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Fri, 30 Mar 2007 11:41:14 +0000 Subject: [PATCH] LDAP-47: Code example in section 4.1 of the documentation is incorrect --- spring-ldap/docs/reference/src/executors.xml | 33 ++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/spring-ldap/docs/reference/src/executors.xml b/spring-ldap/docs/reference/src/executors.xml index 0bb3c46d..cadc78e8 100644 --- a/spring-ldap/docs/reference/src/executors.xml +++ b/spring-ldap/docs/reference/src/executors.xml @@ -9,13 +9,16 @@ versions of the most common operations in DirContext, we have not provided an alternative for each and every method signature, mostly because there are so many of them. We have, however, provided a - means to call whichever overloaded method you want. Let's say, for - example, that you want to use the following method: + means to call whichever DirContext method you want + and still get the benefits that LdapTemplate provides. + + Let's say that you want to call the following DirContext + method: NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls ctls) - The way to do this is to use a custom - SearchExecutor implementation: + There is no corresponding overloaded method in LdapTemplate. The way to solve + this is to use a custom SearchExecutor implementation: public interface SearchExecutor { @@ -23,6 +26,16 @@ } + In your custom executor, you have access to a DirContext + object, which you use to call the method you want. You then provide a handler + that is responsible for mapping attributes and collecting the results. You can + for example use one of the available implementations of + CollectingNameClassPairCallbackHandler, which will collect + the mapped results in an internal list. In order to + actually execute the search, you call the search + method in LdapTemplate that takes an executor and a handler as arguments. Finally, + you return whatever your handler has collected. + A custom search method using SearchExecutor and AttributesMapper @@ -39,10 +52,11 @@ public class PersonDaoImpl implements PersonDao { } }; - NameClassPairCallbackHandler handler = + CollectingNameClassPairCallbackHandler handler = new AttributesMapperCallbackHandler(new PersonAttributesMapper()); - return ldapTemplate.search(executor, handler); + ldapTemplate.search(executor, handler); + return handler.getList(); } } @@ -67,17 +81,18 @@ public class PersonDaoImpl implements PersonDao { } }; - NameClassPairCallbackHandler handler = + CollectingNameClassPairCallbackHandler handler = new ContextMapperCallbackHandler(new PersonContextMapper()); - return ldapTemplate.search(executor, handler); + ldapTemplate.search(executor, handler); + return handler.getList(); } } When using the - LdapTemplate.ContextMapperCallbackHandler you must + ContextMapperCallbackHandler you must make sure that you have called setReturningObjFlag(true) on your SearchControls instance.