View Javadoc

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