01: // Copyright (c) 1999 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.mapping;
05:
06: /** This Constraint searches a thread's stack of FluidBindings. */
07:
08: public class FluidConstraint extends Constraint {
09: /** The original Constraint from the Binding.
10: * Use this to get the default value if there is no fluid binding
11: * in the current thread. */
12: Constraint savedConstraint;
13:
14: /** Number of active FluidBinding objects for our Binding. */
15: int referenceCount;
16:
17: public FluidConstraint(Constraint savedConstraint) {
18: this .savedConstraint = savedConstraint;
19: }
20:
21: FluidBinding find(Binding binding) {
22: FluidBinding fl = Future.getFluids();
23: for (; fl != null; fl = fl.previous) {
24: if (fl.binding == binding)
25: return fl;
26: }
27: return null;
28: }
29:
30: public Object get(Binding binding, Object defaultValue) {
31: FluidBinding fl = find(binding);
32: if (fl == null)
33: return savedConstraint.get(binding, defaultValue);
34: else
35: return fl.value;
36: }
37:
38: public void set(Binding binding, Object value) {
39: FluidBinding fl = find(binding);
40: if (fl == null)
41: savedConstraint.set(binding, value);
42: else
43: fl.value = value;
44: }
45:
46: }
|