01: // Copyright (c) 2000 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.mapping;
05:
06: /** The value field of a AliasConstraint points to another Binding. */
07:
08: public class AliasConstraint extends Constraint {
09: public Object get(Binding binding, Object defaultValue) {
10: if (binding.value instanceof Binding)
11: return ((Binding) binding.value).get(defaultValue);
12: try {
13: return ((Location) binding.value).get();
14: } catch (UnboundSymbol ex) {
15: return defaultValue;
16: }
17: }
18:
19: public void set(Binding binding, Object value) {
20: ((Location) binding.value).set(value);
21: }
22:
23: public boolean isBound(Binding binding) {
24: return ((Location) binding.value).isBound();
25: }
26:
27: public Object getFunctionValue(Binding binding) {
28: return ((Binding) binding.value).getFunctionValue();
29: }
30:
31: public static void define(Binding binding, Location location) {
32: synchronized (binding) {
33: binding.value = location;
34: binding.constraint = new AliasConstraint(); // FIXME share?
35: }
36: }
37: }
|