01: package gnu.mapping;
02:
03: /** This is the default Constraint for a simple variable Binding. */
04:
05: public class TrivialConstraint extends Constraint {
06: Environment environment;
07:
08: static TrivialConstraint instance;
09:
10: public static TrivialConstraint getInstance(Environment environment) {
11: TrivialConstraint result;
12: if (environment != null) {
13: result = environment.trivialConstraint;
14: if (result == null) {
15: result = new TrivialConstraint(environment);
16: environment.trivialConstraint = result;
17: }
18: } else {
19: result = instance;
20: if (result == null) {
21: result = new TrivialConstraint(null);
22: instance = result;
23: }
24: }
25: return result;
26: }
27:
28: public static TrivialConstraint getInstance(Binding binding) {
29: Constraint constraint = binding.constraint;
30: if (constraint instanceof TrivialConstraint)
31: return (TrivialConstraint) binding.constraint;
32: return getInstance(constraint.getEnvironment(binding));
33: }
34:
35: public TrivialConstraint(Environment environment) {
36: this .environment = environment;
37: }
38:
39: public boolean isBound(Binding binding) {
40: return true;
41: }
42:
43: public Object get(Binding binding, Object defaultValue) {
44: return binding.value;
45: }
46:
47: public void set(Binding binding, Object value) {
48: binding.value = value;
49: }
50:
51: public Environment getEnvironment(Binding binding) {
52: return environment;
53: }
54: }
|