01: // Copyright (c) 2005 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.mapping;
05:
06: public class ConstrainedLocation extends Location {
07: protected Location base;
08:
09: protected Procedure converter;
10:
11: public static ConstrainedLocation make(Location base,
12: Procedure converter) {
13: ConstrainedLocation cloc = new ConstrainedLocation();
14: cloc.base = base;
15: cloc.converter = converter;
16: return cloc;
17: }
18:
19: public Symbol getKeySymbol() {
20: return base.getKeySymbol();
21: }
22:
23: public Object getKeyProperty() {
24: return base.getKeyProperty();
25: }
26:
27: public boolean isConstant() {
28: return base.isConstant();
29: }
30:
31: public final Object get(Object defaultValue) {
32: return base.get(defaultValue);
33: }
34:
35: public boolean isBound() {
36: return base.isBound();
37: }
38:
39: protected Object coerce(Object newValue) {
40: try {
41: return converter.apply1(newValue);
42: } catch (Throwable ex) {
43: throw WrappedException.wrapIfNeeded(ex);
44: }
45: }
46:
47: public final void set(Object newValue) {
48: base.set(coerce(newValue));
49: }
50:
51: public Object setWithSave(Object newValue, CallContext ctx) {
52: return base.setWithSave(coerce(newValue), ctx);
53: }
54:
55: public void setRestore(Object oldValue, CallContext ctx) {
56: base.setRestore(oldValue, ctx);
57: }
58: }
|