KickJava   Java API By Example, From Geeks To Geeks.

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


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: FileGroupManager.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.Group;
28 import org.apache.lenya.ac.GroupManager;
29 import org.apache.lenya.ac.Item;
30
31 /**
32  * File-based group manager.
33  */

34 public final class FileGroupManager extends FileItemManager implements GroupManager {
35
36     private static Map JavaDoc instances = new HashMap JavaDoc();
37
38     /**
39      * Create a GroupManager
40      *
41      * @param configurationDirectory for which the GroupManager is to be created
42      * @throws AccessControlException if no GroupManager could be instanciated
43      */

44     private FileGroupManager(File JavaDoc configurationDirectory) throws AccessControlException {
45         super(configurationDirectory);
46     }
47
48     /**
49      * Return the <code>GroupManager</code> for the given publication.
50      * The <code>GroupManager</code> is a singleton.
51      *
52      * @param configurationDirectory for which the GroupManager is requested
53      * @return a <code>GroupManager</code>
54      * @throws AccessControlException if no GroupManager could be instanciated
55      */

56     public static FileGroupManager instance(File JavaDoc configurationDirectory)
57         throws AccessControlException {
58         assert configurationDirectory != null;
59
60         if (!instances.containsKey(configurationDirectory)) {
61             instances.put(configurationDirectory, new FileGroupManager(configurationDirectory));
62         }
63
64         return (FileGroupManager) instances.get(configurationDirectory);
65     }
66
67     /**
68      * Get all groups
69      *
70      * @return an array of groups.
71      */

72     public Group[] getGroups() {
73         Item[] items = super.getItems();
74         Group[] groups = new Group[items.length];
75         for (int i = 0; i < groups.length; i++) {
76             groups[i] = (Group) items[i];
77         }
78         return groups;
79     }
80
81     /**
82      * Add a group to this manager
83      *
84      * @param group the group to be added
85      * @throws AccessControlException when the notification failed.
86      */

87     public void add(Group group) throws AccessControlException {
88         super.add(group);
89     }
90
91     /**
92      * Remove a group from this manager
93      *
94      * @param group the group to be removed
95      * @throws AccessControlException when the notification failed.
96      */

97     public void remove(Group group) throws AccessControlException {
98         super.remove(group);
99     }
100
101     /**
102      * Get the group with the given group name.
103      *
104      * @param groupId the id of the requested group
105      * @return a <code>Group</code> or null if there is no group with the given name
106      */

107     public Group getGroup(String JavaDoc groupId) {
108         return (Group) getItem(groupId);
109     }
110
111     protected static final String JavaDoc SUFFIX = ".gml";
112     
113     /**
114      * @see org.apache.lenya.ac.file.FileItemManager#getSuffix()
115      */

116     protected String JavaDoc getSuffix() {
117         return SUFFIX;
118     }
119
120 }
121
Popular Tags