1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 }