01: package org.rapla.framework;
02:
03: import java.util.HashMap;
04:
05: public class RaplaDefaultContext implements RaplaContext {
06: private final HashMap contextObjects = new HashMap();
07: private final RaplaContext m_parent;
08:
09: public RaplaDefaultContext() {
10: this (null);
11: }
12:
13: public RaplaDefaultContext(final RaplaContext parent) {
14: m_parent = parent;
15: }
16:
17: public Object lookup(final String key) throws RaplaContextException {
18: final Object object = contextObjects.get(key);
19: if (null != object) {
20: return object;
21: } else if (null != m_parent) {
22: return m_parent.lookup(key);
23: } else {
24: final String message = "Unable to provide implementation for "
25: + key;
26: throw new RaplaContextException(key, message, null);
27: }
28: }
29:
30: public boolean has(final String key) {
31: if (contextObjects.get(key) != null)
32: return true;
33:
34: if (m_parent == null)
35: return false;
36:
37: return m_parent.has(key);
38: }
39:
40: public void put(final String key, final Object object) {
41: contextObjects.put(key, object);
42: }
43:
44: protected Object getUnsave(String key) {
45: if (has(key)) {
46: try {
47: return lookup(key);
48: } catch (RaplaContextException ex) {
49: }
50: }
51: return null;
52: }
53:
54: }
|