1 17 18 19 20 package org.apache.lenya.ac.file; 21 22 import java.io.File ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 import org.apache.lenya.ac.AccessControlException; 27 import org.apache.lenya.ac.IPRange; 28 import org.apache.lenya.ac.IPRangeManager; 29 import org.apache.lenya.ac.Item; 30 31 34 public class FileIPRangeManager extends FileItemManager implements IPRangeManager { 35 36 41 protected FileIPRangeManager(File configurationDirectory) throws AccessControlException { 42 super(configurationDirectory); 43 } 44 45 protected static final String SUFFIX = ".ipml"; 46 47 50 protected String getSuffix() { 51 return SUFFIX; 52 } 53 54 private static Map instances = new HashMap (); 55 56 63 public static FileIPRangeManager instance(File configurationDirectory) throws AccessControlException { 64 65 assert configurationDirectory != null; 66 if (!configurationDirectory.isDirectory()) { 67 throw new AccessControlException( 68 "Configuration directory [" + configurationDirectory + "] does not exist!"); 69 } 70 71 if (!instances.containsKey(configurationDirectory)) { 72 instances.put(configurationDirectory, new FileIPRangeManager(configurationDirectory)); 73 } 74 75 return (FileIPRangeManager) instances.get(configurationDirectory); 76 } 77 78 83 public IPRange[] getIPRanges() { 84 Item[] items = super.getItems(); 85 IPRange[] ranges = new IPRange[items.length]; 86 for (int i = 0; i < ranges.length; i++) { 87 ranges[i] = (IPRange) items[i]; 88 } 89 return ranges; 90 } 91 92 98 public void add(IPRange range) throws AccessControlException { 99 super.add(range); 100 } 101 102 108 public void remove(IPRange range) throws AccessControlException { 109 super.remove(range); 110 } 111 112 119 public IPRange getIPRange(String rangeId) { 120 return (IPRange) getItem(rangeId); 121 } 122 123 } 124 | Popular Tags |