PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/interpreter/tags/at2-build060407/src/edu/vub/at/objects/symbiosis/XJavaException.java

http://ambienttalk.googlecode.com/
Java | 118 lines | 55 code | 19 blank | 44 comment | 6 complexity | 6e33313c7a1de0e1f90cb45a39cc9344 MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * XJavaException.java created on 3-nov-2006 at 11:43:15
  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.objects.symbiosis;
 29
 30import edu.vub.at.exceptions.InterpreterException;
 31import edu.vub.at.objects.ATStripe;
 32import edu.vub.at.objects.coercion.NativeStripes;
 33
 34import java.io.PrintStream;
 35import java.io.PrintWriter;
 36import java.lang.reflect.Member;
 37
 38/**
 39 * An XJavaException AmbientTalk native exception wraps a Java exception.
 40 * 
 41 * @author tvc
 42 */
 43public final class XJavaException extends InterpreterException {
 44
 45	private static final long serialVersionUID = 328306238980169679L;
 46
 47	private final Throwable wrappedJavaException_;
 48	private final transient Object originatingObject_;
 49	private final transient Member originatingMethod_; // method or constructor in which exception originated
 50	
 51	public XJavaException(Object jObj, Member jMeth, Throwable exc) {
 52		wrappedJavaException_ = exc;
 53		originatingObject_ = jObj;
 54		originatingMethod_ = jMeth;
 55	}
 56	
 57	public XJavaException(Throwable exc) {
 58		wrappedJavaException_ = exc;
 59		originatingObject_ = null;
 60		originatingMethod_ = null;
 61	}
 62	
 63	// throwable interface implemented through composition with wrappedJavaException_
 64
 65	public String getLocalizedMessage() {
 66		return wrappedJavaException_.getLocalizedMessage();
 67	}
 68	
 69	public Throwable getWrappedJavaException() {
 70		return wrappedJavaException_;
 71	}
 72
 73	public String getMessage() {
 74		if (originatingObject_ != null) {
 75			return "Java exception from " + originatingObject_.toString() + "."
 76			           + originatingMethod_.getName() + ": " + wrappedJavaException_.getClass().getName() + wrappedJavaException_.getMessage();
 77		} else if (originatingMethod_ != null) {
 78			return "Java exception from constructor " + originatingMethod_.getName()
 79			   + ": " + wrappedJavaException_.getClass().getName() + wrappedJavaException_.getMessage();
 80		} else {
 81			return wrappedJavaException_.getMessage();
 82		}
 83	}
 84//  Backport from JDK 1.4 to 1.3
 85//	public StackTraceElement[] getStackTrace() {
 86//		return wrappedJavaException_.getStackTrace();
 87//	}
 88
 89//  Backport from JDK 1.4 to 1.3
 90//	public synchronized Throwable initCause(Throwable arg) {
 91//		return wrappedJavaException_.initCause(arg);
 92//	}
 93
 94	public void printStackTrace() {
 95		wrappedJavaException_.printStackTrace();
 96	}
 97
 98	public void printStackTrace(PrintStream arg) {
 99		wrappedJavaException_.printStackTrace(arg);
100	}
101
102	public void printStackTrace(PrintWriter arg) {
103		wrappedJavaException_.printStackTrace(arg);
104	}
105
106//	public void setStackTrace(StackTraceElement[] arg) {
107//		wrappedJavaException_.setStackTrace(arg);
108//	}
109
110	public String toString() {
111		return wrappedJavaException_.toString();
112	}
113	
114	public ATStripe getStripeType() {
115		return NativeStripes._JAVAEXCEPTION_;
116	}
117	
118}