1 4 package gnu.mapping; 5 6 public class ConstrainedLocation extends Location 7 { 8 protected Location base; 9 10 protected Procedure converter; 11 12 public static ConstrainedLocation make (Location base, 13 Procedure converter) 14 { 15 ConstrainedLocation cloc = new ConstrainedLocation(); 16 cloc.base = base; 17 cloc.converter = converter; 18 return cloc; 19 } 20 21 public Symbol getKeySymbol () 22 { 23 return base.getKeySymbol(); 24 } 25 26 public Object getKeyProperty () 27 { 28 return base.getKeyProperty(); 29 } 30 31 public boolean isConstant () 32 { 33 return base.isConstant(); 34 } 35 36 public final Object get (Object defaultValue) 37 { 38 return base.get(defaultValue); 39 } 40 41 public boolean isBound () 42 { 43 return base.isBound(); 44 } 45 46 protected Object coerce (Object newValue) 47 { 48 try 49 { 50 return converter.apply1(newValue); 51 } 52 catch (Throwable ex) 53 { 54 throw WrappedException.wrapIfNeeded(ex); 55 } 56 } 57 58 public final void set (Object newValue) 59 { 60 base.set(coerce(newValue)); 61 } 62 63 public Object setWithSave (Object newValue, CallContext ctx) 64 { 65 return base.setWithSave(coerce(newValue), ctx); 66 } 67 68 public void setRestore (Object oldValue, CallContext ctx) 69 { 70 base.setRestore(oldValue, ctx); 71 } 72 } 73 74 | Popular Tags |