1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.ldaptemplate;
17
18 import java.util.LinkedList;
19 import java.util.List;
20
21 import javax.naming.directory.SearchResult;
22
23 /***
24 * A SearchResultCallbackHandler to collect all results in an internal List.
25 * Useful in combination with e.g. an
26 * {@link net.sf.ldaptemplate.AttributesMapper} or
27 * {@link net.sf.ldaptemplate.ContextMapper}.
28 *
29 * @see net.sf.ldaptemplate.LdapTemplate
30 * @see net.sf.ldaptemplate.LdapTemplate.AttributesMapperCallbackHandler
31 * @see net.sf.ldaptemplate.LdapTemplate.ContextMapperCallbackHandler
32 * @author Mattias Arthursson
33 */
34 public abstract class CollectingSearchResultCallbackHandler implements
35 SearchResultCallbackHandler {
36
37 private List list = new LinkedList();
38
39
40
41
42
43
44 public void handleSearchResult(SearchResult searchResult) {
45 list.add(getObjectFromResult(searchResult));
46 }
47
48 /***
49 * Handle a single search result and transform it to an Object.
50 *
51 * @param searchResult
52 * a SearchResult from a search operation.
53 * @return an object constructed from the data in the SearchResult.
54 */
55 protected abstract Object getObjectFromResult(SearchResult searchResult);
56
57 /***
58 * Get the assembled list.
59 *
60 * @return the list of all assembled objects.
61 */
62 public List getList() {
63 return list;
64 }
65 }