1 package org.sapia.util.text; 2 3 import java.util.Map ; 4 5 6 31 public class MapContext implements TemplateContextIF { 32 private Map _props; 33 private TemplateContextIF _ancestor; 34 private boolean _ancestorFirst; 35 36 46 public MapContext(Map props, TemplateContextIF ancestor, boolean ancestorFirst) { 47 _props = props; 48 _ancestor = ancestor; 49 _ancestorFirst = ancestorFirst; 50 } 51 52 55 public Object getValue(String aName) { 56 Object value; 57 58 if (_ancestorFirst) { 59 value = fromAncestor(aName); 60 61 if (value == null) { 62 value = _props.get(aName); 63 } 64 } else { 65 value = _props.get(aName); 66 67 if (value == null) { 68 value = fromAncestor(aName); 69 } 70 } 71 72 return value; 73 } 74 75 78 public void put(String name, Object value) { 79 _props.put(name, value); 80 } 81 82 protected Object fromAncestor(String aName) { 83 if (_ancestor != null) { 84 return _ancestor.getValue(aName); 85 } 86 87 return null; 88 } 89 } 90 | Popular Tags |