1 package org.jicengine.operation; 2 3 import java.util.*; 4 5 14 public class SimpleContext extends AbstractContext { 15 16 private Map objects; 17 18 public SimpleContext() 19 { 20 this(""); 21 } 22 23 public SimpleContext(String name) 24 { 25 this(name,new java.util.HashMap ()); 26 } 27 28 public SimpleContext(String name, Map objects) 29 { 30 super(name); 31 this.objects = objects; 32 } 33 34 public boolean hasObject(String name) 35 { 36 return this.objects.containsKey(name); 37 } 38 39 public Object getObject(String name) throws ObjectNotFoundException 40 { 41 Object 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 name, Object object) 51 { 52 Object 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 |