1 package com.atlassian.user.impl.ldap.search.page;
2
3 import com.atlassian.user.Entity;
4 import com.atlassian.user.EntityException;
5 import com.atlassian.user.impl.ldap.LDAPEntityFactory;
6 import com.atlassian.user.impl.ldap.properties.LdapSearchProperties;
7 import com.atlassian.user.impl.ldap.repository.LdapContextFactory;
8 import com.atlassian.user.impl.ldap.search.LDAPPagerInfo;
9 import org.apache.log4j.Category;
10
11 import javax.naming.directory.Attributes;
12 import javax.naming.directory.SearchResult;
13 import java.util.List;
14
15 public class LDAPEntityPager<T extends Entity> extends AbstractLDAPPager<T>
16 {
17 public static final Category log = Category.getInstance(LDAPEntityPager.class);
18 protected LDAPEntityFactory<? extends T> entityFactory;
19
20 public LDAPEntityPager(LdapSearchProperties searchProperties,
21 LdapContextFactory repository, LDAPEntityFactory<? extends T> entityFactory, LDAPPagerInfo info)
22 {
23 super(searchProperties, repository, info);
24 this.entityFactory = entityFactory;
25
26 preload();
27 }
28
29 protected List<T> preloadSearchResult(SearchResult result, List<T> prefetched) throws EntityException
30 {
31 try
32 {
33 Attributes entityAttributes = result.getAttributes();
34 T entity = entityFactory.getEntity(entityAttributes, result.getName());
35 prefetched.add(entity);
36 }
37 catch (Throwable e)
38 {
39 log.error("There was an error converting the SearchResult: " + result + " into an entity or entities.", e);
40 }
41
42 return prefetched;
43 }
44 }