KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.lenya.ac.file;
19
20 import java.io.File JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.lenya.ac.AccessControlException;
25 import org.apache.lenya.ac.Item;
26 import org.apache.lenya.ac.Role;
27 import org.apache.lenya.ac.RoleManager;
28
29 /**
30  * File-based role manager implementation.
31  * @version $Id: FileRoleManager.java 43237 2004-08-16 15:59:51Z andreas $
32  */

33 public final class FileRoleManager extends FileItemManager implements RoleManager {
34     protected static final String JavaDoc SUFFIX = ".rml";
35     private static Map JavaDoc instances = new HashMap JavaDoc();
36
37     /**
38      * Return the <code>RoleManager</code> for this configuration directory.
39      * The <code>RoleManager</code> is a singleton.
40      *
41      * @param configurationDirectory the directory for which the RoleManager is requested.
42      * @throws AccessControlException if the <code>RoleManager<code> could not be instantiated
43      */

44     protected FileRoleManager(File JavaDoc configurationDirectory)
45         throws AccessControlException {
46         super(configurationDirectory);
47     }
48
49     /**
50      * Returns the role manager for this configuration directory.
51      * @param configurationDirectory The configuration directory.
52      * @return A role manager.
53      * @throws AccessControlException when something went wrong.
54      */

55     public static FileRoleManager instance(File JavaDoc configurationDirectory)
56         throws AccessControlException {
57         if (!instances.containsKey(configurationDirectory)) {
58             instances.put(configurationDirectory, new FileRoleManager(configurationDirectory));
59         }
60
61         return (FileRoleManager) instances.get(configurationDirectory);
62     }
63
64     /**
65      * Get the role for the given ID.
66      *
67      * @param roleId The name of the role requested.
68      * @return a <code>Role</code> or null if no role with the given name found
69      */

70     public Role getRole(String JavaDoc roleId) {
71         return (Role) getItem(roleId);
72     }
73
74     /**
75      * @see org.apache.lenya.ac.file.FileItemManager#getSuffix()
76      */

77     protected String JavaDoc getSuffix() {
78         return SUFFIX;
79     }
80
81     /**
82      * Get all roles
83      *
84      * @return an array of roles.
85      */

86     public Role[] getRoles() {
87         Item[] items = super.getItems();
88         Role[] roles = new Role[items.length];
89         for (int i = 0; i < roles.length; i++) {
90             roles[i] = (Role) items[i];
91         }
92         return roles;
93     }
94
95     /**
96      * Add a role
97      *
98      * @param role The role to add.
99      * @throws AccessControlException if an error occurs.
100      */

101     public void add(Role role) throws AccessControlException {
102         super.add(role);
103     }
104
105     /**
106      * Remove a role
107      *
108      * @param role The role to remove.
109      * @throws AccessControlException if an error occurs.
110      */

111     public void remove(Role role) throws AccessControlException {
112         super.remove(role);
113     }
114 }
115
Popular Tags