01: // Copyright (c) 1998 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.mapping;
05:
06: /* A Location whose current value is given by a Procedure call. */
07:
08: public class ProcLocation extends Location {
09: Procedure proc;
10: Object[] args;
11:
12: public ProcLocation(Procedure proc, Object[] args) {
13: this .proc = proc;
14: this .args = args;
15: }
16:
17: public Object get(Object defaultValue) {
18: try {
19: return proc.applyN(args);
20: } catch (RuntimeException ex) {
21: throw ex;
22: } catch (Error ex) {
23: throw ex;
24: } catch (Throwable ex) {
25: throw new WrappedException(ex);
26: }
27: }
28:
29: public void set(Object value) {
30: int len = args.length;
31: Object[] xargs = new Object[len + 1];
32: xargs[len] = value;
33: System.arraycopy(args, 0, xargs, 0, len);
34: try {
35: proc.setN(xargs);
36: } catch (RuntimeException ex) {
37: throw ex;
38: } catch (Error ex) {
39: throw ex;
40: } catch (Throwable ex) {
41: throw new WrappedException(ex);
42: }
43: }
44:
45: public boolean isBound() {
46: return true;
47: }
48: }
|