KickJava   Java API By Example, From Geeks To Geeks.

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


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.Hashtable JavaDoc;
20
21 import org.alfresco.config.ConfigElement;
22
23 /**
24  * Access Control Factoy Class
25  * <p>
26  * The AccessControlFactory class holds a table of available AccessControlParsers that are used to
27  * generate AccessControl instances.
28  * <p>
29  * An AccessControlParser has an associated unique type name that is used to call the appropriate
30  * parser.
31  */

32 public class AccessControlFactory
33 {
34
35     // Access control parsers
36

37     private Hashtable JavaDoc<String JavaDoc, AccessControlParser> m_parsers;
38
39     /**
40      * Class constructor
41      */

42     public AccessControlFactory()
43     {
44         m_parsers = new Hashtable JavaDoc<String JavaDoc, AccessControlParser>();
45     }
46
47     /**
48      * Create an access control using the specified parameters
49      *
50      * @param type String
51      * @param params ConfigElement
52      * @return AccessControl
53      * @exception ACLParseException
54      * @exception InvalidACLTypeException
55      */

56     public final AccessControl createAccessControl(String JavaDoc type, ConfigElement params) throws ACLParseException,
57             InvalidACLTypeException
58     {
59
60         // Find the access control parser
61

62         AccessControlParser parser = m_parsers.get(type);
63         if (parser == null)
64             throw new InvalidACLTypeException(type);
65
66         // Parse the parameters and create a new AccessControl instance
67

68         return parser.createAccessControl(params);
69     }
70
71     /**
72      * Add a parser to the list of available parsers
73      *
74      * @param parser AccessControlParser
75      */

76     public final void addParser(AccessControlParser parser)
77     {
78         m_parsers.put(parser.getType(), parser);
79     }
80
81     /**
82      * Remove a parser from the available parser list
83      *
84      * @param type String
85      * @return AccessControlParser
86      */

87     public final AccessControlParser removeParser(String JavaDoc type)
88     {
89         return (AccessControlParser) m_parsers.remove(type);
90     }
91 }
92
Popular Tags