KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > ac > file > FileIPRangeManager


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: FileIPRangeManager.java 43237 2004-08-16 15:59:51Z andreas $ */
19
20 package org.apache.lenya.ac.file;
21
22 import java.io.File JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
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 /**
32  * Manager for IP address ranges.
33  */

34 public class FileIPRangeManager extends FileItemManager implements IPRangeManager {
35
36     /**
37      * Ctor.
38      * @param configurationDirectory The configuration directory.
39      * @throws AccessControlException when something went wrong.
40      */

41     protected FileIPRangeManager(File JavaDoc configurationDirectory) throws AccessControlException {
42         super(configurationDirectory);
43     }
44     
45     protected static final String JavaDoc SUFFIX = ".ipml";
46
47     /**
48      * @see org.apache.lenya.ac.file.FileItemManager#getSuffix()
49      */

50     protected String JavaDoc getSuffix() {
51         return SUFFIX;
52     }
53
54     private static Map JavaDoc instances = new HashMap JavaDoc();
55     
56     /**
57      * Describe <code>instance</code> method here.
58      *
59      * @param configurationDirectory a directory
60      * @return an <code>IPRangeManager</code> value
61      * @exception AccessControlException if an error occurs
62      */

63     public static FileIPRangeManager instance(File JavaDoc 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     /**
79      * Get all IP ranges.
80      *
81      * @return an array of IP ranges.
82      */

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     /**
93      * Add the given IP range
94      *
95      * @param range IP range that is to be added
96      * @throws AccessControlException when the notification failed.
97      */

98     public void add(IPRange range) throws AccessControlException {
99         super.add(range);
100     }
101
102     /**
103      * Remove the given IP range
104      *
105      * @param range IP range that is to be removed
106      * @throws AccessControlException when the notification failed.
107      */

108     public void remove(IPRange range) throws AccessControlException {
109         super.remove(range);
110     }
111
112     /**
113      * Get the IPRange with the given id.
114      *
115      * @param rangeId user id of requested IP range
116      * @return the requested IP range or null if there is
117      * no IP range with the given id
118      */

119     public IPRange getIPRange(String JavaDoc rangeId) {
120         return (IPRange) getItem(rangeId);
121     }
122
123 }
124
Popular Tags