PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://ambienttalk.googlecode.com/
Java | 81 lines | 31 code | 9 blank | 41 comment | 1 complexity | 0bcc1313d983a3d11c6715b1644892a4 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.ATStripe;
32import edu.vub.at.objects.coercion.NativeStripes;
33import edu.vub.at.objects.grammar.ATSymbol;
34
35/**
36 * XSelectorNotFound is thrown during lookup when a particular field cannot be
37 * found. It is equipped with a dedicated constructor to allow diagnosing the
38 * underlying problem.
39 * 
40 * @author smostinc
41 */
42public class XSelectorNotFound extends InterpreterException {
43
44	private static final long serialVersionUID = -9186247764999498158L;
45	
46	public final ATSymbol selector_;
47	public final ATObject inObject_;
48	
49	public XSelectorNotFound(ATSymbol selector, ATObject inObject) {
50		selector_ = selector;
51		inObject_ = inObject;
52	}
53	
54	public String getMessage() {
55		String obj;
56		try {
57			obj = inObject_.meta_print().javaValue;
58		} catch(InterpreterException e) {
59			obj = "<unprintable object: "+e.getMessage()+">";
60		}
61		return "Lookup failure : selector " + selector_ + " could not be found in "+ obj;
62	}
63	
64	public ATStripe getStripeType() {
65		return NativeStripes._SELECTORNOTFOUND_;
66	}
67	
68	/**
69	 * Several meta_* methods actually catch this exception to recover from a failed lookup by continuing
70	 * the search in an other object (e.g. parent objects, native objects, ...). When the lookup would
71	 * succeed and an XSelectorNotFound exception is raised because of another failed lookup, this alternate
72	 * behaviour should not be tried. Hence, when catching an XSelectorNotFound with the intention of redirecting
73	 * lookup, the exception handler should invoke this method to ensure that he is dealing with the right exception.
74	 */
75	public void catchOnlyIfSelectorEquals(ATSymbol sym) throws InterpreterException {
76		if (!selector_.base__opeql__opeql_(sym).asNativeBoolean().javaValue) {
77			throw this;
78		}
79	}
80	
81}