/interpreter/tags/at2-build270707/src/edu/vub/at/exceptions/XSelectorNotFound.java

http://ambienttalk.googlecode.com/ · Java · 100 lines · 37 code · 11 blank · 52 comment · 1 complexity · 0961354d0a0af82b4d3f0eaf519d033a MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * XSelectorNotFound.java created on Jul 23, 2006 at 3:20:22 PM
  4. * (c) Programming Technology Lab, 2006 - 2007
  5. * Authors: Tom Van Cutsem & Stijn Mostinckx
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use,
  11. * copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following
  14. * conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  21. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  23. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  24. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. package edu.vub.at.exceptions;
  29. import edu.vub.at.objects.ATObject;
  30. import edu.vub.at.objects.ATTypeTag;
  31. import edu.vub.at.objects.coercion.NativeTypeTags;
  32. import edu.vub.at.objects.grammar.ATSymbol;
  33. /**
  34. * XSelectorNotFound is thrown during lookup when a particular slot cannot be found. It is
  35. * equipped with a dedicated constructor to allow diagnosing the underlying problem.
  36. *
  37. * @author smostinc
  38. */
  39. public class XSelectorNotFound extends InterpreterException {
  40. private static final long serialVersionUID = -9186247764999498158L;
  41. private final ATSymbol selector_;
  42. private final ATObject inObject_;
  43. /**
  44. * Constructor reporting that a particular slot could not be found.
  45. * @param selector the name of the slot being sought for.
  46. * @param inObject the object from which the slot was being selected.
  47. */
  48. public XSelectorNotFound(ATSymbol selector, ATObject inObject) {
  49. selector_ = selector;
  50. inObject_ = inObject;
  51. }
  52. public String getMessage() {
  53. String obj;
  54. try {
  55. obj = inObject_.meta_print().javaValue;
  56. } catch(InterpreterException e) {
  57. obj = "<unprintable object: "+e.getMessage()+">";
  58. }
  59. return "Lookup failure : selector " + selector_ + " could not be found in "+ obj;
  60. }
  61. public ATTypeTag getType() {
  62. return NativeTypeTags._SELECTORNOTFOUND_;
  63. }
  64. /**
  65. * Rethrows the exception unless the missing selector equals the one given in this method. Rationale:
  66. * Several meta_* methods actually catch this exception to recover from a failed lookup by continuing
  67. * the search in an other object (e.g. parent objects, native objects, ...). When the lookup would
  68. * succeed and an XSelectorNotFound exception is raised because of another failed lookup, this alternate
  69. * behaviour should not be tried. Hence, when catching an XSelectorNotFound with the intention of redirecting
  70. * lookup, the exception handler should invoke this method to ensure that he is dealing with the right exception.
  71. */
  72. public void catchOnlyIfSelectorEquals(ATSymbol sym) throws InterpreterException {
  73. if (!selector_.base__opeql__opeql_(sym).asNativeBoolean().javaValue) {
  74. throw this;
  75. }
  76. }
  77. /**
  78. * @return the selector that could not be located.
  79. */
  80. public ATSymbol getSelector() {
  81. return selector_;
  82. }
  83. /**
  84. * @return the object in which the selector could not be located.
  85. */
  86. public ATObject getInObject() {
  87. return inObject_;
  88. }
  89. }