1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.neethi;
17
18 import java.util.HashMap;
19
20 /**
21 * Provides a default implementation of PolicyRegistry interface.
22 */
23 public class PolicyRegistryImpl implements PolicyRegistry {
24
25 private PolicyRegistry parent = null;
26
27 private HashMap reg = new HashMap();
28
29 public PolicyRegistryImpl() {
30 }
31
32 /**
33 * Constructs a PolicyRegistryImpl with the specified PolicyRegistry
34 * as it's parent. If it can't lookup a Policy in it's own registry
35 * then it lookup in the parent and returns the results.
36 *
37 * @param parent the Parent of this PolicyRegistry
38 */
39 public PolicyRegistryImpl(PolicyRegistry parent) {
40 this.parent = parent;
41 }
42
43 public Policy lookup(String key) {
44 Policy policy = (Policy) reg.get(key);
45
46 if (policy == null && parent != null) {
47 return parent.lookup(key);
48 }
49
50 return policy;
51 }
52
53 public void register(String key, Policy policy) {
54 reg.put(key, policy);
55 }
56
57 public void remove(String key) {
58 reg.remove(key);
59 }
60
61 public void setParent(PolicyRegistry parent) {
62 this.parent = parent;
63 }
64
65 public PolicyRegistry getParent() {
66 return parent;
67 }
68 }