KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > ProcLocation


1 // Copyright (c) 1998 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 whose current value is given by a Procedure call. */
7
8 public class ProcLocation extends Location
9 {
10   Procedure proc;
11   Object JavaDoc[] args;
12
13   public ProcLocation (Procedure proc, Object JavaDoc[] args)
14   {
15     this.proc = proc;
16     this.args = args;
17   }
18
19   public Object JavaDoc get (Object JavaDoc defaultValue)
20   {
21     try
22       {
23     return proc.applyN(args);
24       }
25     catch (RuntimeException JavaDoc ex)
26       {
27     throw ex;
28       }
29     catch (Error JavaDoc ex)
30       {
31     throw ex;
32       }
33     catch (Throwable JavaDoc ex)
34       {
35     throw new WrappedException(ex);
36       }
37   }
38
39   public void set (Object JavaDoc value)
40   {
41     int len = args.length;
42     Object JavaDoc[] xargs = new Object JavaDoc[len + 1];
43     xargs[len] = value;
44     System.arraycopy(args, 0, xargs, 0, len);
45     try
46       {
47     proc.setN(xargs);
48       }
49     catch (RuntimeException JavaDoc ex)
50       {
51     throw ex;
52       }
53     catch (Error JavaDoc ex)
54       {
55     throw ex;
56       }
57     catch (Throwable JavaDoc ex)
58       {
59     throw new WrappedException(ex);
60       }
61   }
62
63   public boolean isBound ()
64   {
65     return true;
66   }
67 }
68
69
Popular Tags