KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > auth > acl > AccessControlList


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server.auth.acl;
18
19 import java.util.Vector JavaDoc;
20
21 /**
22  * Access Control List Class
23  * <p>
24  * Contains a list of access controls for a shared filesystem.
25  */

26 public class AccessControlList
27 {
28
29     // Access control list
30

31     private Vector JavaDoc<AccessControl> m_list;
32
33     // Default access level applied when rules return a default status
34

35     private int m_defaultAccess = AccessControl.ReadWrite;
36
37     /**
38      * Create an access control list.
39      */

40     public AccessControlList()
41     {
42         m_list = new Vector JavaDoc<AccessControl>();
43     }
44
45     /**
46      * Get the default access level
47      *
48      * @return int
49      */

50     public final int getDefaultAccessLevel()
51     {
52         return m_defaultAccess;
53     }
54
55     /**
56      * Set the default access level
57      *
58      * @param level int
59      * @exception InvalidACLTypeException If the access level is invalid
60      */

61     public final void setDefaultAccessLevel(int level) throws InvalidACLTypeException
62     {
63
64         // Check the default access level
65

66         if (level < AccessControl.NoAccess || level > AccessControl.MaxLevel)
67             throw new InvalidACLTypeException();
68
69         // Set the default access level for the access control list
70

71         m_defaultAccess = level;
72     }
73
74     /**
75      * Add an access control to the list
76      *
77      * @param accCtrl AccessControl
78      */

79     public final void addControl(AccessControl accCtrl)
80     {
81
82         // Add the access control to the list
83

84         m_list.add(accCtrl);
85     }
86
87     /**
88      * Return the specified access control
89      *
90      * @param idx int
91      * @return AccessControl
92      */

93     public final AccessControl getControlAt(int idx)
94     {
95         if (idx < 0 || idx >= m_list.size())
96             return null;
97         return m_list.get(idx);
98     }
99
100     /**
101      * Return the number of access controls in the list
102      *
103      * @return int
104      */

105     public final int numberOfControls()
106     {
107         return m_list.size();
108     }
109
110     /**
111      * Remove all access controls from the list
112      */

113     public final void removeAllControls()
114     {
115         m_list.removeAllElements();
116     }
117
118     /**
119      * Remove the specified access control from the list.
120      *
121      * @param idx int
122      * @return AccessControl
123      */

124     public final AccessControl removeControl(int idx)
125     {
126         if (idx < 0 || idx >= m_list.size())
127             return null;
128         return m_list.remove(idx);
129     }
130
131     /**
132      * Return the access control list as a string.
133      *
134      * @return java.lang.String
135      */

136     public String JavaDoc toString()
137     {
138         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
139
140         str.append("[");
141         str.append(m_list.size());
142         str.append(":");
143
144         str.append(":");
145         str.append(AccessControl.asAccessString(getDefaultAccessLevel()));
146         str.append(":");
147
148         for (int i = 0; i < m_list.size(); i++)
149         {
150             AccessControl ctrl = m_list.get(i);
151             str.append(ctrl.toString());
152             str.append(",");
153         }
154         str.append("]");
155
156         return str.toString();
157     }
158 }
159
Popular Tags