/interpreter/tags/at2dist090708/src/edu/vub/at/exceptions/XSelectorNotFound.java
Java | 100 lines | 37 code | 11 blank | 52 comment | 1 complexity | 77f911e6dc34518fbc7ec6eb273fd2b8 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 */ 28package edu.vub.at.exceptions; 29 30import edu.vub.at.objects.ATObject; 31import edu.vub.at.objects.ATTypeTag; 32import edu.vub.at.objects.coercion.NativeTypeTags; 33import edu.vub.at.objects.grammar.ATSymbol; 34 35/** 36 * XSelectorNotFound is thrown during lookup when a particular slot cannot be found. It is 37 * equipped with a dedicated constructor to allow diagnosing the underlying problem. 38 * 39 * @author smostinc 40 */ 41public class XSelectorNotFound extends InterpreterException { 42 43 private static final long serialVersionUID = -9186247764999498158L; 44 45 private final ATSymbol selector_; 46 private final ATObject inObject_; 47 48 /** 49 * Constructor reporting that a particular slot could not be found. 50 * @param selector the name of the slot being sought for. 51 * @param inObject the object from which the slot was being selected. 52 */ 53 public XSelectorNotFound(ATSymbol selector, ATObject inObject) { 54 selector_ = selector; 55 inObject_ = inObject; 56 } 57 58 public String getMessage() { 59 String obj; 60 try { 61 obj = inObject_.meta_print().javaValue; 62 } catch(InterpreterException e) { 63 obj = "<unprintable object: "+e.getMessage()+">"; 64 } 65 return "Lookup failure : selector " + selector_ + " could not be found in "+ obj; 66 } 67 68 public ATTypeTag getType() { 69 return NativeTypeTags._SELECTORNOTFOUND_; 70 } 71 72 /** 73 * Rethrows the exception unless the missing selector equals the one given in this method. Rationale: 74 * Several meta_* methods actually catch this exception to recover from a failed lookup by continuing 75 * the search in an other object (e.g. parent objects, native objects, ...). When the lookup would 76 * succeed and an XSelectorNotFound exception is raised because of another failed lookup, this alternate 77 * behaviour should not be tried. Hence, when catching an XSelectorNotFound with the intention of redirecting 78 * lookup, the exception handler should invoke this method to ensure that he is dealing with the right exception. 79 */ 80 public void catchOnlyIfSelectorEquals(ATSymbol sym) throws InterpreterException { 81 if (!selector_.equals(sym)) { 82 throw this; 83 } 84 } 85 86 /** 87 * @return the selector that could not be located. 88 */ 89 public ATSymbol getSelector() { 90 return selector_; 91 } 92 93 /** 94 * @return the object in which the selector could not be located. 95 */ 96 public ATObject getInObject() { 97 return inObject_; 98 } 99 100}