diff --git a/java/external/src/javax/xml/datatype/DatatypeConfigurationException.java b/java/external/src/javax/xml/datatype/DatatypeConfigurationException.java index f88fbef..e02dea3 100644 --- a/java/external/src/javax/xml/datatype/DatatypeConfigurationException.java +++ b/java/external/src/javax/xml/datatype/DatatypeConfigurationException.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004 The Apache Software Foundation. + * Copyright 2003-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,12 @@ package javax.xml.datatype; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.lang.reflect.Method; + /** *
Indicates a serious configuration error.
* @@ -29,6 +35,15 @@ package javax.xml.datatype; */ public class DatatypeConfigurationException extends Exception { + + /** Stream Unique Identifier. */ + private static final long serialVersionUID = -1699373159027047238L; + + /** This field is required to store the cause on JDK 1.3 and below. */ + private Throwable causeOnJDK13OrBelow; + + /** Indicates whether this class is being used in a JDK 1.4 context. */ + private transient boolean isJDK14OrAbove = false; /** *Create a new DatatypeConfigurationException with
@@ -59,7 +74,8 @@ public class DatatypeConfigurationException extends Exception {
*/
public DatatypeConfigurationException(String message, Throwable cause) {
- super(message, cause);
+ super(message);
+ initCauseByReflection(cause);
}
/**
@@ -70,6 +86,87 @@ public class DatatypeConfigurationException extends Exception {
*/
public DatatypeConfigurationException(Throwable cause) {
- super(cause);
+ super(cause == null ? null : cause.toString());
+ initCauseByReflection(cause);
}
+
+ /**
+ * Print the the trace of methods from where the error
+ * originated. This will trace all nested exception
+ * objects, as well as this object.
+ */
+ public void printStackTrace() {
+ if (!isJDK14OrAbove && causeOnJDK13OrBelow != null) {
+ printStackTrace0(new PrintWriter(System.err, true));
+ }
+ else {
+ super.printStackTrace();
+ }
+ }
+
+ /**
+ * Print the the trace of methods from where the error
+ * originated. This will trace all nested exception
+ * objects, as well as this object.
+ * @param s The stream where the dump will be sent to.
+ */
+ public void printStackTrace(PrintStream s) {
+ if (!isJDK14OrAbove && causeOnJDK13OrBelow != null) {
+ printStackTrace0(new PrintWriter(s));
+ }
+ else {
+ super.printStackTrace(s);
+ }
+ }
+
+ /**
+ * Print the the trace of methods from where the error
+ * originated. This will trace all nested exception
+ * objects, as well as this object.
+ * @param s The writer where the dump will be sent to.
+ */
+ public void printStackTrace(PrintWriter s) {
+ if (!isJDK14OrAbove && causeOnJDK13OrBelow != null) {
+ printStackTrace0(s);
+ }
+ else {
+ super.printStackTrace(s);
+ }
+ }
+
+ private void printStackTrace0(PrintWriter s) {
+ causeOnJDK13OrBelow.printStackTrace(s);
+ s.println("------------------------------------------");
+ super.printStackTrace(s);
+ }
+
+ private void initCauseByReflection(Throwable cause) {
+ causeOnJDK13OrBelow = cause;
+ try {
+ Method m = this.getClass().getMethod("initCause", new Class[] {Throwable.class});
+ m.invoke(this, new Object[] {cause});
+ isJDK14OrAbove = true;
+ }
+ // Ignore exception
+ catch (Exception e) {}
+ }
+
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ try {
+ Method m1 = this.getClass().getMethod("getCause", new Class[] {});
+ Throwable cause = (Throwable) m1.invoke(this, new Object[] {});
+ if (causeOnJDK13OrBelow == null) {
+ causeOnJDK13OrBelow = cause;
+ }
+ else if (cause == null) {
+ Method m2 = this.getClass().getMethod("initCause", new Class[] {Throwable.class});
+ m2.invoke(this, new Object[] {causeOnJDK13OrBelow});
+ }
+ isJDK14OrAbove = true;
+ }
+ // Ignore exception
+ catch (Exception e) {}
+ }
}