KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > AbstractPolicyDatabase


1 package com.sslexplorer.policyframework;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 import com.sslexplorer.boot.PropertyList;
13 import com.sslexplorer.core.CoreEvent;
14 import com.sslexplorer.core.CoreServlet;
15 import com.sslexplorer.security.Role;
16 import com.sslexplorer.security.SessionInfo;
17 import com.sslexplorer.security.User;
18
19
20 /**
21  * Abstract implementation of a
22  * {@link com.sslexplorer.policyframework.PolicyDatabase} that provides basic
23  * functionality for registering resource types.
24  *
25  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
26  */

27 public abstract class AbstractPolicyDatabase implements PolicyDatabase {
28
29     protected Map JavaDoc resourceTypes = new HashMap JavaDoc();
30
31     /*
32      * (non-Javadoc)
33      *
34      * @see com.sslexplorer.policyframework.PolicyDatabase#registerResourceType(com.sslexplorer.policyframework.ResourceType)
35      */

36     public void registerResourceType(ResourceType resourceType) throws Exception JavaDoc {
37         resourceTypes.put(String.valueOf(resourceType.getResourceTypeId()), resourceType);
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see com.sslexplorer.policyframework.PolicyDatabase#deregisterResourceType(com.sslexplorer.policyframework.ResourceType)
44      */

45     public void deregisterResourceType(ResourceType resourceType) throws Exception JavaDoc {
46         resourceTypes.remove(String.valueOf(resourceType.getResourceTypeId()));
47     }
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see com.sslexplorer.policyframework.PolicyDatabase#getResourceType(int)
53      */

54     public ResourceType getResourceType(int resourceTypeId) {
55         return (ResourceType) resourceTypes.get(String.valueOf(resourceTypeId));
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see com.sslexplorer.policyframework.PolicyDatabase#getResourceTypes(java.lang.String)
62      */

63     public List JavaDoc getResourceTypes(String JavaDoc permissionClass) throws Exception JavaDoc {
64         List JavaDoc l = new ArrayList JavaDoc();
65         Map.Entry JavaDoc entry;
66         for (Iterator JavaDoc i = resourceTypes.entrySet().iterator(); i.hasNext();) {
67             entry = (Map.Entry JavaDoc) i.next();
68             if (permissionClass == null || permissionClass.equals(((ResourceType) entry.getValue()).getPermissionClass())) {
69                 l.add(entry.getValue());
70             }
71         }
72         return l;
73     }
74
75     /*
76      * (non-Javadoc)
77      *
78      * @see com.sslexplorer.policyframework.PolicyDatabase#getResourceTypeCount()
79      */

80     public int getResourceTypeCount() {
81         return resourceTypes.size();
82     }
83 }
84
Popular Tags