1 17 18 19 20 package org.apache.lenya.ac.impl; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import org.apache.avalon.framework.activity.Disposable; 27 import org.apache.avalon.framework.logger.AbstractLogEnabled; 28 import org.apache.lenya.ac.AccessControlException; 29 import org.apache.lenya.ac.AccreditableManager; 30 import org.apache.lenya.ac.GroupManager; 31 import org.apache.lenya.ac.IPRangeManager; 32 import org.apache.lenya.ac.Item; 33 import org.apache.lenya.ac.ItemManagerListener; 34 import org.apache.lenya.ac.RoleManager; 35 import org.apache.lenya.ac.UserManager; 36 37 40 public abstract class AbstractAccreditableManager 41 extends AbstractLogEnabled 42 implements AccreditableManager, ItemManagerListener, Disposable { 43 44 private UserManager userManager = null; 45 private GroupManager groupManager = null; 46 private IPRangeManager ipRangeManager = null; 47 private RoleManager roleManager = null; 48 49 private List itemManagerListeners = new ArrayList (); 50 51 56 public void addItemManagerListener(ItemManagerListener listener) { 57 if (!itemManagerListeners.contains(listener)) { 58 59 if (getLogger().isDebugEnabled()) { 60 getLogger().debug("Adding listener: [" + listener + "]"); 61 } 62 63 itemManagerListeners.add(listener); 64 } 65 } 66 67 72 public void removeItemManagerListener(ItemManagerListener listener) { 73 if (getLogger().isDebugEnabled()) { 74 getLogger().debug("Removing listener: [" + listener + "]"); 75 } 76 77 itemManagerListeners.remove(listener); 78 } 79 80 86 protected void notifyAdded(Item item) throws AccessControlException { 87 List clone = new ArrayList (itemManagerListeners); 88 for (Iterator i = clone.iterator(); i.hasNext();) { 89 ItemManagerListener listener = (ItemManagerListener) i.next(); 90 listener.itemAdded(item); 91 } 92 } 93 94 100 protected void notifyRemoved(Item item) throws AccessControlException { 101 102 List clone = new ArrayList (itemManagerListeners); 103 for (Iterator i = clone.iterator(); i.hasNext();) { 104 ItemManagerListener listener = (ItemManagerListener) i.next(); 105 listener.itemRemoved(item); 106 } 107 } 108 109 112 public void itemAdded(Item item) throws AccessControlException { 113 if (getLogger().isDebugEnabled()) { 114 getLogger().debug("Item was added: [" + item + "] - notifying listeners"); 115 } 116 notifyAdded(item); 117 } 118 119 122 public void itemRemoved(Item item) throws AccessControlException { 123 if (getLogger().isDebugEnabled()) { 124 getLogger().debug("Item was removed: [" + item + "] - notifying listeners"); 125 } 126 notifyRemoved(item); 127 } 128 129 132 public void dispose() { 133 if (userManager != null) { 134 userManager.removeItemManagerListener(this); 135 } 136 if (groupManager != null) { 137 groupManager.removeItemManagerListener(this); 138 } 139 if (ipRangeManager != null) { 140 this.ipRangeManager.removeItemManagerListener(this); 141 } 142 if (roleManager != null) { 143 this.roleManager.removeItemManagerListener(this); 144 } 145 146 if (getLogger().isDebugEnabled()) { 147 getLogger().debug("Disposing [" + this + "]"); 148 } 149 } 150 151 154 public UserManager getUserManager() throws AccessControlException { 155 if (userManager == null) { 156 userManager = initializeUserManager(); 157 userManager.addItemManagerListener(this); 158 } 159 return userManager; 160 } 161 162 165 public GroupManager getGroupManager() throws AccessControlException { 166 if (groupManager == null) { 167 groupManager = initializeGroupManager(); 168 groupManager.addItemManagerListener(this); 169 } 170 return groupManager; 171 } 172 173 176 public RoleManager getRoleManager() throws AccessControlException { 177 if (roleManager == null) { 178 roleManager = initializeRoleManager(); 179 roleManager.addItemManagerListener(this); 180 } 181 return roleManager; 182 } 183 184 187 public IPRangeManager getIPRangeManager() throws AccessControlException { 188 if (ipRangeManager == null) { 189 ipRangeManager = initializeIPRangeManager(); 190 ipRangeManager.addItemManagerListener(this); 191 } 192 return ipRangeManager; 193 } 194 195 201 protected abstract GroupManager initializeGroupManager() throws AccessControlException; 202 203 209 protected abstract IPRangeManager initializeIPRangeManager() throws AccessControlException; 210 211 217 protected abstract RoleManager initializeRoleManager() throws AccessControlException; 218 219 225 protected abstract UserManager initializeUserManager() throws AccessControlException; 226 227 } 228 | Popular Tags |