View Javadoc

1   /*
2    * AccountPoolMapper.java
3    *
4    * Created on June 16, 2004, 3:10 PM
5    */
6   
7   package gov.bnl.gums;
8   
9   /*** Provides the mapping by assigning user accounts from a pool provided by
10   * the AccountPoolMapperDB.
11   * <p>
12   * The accounts are mapped when the mapUser function is called for that
13   * particular user. Accounts are never deleted from the pool
14   *
15   * @todo should implement caching?
16   * @author  Gabriele Carcassi
17   */
18  public class AccountPoolMapper implements AccountMapper {
19      
20      private AccountPoolMapperDB db;
21      private String name;
22      private PersistenceFactory persistanceFactory;
23  
24      public String mapUser(String userDN) {
25          String account = db.retrieveAccount(userDN);
26          if (account != null) return account;
27          return db.assignAccount(userDN);
28      }    
29      
30      public String getPersistenceFactory() {
31          return persistanceFactory.getName();
32      }
33      
34      public void setPersistence(PersistenceFactory persistanceFactory, String name) {
35          this.persistanceFactory = persistanceFactory;
36          this.name = name;
37          db = persistanceFactory.retrieveAccountPoolMapperDB(name);
38      }
39      public String getName() {
40          return name;
41      }
42  }