1 package org.jicengine.operation; 2 3 import java.util.Map ; 4 import java.util.HashMap ; 5 6 28 29 public class LocalContext extends AbstractContext { 30 31 private Context local; 32 private Context parent; 33 34 37 public LocalContext(Context local, Context parent) 38 { 39 super(local + " + " + parent); 40 this.local = local; 41 this.parent = parent; 42 } 43 44 public LocalContext(String name, Context parent) 45 { 46 this(name, new SimpleContext(name), parent); 47 } 48 49 50 public LocalContext(String name, Context local, Context parent) 51 { 52 super(name); 53 this.local = local; 54 this.parent = parent; 55 } 56 57 public Context getParent() 58 { 59 return this.parent; 60 } 61 62 public Object getObject(String name) throws ObjectNotFoundException 63 { 64 if( this.local.hasObject(name) ){ 65 return this.local.getObject(name); 66 } 67 else { 68 try { 69 return getFromParent(name); 70 } catch (ObjectNotFoundException e){ 71 throw new ObjectNotFoundException(name, this); 72 } 73 } 74 } 75 76 protected Object getFromParent(String name) throws ObjectNotFoundException 77 { 78 return getParent().getObject(name); 79 } 80 81 public boolean hasObject(String name) { 82 return (this.local.hasObject(name)) || (hasInParent(name)); 83 } 84 85 protected boolean hasInParent(String name) 86 { 87 return getParent().hasObject(name); 88 } 89 90 public void addObject(String name, Object object) 91 { 92 this.local.addObject(name,object); 93 } 94 95 protected void copyObjectsTo(Map map) 96 { 97 ((AbstractContext)this.parent).copyObjectsTo(map); 99 ((AbstractContext)this.local).copyObjectsTo(map); 101 } 102 103 } 104 | Popular Tags |