KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > ConstrainedLocation


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

4 package gnu.mapping;
5
6 public class ConstrainedLocation extends Location
7 {
8   protected Location base;
9
10   protected Procedure converter;
11
12   public static ConstrainedLocation make (Location base,
13                       Procedure converter)
14   {
15     ConstrainedLocation cloc = new ConstrainedLocation();
16     cloc.base = base;
17     cloc.converter = converter;
18     return cloc;
19   }
20
21   public Symbol getKeySymbol ()
22   {
23     return base.getKeySymbol();
24   }
25
26   public Object JavaDoc getKeyProperty ()
27   {
28     return base.getKeyProperty();
29   }
30
31   public boolean isConstant ()
32   {
33     return base.isConstant();
34   }
35
36   public final Object JavaDoc get (Object JavaDoc defaultValue)
37   {
38     return base.get(defaultValue);
39   }
40   
41   public boolean isBound ()
42   {
43     return base.isBound();
44   }
45
46   protected Object JavaDoc coerce (Object JavaDoc newValue)
47   {
48     try
49       {
50     return converter.apply1(newValue);
51       }
52     catch (Throwable JavaDoc ex)
53       {
54     throw WrappedException.wrapIfNeeded(ex);
55       }
56   }
57
58   public final void set (Object JavaDoc newValue)
59   {
60     base.set(coerce(newValue));
61   }
62
63   public Object JavaDoc setWithSave (Object JavaDoc newValue, CallContext ctx)
64   {
65     return base.setWithSave(coerce(newValue), ctx);
66   }
67
68   public void setRestore (Object JavaDoc oldValue, CallContext ctx)
69   {
70     base.setRestore(oldValue, ctx);
71   }
72 }
73
74
Popular Tags