KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > IndirectableLocation


1 // Copyright (c) 2004 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.mapping;
5
6 public abstract class IndirectableLocation extends Location
7 {
8   /** If <code>value==DIRECT_ON_SET</code>, break indirection on a <code>set</code>. */
9   protected static final Object JavaDoc DIRECT_ON_SET = new String JavaDoc("(direct-on-set)");
10
11   /** If <code>value</code> has this value, force indirection even
12    * for the <code>setWithSave</code> operation.
13    * Ignoring the restore aspect of a <code>fluid-let</code>, it is normally
14    * treated as closer to a <code>define</code> than to a <code>set</code>,
15    * in that we break the sharing with another <code>Environment</code>.
16    * Setting <code>value</code> to <code>INDIRECT_FLUIDS</code> means we do
17    * <em>not</em> want to break the indirection in this case. */

18   protected static final Object JavaDoc INDIRECT_FLUIDS = new String JavaDoc("(indirect-fluids)");
19
20   /** If non-null, operations are forwarded to the base location. */
21   protected Location base;
22
23   /** If <code>base</code> is null, the current value stored in
24    * this <code>Location</code>.
25    * If <code>base</code> is non-null, then <code>value</code> is generally
26    * ignored. However, the special value <code>DIRECT_ON_SET</code> means that
27    * writes change change <code>value</code> directly, instead of setting
28    * the value of <code>base</code>.
29    */

30   protected Object JavaDoc value;
31
32   public Symbol getKeySymbol ()
33   {
34     return base != null ? base.getKeySymbol() : null;
35   }
36
37   public Object JavaDoc getKeyProperty ()
38   {
39     return base != null ? base.getKeyProperty() : null;
40   }
41
42   public boolean isConstant ()
43   {
44     return base != null && base.isConstant();
45   }
46
47   public Location getBase ()
48   {
49     return base == null ? this : base.getBase();
50   }
51
52   public Location getBaseForce ()
53   {
54     if (base == null)
55       return new PlainLocation(getKeySymbol(), getKeyProperty(), value);
56     else
57       return base;
58   }
59
60   public void setBase (Location base)
61   {
62     this.base = base;
63     this.value = null;
64   }
65
66   /** Define this Location as an alias for some other Location. */
67   public void setAlias (Location base)
68   {
69     this.base = base;
70     this.value = INDIRECT_FLUIDS;
71   }
72
73   public void undefine ()
74   {
75     base = null;
76     value = UNBOUND;
77   }
78
79   public Environment getEnvironment ()
80   {
81     return (base instanceof NamedLocation
82         ? ((NamedLocation) base).getEnvironment()
83         : null);
84   }
85 }
86
Popular Tags