/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. */
  28. package edu.vub.at.objects.symbiosis;
  29. import edu.vub.at.exceptions.InterpreterException;
  30. import edu.vub.at.objects.ATStripe;
  31. import edu.vub.at.objects.coercion.NativeStripes;
  32. import java.io.PrintStream;
  33. import java.io.PrintWriter;
  34. import java.lang.reflect.Member;
  35. /**
  36. * An XJavaException AmbientTalk native exception wraps a Java exception.
  37. *
  38. * @author tvc
  39. */
  40. public final class XJavaException extends InterpreterException {
  41. private static final long serialVersionUID = 328306238980169679L;
  42. private final Throwable wrappedJavaException_;
  43. private final transient Object originatingObject_;
  44. private final transient Member originatingMethod_; // method or constructor in which exception originated
  45. public XJavaException(Object jObj, Member jMeth, Throwable exc) {
  46. wrappedJavaException_ = exc;
  47. originatingObject_ = jObj;
  48. originatingMethod_ = jMeth;
  49. }
  50. public XJavaException(Throwable exc) {
  51. wrappedJavaException_ = exc;
  52. originatingObject_ = null;
  53. originatingMethod_ = null;
  54. }
  55. // throwable interface implemented through composition with wrappedJavaException_
  56. public String getLocalizedMessage() {
  57. return wrappedJavaException_.getLocalizedMessage();
  58. }
  59. public Throwable getWrappedJavaException() {
  60. return wrappedJavaException_;
  61. }
  62. public String getMessage() {
  63. if (originatingObject_ != null) {
  64. return "Java exception from " + originatingObject_.toString() + "."
  65. + originatingMethod_.getName() + ": " + wrappedJavaException_.getClass().getName() + wrappedJavaException_.getMessage();
  66. } else if (originatingMethod_ != null) {
  67. return "Java exception from constructor " + originatingMethod_.getName()
  68. + ": " + wrappedJavaException_.getClass().getName() + wrappedJavaException_.getMessage();
  69. } else {
  70. return wrappedJavaException_.getMessage();
  71. }
  72. }
  73. // Backport from JDK 1.4 to 1.3
  74. // public StackTraceElement[] getStackTrace() {
  75. // return wrappedJavaException_.getStackTrace();
  76. // }
  77. // Backport from JDK 1.4 to 1.3
  78. // public synchronized Throwable initCause(Throwable arg) {
  79. // return wrappedJavaException_.initCause(arg);
  80. // }
  81. public void printStackTrace() {
  82. wrappedJavaException_.printStackTrace();
  83. }
  84. public void printStackTrace(PrintStream arg) {
  85. wrappedJavaException_.printStackTrace(arg);
  86. }
  87. public void printStackTrace(PrintWriter arg) {
  88. wrappedJavaException_.printStackTrace(arg);
  89. }
  90. // public void setStackTrace(StackTraceElement[] arg) {
  91. // wrappedJavaException_.setStackTrace(arg);
  92. // }
  93. public String toString() {
  94. return wrappedJavaException_.toString();
  95. }
  96. public ATStripe getStripeType() {
  97. return NativeStripes._JAVAEXCEPTION_;
  98. }
  99. }