From 400b61e34a24df5a3938c335ca164f59e151b260 Mon Sep 17 00:00:00 2001 From: mdb Date: Mon, 17 Mar 2003 23:01:37 +0000 Subject: [PATCH] Redid nestable exceptions using standard Java support for same rather than Jakarta lang's support. No longer do we depend on Jakarta lang. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1068 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/io/NestableIOException.java | 133 +----------------- .../samskivert/io/PersistenceException.java | 11 +- .../util/ServiceUnavailableException.java | 11 +- 3 files changed, 16 insertions(+), 139 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/io/NestableIOException.java b/projects/samskivert/src/java/com/samskivert/io/NestableIOException.java index a28c4cbb..3ae7a74c 100644 --- a/projects/samskivert/src/java/com/samskivert/io/NestableIOException.java +++ b/projects/samskivert/src/java/com/samskivert/io/NestableIOException.java @@ -1,5 +1,5 @@ // -// $Id: NestableIOException.java,v 1.2 2002/04/01 01:57:03 mdb Exp $ +// $Id: NestableIOException.java,v 1.3 2003/03/17 23:01:37 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -24,37 +24,12 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.IOException; -import org.apache.commons.lang.exception.Nestable; -import org.apache.commons.lang.exception.NestableDelegate; - /** - * A base class for IO exceptions that can contain other exceptions. - * - * @see org.apache.commons.lang.exception.NestableException + * A convenience class for creating IO exceptions that are caused by other + * exceptions. */ -public class NestableIOException - extends IOException - implements Nestable +public class NestableIOException extends IOException { - /** - * Constructs a new NestableIOException without specified - * detail message. - */ - public NestableIOException () - { - } - - /** - * Constructs a new NestableIOException with specified - * detail message. - * - * @param msg the error message. - */ - public NestableIOException (String msg) - { - super(msg); - } - /** * Constructs a new NestableIOException with specified * nested Throwable. @@ -64,8 +39,7 @@ public class NestableIOException */ public NestableIOException (Throwable cause) { - super(); - _cause = cause; + initCause(cause); } /** @@ -79,101 +53,6 @@ public class NestableIOException public NestableIOException (String msg, Throwable cause) { super(msg); - _cause = cause; + initCause(cause); } - - /** - * Returns the nested exception. - * - * @see Nestable#getCause - */ - public Throwable getCause () - { - return _cause; - } - - /** - * Concatenates this exception's message with that of the nested - * exception and returns it. - * - * @see Nestable#getMessage - */ - public String getMessage () - { - StringBuffer msg = new StringBuffer(); - String ourMsg = super.getMessage(); - - // add our message (if there is one) - if (ourMsg != null) { - msg.append(ourMsg); - } - - // add our cause's message (if there is one) - if (_cause != null) { - String causeMsg = _cause.getMessage(); - if (causeMsg != null) { - if (ourMsg != null) { - msg.append(": "); - } - msg.append(causeMsg); - } - } - - return (msg.length() > 0 ? msg.toString() : null); - } - - /** - * Prints the stack trace of this exception (and the nested exception) - * the the standard error stream. - * - * @see Nestable#printStackTrace() - */ - public void printStackTrace () - { - _delegate.printStackTrace(); - } - - /** - * Prints the stack trace of this exception (and the nested exception) - * to the specified print stream. - * - * @param out PrintStream to use for output. - * - * @see Nestable#printStackTrace(PrintStream) - */ - public void printStackTrace (PrintStream out) - { - _delegate.printStackTrace(out); - } - - /** - * Prints the stack trace of this exception (and the nested exception) - * to the specified print writer. - * - * @param out PrintWriter to use for output. - * - * @see Nestable#printStackTrace(PrintWriter) - */ - public void printStackTrace (PrintWriter out) - { - _delegate.printStackTrace(out); - } - - /** - * Prints the stack trace only of the enclosing exception. - * - * @see Nestable#printPartialStackTrace(PrintWriter) - */ - public final void printPartialStackTrace (PrintWriter out) - { - super.printStackTrace(out); - } - - /** The helper instance which contains much of the code to which we - * delegate. */ - protected NestableDelegate _delegate = new NestableDelegate(this); - - /** Holds the reference to the exception or error that caused this - * exception to be thrown. */ - protected Throwable _cause = null; } diff --git a/projects/samskivert/src/java/com/samskivert/io/PersistenceException.java b/projects/samskivert/src/java/com/samskivert/io/PersistenceException.java index ee39ad6f..d3b51037 100644 --- a/projects/samskivert/src/java/com/samskivert/io/PersistenceException.java +++ b/projects/samskivert/src/java/com/samskivert/io/PersistenceException.java @@ -1,5 +1,5 @@ // -// $Id: PersistenceException.java,v 1.3 2002/04/01 01:57:03 mdb Exp $ +// $Id: PersistenceException.java,v 1.4 2003/03/17 23:01:37 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -20,8 +20,6 @@ package com.samskivert.io; -import org.apache.commons.lang.exception.NestableException; - /** * A persistence exception can be thrown when an error occurs in * underlying persistence code. By encapsulating errors, one retains the @@ -29,7 +27,7 @@ import org.apache.commons.lang.exception.NestableException; * affecting the interface to persistence services presented to the * application. */ -public class PersistenceException extends NestableException +public class PersistenceException extends Exception { /** * Constructs a persistence exception with the specified error @@ -46,7 +44,8 @@ public class PersistenceException extends NestableException */ public PersistenceException (String message, Exception cause) { - super(message, cause); + super(message); + initCause(cause); } /** @@ -55,6 +54,6 @@ public class PersistenceException extends NestableException */ public PersistenceException (Exception cause) { - super(cause); + initCause(cause); } } diff --git a/projects/samskivert/src/java/com/samskivert/util/ServiceUnavailableException.java b/projects/samskivert/src/java/com/samskivert/util/ServiceUnavailableException.java index b8bc11ef..99a57936 100644 --- a/projects/samskivert/src/java/com/samskivert/util/ServiceUnavailableException.java +++ b/projects/samskivert/src/java/com/samskivert/util/ServiceUnavailableException.java @@ -1,5 +1,5 @@ // -// $Id: ServiceUnavailableException.java,v 1.2 2002/04/01 01:57:03 mdb Exp $ +// $Id: ServiceUnavailableException.java,v 1.3 2003/03/17 23:01:37 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -20,8 +20,6 @@ package com.samskivert.util; -import org.apache.commons.lang.exception.NestableRuntimeException; - /** * The service unavailable exception can be thrown by any service that * relies on some other services which is currently not available. If a @@ -36,7 +34,7 @@ import org.apache.commons.lang.exception.NestableRuntimeException; * class of error recovery as if our service threw a * NullPointerException). */ -public class ServiceUnavailableException extends NestableRuntimeException +public class ServiceUnavailableException extends RuntimeException { /** * Constructs a service unavailable exception with the specified error @@ -53,7 +51,8 @@ public class ServiceUnavailableException extends NestableRuntimeException */ public ServiceUnavailableException (String message, Exception cause) { - super(message, cause); + super(message); + initCause(cause); } /** @@ -62,6 +61,6 @@ public class ServiceUnavailableException extends NestableRuntimeException */ public ServiceUnavailableException (Exception cause) { - super(cause); + initCause(cause); } }