01: package gnu.mapping;
02:
03: public class IndirectConstraint extends Constraint {
04: public Object get(Binding binding, Object defaultValue) {
05: try {
06: return ((Procedure) binding.value).apply0();
07: } catch (RuntimeException ex) {
08: throw ex;
09: } catch (Error ex) {
10: throw ex;
11: } catch (Throwable ex) {
12: throw new WrappedException(ex);
13: }
14: }
15:
16: public void set(Binding binding, Object value) {
17: try {
18: ((Procedure) (HasSetter) binding.value).set0(value);
19: } catch (RuntimeException ex) {
20: throw ex;
21: } catch (Error ex) {
22: throw ex;
23: } catch (Throwable ex) {
24: throw new WrappedException(ex);
25: }
26: }
27:
28: public static void define(String name, Procedure location) {
29: define(name, location, Environment.getCurrent());
30: }
31:
32: public static void define(String name, Procedure location,
33: Environment env) {
34: Binding binding = env.getBinding(name);
35: synchronized (binding) {
36: binding.value = location;
37: binding.constraint = new IndirectConstraint();
38: }
39: }
40:
41: public static void define(Binding binding, Procedure location) {
42: synchronized (binding) {
43: binding.value = location;
44: binding.constraint = new IndirectConstraint();
45: }
46: }
47: }
|