ProcLocation.java 993 B

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