1 17 18 package org.apache.lenya.ac.file; 19 20 import java.io.File ; 21 import java.util.Arrays ; 22 import java.util.HashMap ; 23 import java.util.HashSet ; 24 import java.util.Map ; 25 import java.util.Set ; 26 27 import org.apache.lenya.ac.AccessControlException; 28 import org.apache.lenya.ac.Item; 29 import org.apache.lenya.ac.User; 30 import org.apache.lenya.ac.UserManager; 31 import org.apache.lenya.ac.UserType; 32 33 37 public class FileUserManager extends FileItemManager implements UserManager { 38 39 private static Map instances = new HashMap (); 40 private Set userTypes; 41 42 49 protected FileUserManager(File configurationDirectory, UserType[] userTypes) 50 throws AccessControlException { 51 super(configurationDirectory); 52 this.userTypes = new HashSet (Arrays.asList(userTypes)); 53 } 54 55 63 public static FileUserManager instance(File configurationDirectory, UserType[] userTypes) 64 throws AccessControlException { 65 66 assert configurationDirectory != null; 67 if (!configurationDirectory.isDirectory()) { 68 throw new AccessControlException("Configuration directory [" + configurationDirectory 69 + "] does not exist!"); 70 } 71 72 if (!instances.containsKey(configurationDirectory)) { 73 instances.put(configurationDirectory, new FileUserManager(configurationDirectory, 74 userTypes)); 75 } 76 77 return (FileUserManager) instances.get(configurationDirectory); 78 } 79 80 85 public User[] getUsers() { 86 Item[] items = super.getItems(); 87 User[] users = new User[items.length]; 88 for (int i = 0; i < users.length; i++) { 89 users[i] = (User) items[i]; 90 } 91 return users; 92 } 93 94 97 public void add(User user) throws AccessControlException { 98 super.add(user); 99 } 100 101 104 public void remove(User user) throws AccessControlException { 105 super.remove(user); 106 } 107 108 114 public User getUser(String userId) { 115 return (User) getItem(userId); 116 } 117 118 121 public UserType[] getUserTypes() { 122 return (UserType[]) userTypes.toArray(new UserType[userTypes.size()]); 123 } 124 125 protected static final String SUFFIX = ".iml"; 126 127 130 protected String getSuffix() { 131 return SUFFIX; 132 } 133 134 } | Popular Tags |