KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > operation > SimpleContext


1 package org.jicengine.operation;
2
3 import java.util.*;
4
5 /**
6  *
7  * <p>
8  * Copyright (C) 2004 Timo Laitinen
9  * </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     {
20         this("");
21     }
22
23     public SimpleContext(String JavaDoc name)
24     {
25         this(name,new java.util.HashMap JavaDoc());
26     }
27
28     public SimpleContext(String JavaDoc name, Map objects)
29     {
30         super(name);
31         this.objects = objects;
32     }
33
34     public boolean hasObject(String JavaDoc name)
35     {
36         return this.objects.containsKey(name);
37     }
38
39     public Object JavaDoc getObject(String JavaDoc name) throws ObjectNotFoundException
40     {
41         Object JavaDoc object = this.objects.get(name);
42         if( object != null ){
43             return object;
44         }
45         else {
46             throw new ObjectNotFoundException(name,this);
47         }
48     }
49
50     public void addObject(String JavaDoc name, Object JavaDoc object)
51     {
52         Object JavaDoc previous = this.objects.put(name, object);
53         if( previous != null ){
54             throw new DuplicateNameException(name,previous, object, this);
55         }
56     }
57
58     protected void copyObjectsTo(Map map)
59     {
60         map.putAll(this.objects);
61     }
62
63 }
64
Popular Tags