01: package org.jicengine.operation;
02:
03: import java.util.*;
04:
05: /**
06: *
07: * <p>
08: * Copyright (C) 2004 Timo Laitinen
09: * </p>
10: * @author Timo Laitinen
11: * @created 2004-09-20
12: * @since JICE-0.10
13: */
14: public class SimpleContext extends AbstractContext {
15:
16: private Map objects;
17:
18: public SimpleContext() {
19: this ("");
20: }
21:
22: public SimpleContext(String name) {
23: this (name, new java.util.HashMap());
24: }
25:
26: public SimpleContext(String name, Map objects) {
27: super (name);
28: this .objects = objects;
29: }
30:
31: public boolean hasObject(String name) {
32: return this .objects.containsKey(name);
33: }
34:
35: public Object getObject(String name) throws ObjectNotFoundException {
36: Object object = this .objects.get(name);
37: if (object != null) {
38: return object;
39: } else {
40: throw new ObjectNotFoundException(name, this );
41: }
42: }
43:
44: public void addObject(String name, Object object) {
45: Object previous = this .objects.put(name, object);
46: if (previous != null) {
47: throw new DuplicateNameException(name, previous, object,
48: this );
49: }
50: }
51:
52: protected void copyObjectsTo(Map map) {
53: map.putAll(this.objects);
54: }
55:
56: }
|