Announcement Announcement Module
Collapse
No announcement yet.
Question regarding the documentation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question regarding the documentation

    Hi,

    I am trying to work through the documentation http://static.springframework.org/sp...1.1/reference/

    and am having a bit of trouble with chapter 4, namely the 4.1 section.

    Here is the code sample in that section:
    Code:
    Example 4.1. A custom search method using SearchExecutor and AttributesMapper
    
    package com.example.dao;
    
    public class PersonDaoImpl implements PersonDao {
       ...
       public List search(final Name base, final String filter, final String[] params,
             final SearchControls ctls) {
          SearchExecutor executor = new SearchExecutor() {
             public NamingEnumeration executeSearch(DirContext ctx) {
                return ctx.search(base, filter, params, ctls);
             }
          };
    
          NameClassPairCallbackHandler handler =
             ldapTemplate.new AttributesMapperCallbackHandler(new PersonAttributesMapper());
    
          return ldapTemplate.search(executor, handler);
       }
    }
    Now the problem I have is that ldapTemplate.search(executor, handler) returns void not a List. So how do I actually do what this example is trying to demonstrate?

    Any help much appreciated

  • #2
    Ouch, there's actually two errors in that example. Of course, the search method that's used in this case does not have a return value. In stead you'll need to rely on the NameClassPairCallbackHandler to collect the results. In this case we are using LdapTemplate.AttributesMapperCallbackHandler, which does indeed collect the results. When the search is executed, the collected results can be retrieved using the getList() method of the CallbackHandler, which also means that you should make the handler variable a CollectingNameClassPairCallbackHandler in the variable declaration.

    This should definitely be corrected. I would appreciate if you would file a jira issue on this.

    Comment


    • #3
      Mattias beat me to it. Anyway, here's my answer.

      The callback handler used in the example, AttributesMapperCallbackHandler, is actually a subclass of CollectingNameClassPairCallbackHandler, which collects the results in an internal List. The correct code would have asked the handler for its list and returned that. Like this:

      Code:
      package com.example.dao;
      
      public class PersonDaoImpl implements PersonDao {
         ...
         public List search(final Name base, final String filter, final String[] params,
               final SearchControls ctls) {
            SearchExecutor executor = new SearchExecutor() {
               public NamingEnumeration executeSearch(DirContext ctx) {
                  return ctx.search(base, filter, params, ctls);
               }
            };
      
            CollectingNameClassPairCallbackHandler handler =
               ldapTemplate.new AttributesMapperCallbackHandler(new PersonAttributesMapper());
      
            ldapTemplate.search(executor, handler);
            return handler.getList();
         }
      }
      As a side note, we have recently turned the nested class AttributesMapperCallbackHandler into a top-level class, so future versions won't need an LdapTemplate instance when creating an instance of it:

      Code:
      CollectingNameClassPairCallbackHandler handler =
            new AttributesMapperCallbackHandler(new PersonAttributesMapper());
      Last edited by ulsa; Mar 21st, 2007, 03:51 AM.

      Comment


      • #4
        Thanks guys I did a little more digging after I posted and managed to come across the getList() method, but it is good to see my stumblings confirmed

        I've noticed a couple of other problems with some of the sample code in the doco, I will make a jira account and raise issues through that.

        p.s. It would be cool if you could link the jira account to the forum account

        Comment

        Working...
        X