1 package org.catacomb.druid.load;
2
3 import java.util.HashMap;
4
5 import org.catacomb.druid.manifest.DecManifest;
6 import org.catacomb.interlish.resource.Role;
7
8
9 public class RoleMap {
10
11 protected HashMap<String, HashMap<String, Role>> functionMaps;
12
13 public RoleMap() {
14 functionMaps = new HashMap<String, HashMap<String, Role>>();
15 }
16
17
18
19 public void addRoles(DecManifest dm) {
20 for (Role r : dm.getRoles()) {
21 addRole(r);
22 }
23 }
24
25
26 private void addRole(Role r) {
27
28 (getFunctionMap(r.getFunction())).put(r.getValue(), r);
29 }
30
31
32 private HashMap<String, Role> getFunctionMap(String s) {
33 HashMap<String, Role> ret = null;
34
35 if (functionMaps.containsKey(s)) {
36 ret = functionMaps.get(s);
37
38 } else {
39 ret = new HashMap<String, Role>();
40 functionMaps.put(s, ret);
41
42 }
43 return ret;
44 }
45
46
47
48 public boolean hasRole(String role, String subject) {
49 boolean ret = (getFunctionMap(role).containsKey(subject));
50
51 if (!ret) {
52
53 }
54 return ret;
55 }
56
57 public Role getRole(String role, String subject) {
58 return (getFunctionMap(role).get(subject));
59 }
60
61 }