KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > SharedLocation


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 /** A Location suitable when Environment or Location can be access by
7  * multiple threads. Accesses are synchronized. */

8
9 public class SharedLocation extends NamedLocation
10 {
11   int timestamp;
12
13   public SharedLocation (Symbol symbol, Object JavaDoc property, int timestamp)
14   {
15     super(symbol, property);
16     this.timestamp = timestamp;
17   }
18
19   public synchronized final Object JavaDoc get (Object JavaDoc defaultValue)
20   {
21     return base != null ? base.get(defaultValue)
22       : value == Location.UNBOUND ? defaultValue : value;
23   }
24
25   public synchronized boolean isBound ()
26   {
27     return base != null ? base.isBound() : value != Location.UNBOUND;
28   }
29
30   public synchronized final void set (Object JavaDoc newValue)
31   {
32     if (base == null)
33       value = newValue;
34     else if (value == DIRECT_ON_SET)
35       {
36     base = null;
37     value = newValue;
38       }
39     else if (base.isConstant())
40       getEnvironment().put(getKeySymbol(), getKeyProperty(), newValue);
41     else
42       base.set(newValue);
43   }
44
45 }
46
Popular Tags