Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 72E1A7A0D for ; Sun, 4 Sep 2011 14:39:11 +0000 (UTC) Received: (qmail 11720 invoked by uid 500); 4 Sep 2011 14:39:10 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 11336 invoked by uid 500); 4 Sep 2011 14:39:08 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 11312 invoked by uid 99); 4 Sep 2011 14:39:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Sep 2011 14:39:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Sep 2011 14:39:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A60352388900 for ; Sun, 4 Sep 2011 14:38:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1165034 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/exception/ main/java/org/apache/commons/math/exception/util/ test/java/org/apache/commons/math/exception/util/ Date: Sun, 04 Sep 2011 14:38:41 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110904143841.A60352388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Sun Sep 4 14:38:40 2011 New Revision: 1165034 URL: http://svn.apache.org/viewvc?rev=1165034&view=rev Log: moved the binding of the underlying exception from ExceptionContextProvider to ExceptionContext, as diccussed on the dev list Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContext.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContextProvider.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/ExceptionContextTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java?rev=1165034&r1=1165033&r2=1165034&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java Sun Sep 4 14:38:40 2011 @@ -35,12 +35,13 @@ public class MathArithmeticException ext /** Serializable version Id. */ private static final long serialVersionUID = -6024911025449780478L; /** Context. */ - private final ExceptionContext context = new ExceptionContext(); + private final ExceptionContext context; /** * Default constructor. */ public MathArithmeticException() { + context = new ExceptionContext(this); context.addMessage(LocalizedFormats.ARITHMETIC_EXCEPTION); } @@ -53,6 +54,7 @@ public class MathArithmeticException ext */ public MathArithmeticException(Localizable pattern, Object ... args) { + context = new ExceptionContext(this); context.addMessage(pattern, args); } @@ -62,11 +64,6 @@ public class MathArithmeticException ext } /** {@inheritDoc} */ - public Throwable getException() { - return this; - } - - /** {@inheritDoc} */ @Override public String getMessage() { return context.getMessage(); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=1165034&r1=1165033&r2=1165034&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java Sun Sep 4 14:38:40 2011 @@ -34,7 +34,7 @@ public class MathIllegalArgumentExceptio /** Serializable version Id. */ private static final long serialVersionUID = -6024911025449780478L; /** Context. */ - private final ExceptionContext context = new ExceptionContext(); + private final ExceptionContext context; /** * @param pattern Message pattern explaining the cause of the error. @@ -42,6 +42,7 @@ public class MathIllegalArgumentExceptio */ public MathIllegalArgumentException(Localizable pattern, Object ... args) { + context = new ExceptionContext(this); context.addMessage(pattern, args); } @@ -51,11 +52,6 @@ public class MathIllegalArgumentExceptio } /** {@inheritDoc} */ - public Throwable getException() { - return this; - } - - /** {@inheritDoc} */ @Override public String getMessage() { return context.getMessage(); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java?rev=1165034&r1=1165033&r2=1165034&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java Sun Sep 4 14:38:40 2011 @@ -33,7 +33,7 @@ public class MathIllegalStateException e /** Serializable version Id. */ private static final long serialVersionUID = -6024911025449780478L; /** Context. */ - private final ExceptionContext context = new ExceptionContext(); + private final ExceptionContext context; /** * Simple constructor. @@ -43,6 +43,7 @@ public class MathIllegalStateException e */ public MathIllegalStateException(Localizable pattern, Object ... args) { + context = new ExceptionContext(this); context.addMessage(pattern, args); } @@ -57,6 +58,7 @@ public class MathIllegalStateException e Localizable pattern, Object ... args) { super(cause); + context = new ExceptionContext(this); context.addMessage(pattern, args); } @@ -73,11 +75,6 @@ public class MathIllegalStateException e } /** {@inheritDoc} */ - public Throwable getException() { - return this; - } - - /** {@inheritDoc} */ @Override public String getMessage() { return context.getMessage(); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java?rev=1165034&r1=1165033&r2=1165034&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java Sun Sep 4 14:38:40 2011 @@ -35,7 +35,7 @@ public class MathUnsupportedOperationExc /** Serializable version Id. */ private static final long serialVersionUID = -6024911025449780478L; /** Context. */ - private final ExceptionContext context = new ExceptionContext(); + private final ExceptionContext context; /** * Default constructor. @@ -50,6 +50,7 @@ public class MathUnsupportedOperationExc */ public MathUnsupportedOperationException(Localizable pattern, Object ... args) { + context = new ExceptionContext(this); context.addMessage(pattern, args); } @@ -59,11 +60,6 @@ public class MathUnsupportedOperationExc } /** {@inheritDoc} */ - public Throwable getException() { - return this; - } - - /** {@inheritDoc} */ @Override public String getMessage() { return context.getMessage(); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java?rev=1165034&r1=1165033&r2=1165034&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java Sun Sep 4 14:38:40 2011 @@ -37,12 +37,13 @@ public class MathUserException extends R /** Serializable version Id. */ private static final long serialVersionUID = -6024911025449780478L; /** Context. */ - private final ExceptionContext context = new ExceptionContext(); + private final ExceptionContext context; /** * Build an exception with a default message. */ public MathUserException() { + context = new ExceptionContext(this); context.addMessage(LocalizedFormats.USER_EXCEPTION); } @@ -52,6 +53,7 @@ public class MathUserException extends R */ public MathUserException(final Throwable cause) { super(cause); + context = new ExceptionContext(this); context.addMessage(LocalizedFormats.USER_EXCEPTION); } @@ -63,6 +65,7 @@ public class MathUserException extends R */ public MathUserException(final Localizable pattern, final Object ... arguments) { + context = new ExceptionContext(this); context.addMessage(pattern, arguments); } @@ -77,6 +80,7 @@ public class MathUserException extends R final Localizable pattern, final Object ... arguments) { super(cause); + context = new ExceptionContext(this); context.addMessage(pattern, arguments); } @@ -86,11 +90,6 @@ public class MathUserException extends R } /** {@inheritDoc} */ - public Throwable getException() { - return this; - } - - /** {@inheritDoc} */ @Override public String getMessage() { return context.getMessage(); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContext.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContext.java?rev=1165034&r1=1165033&r2=1165034&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContext.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContext.java Sun Sep 4 14:38:40 2011 @@ -40,19 +40,40 @@ public class ExceptionContext implements /** Serializable version Id. */ private static final long serialVersionUID = -6024911025449780478L; /** + * The throwable to which this context refers to. + */ + private Throwable throwable; + /** * Various informations that enrich the informative message. */ - private List msgPatterns = new ArrayList(); + private List msgPatterns; /** * Various informations that enrich the informative message. * The arguments will replace the corresponding place-holders in * {@link #msgPatterns}. */ - private List msgArguments = new ArrayList(); + private List msgArguments; /** * Arbitrary context information. */ - private Map context = new HashMap(); + private Map context; + + /** Simple constructor. + * @param throwable the exception this context refers too + */ + public ExceptionContext(final Throwable throwable) { + this.throwable = throwable; + msgPatterns = new ArrayList(); + msgArguments = new ArrayList(); + context = new HashMap(); + } + + /** Get a reference to the exception to which the context relates. + * @return a reference to the exception to which the context relates + */ + public Throwable getThrowable() { + return throwable; + } /** * Adds a message. @@ -173,6 +194,7 @@ public class ExceptionContext implements */ private void writeObject(ObjectOutputStream out) throws IOException { + out.writeObject(throwable); serializeMessages(out); serializeContext(out); } @@ -186,6 +208,7 @@ public class ExceptionContext implements private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + throwable = (Throwable) in.readObject(); deSerializeMessages(in); deSerializeContext(in); } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContextProvider.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContextProvider.java?rev=1165034&r1=1165033&r2=1165034&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContextProvider.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/ExceptionContextProvider.java Sun Sep 4 14:38:40 2011 @@ -31,9 +31,4 @@ public interface ExceptionContextProvide */ ExceptionContext getContext(); - /** Get a reference to the exception to which the context relates. - * @return a reference to the exception to which the context relates - */ - Throwable getException(); - } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/ExceptionContextTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/ExceptionContextTest.java?rev=1165034&r1=1165033&r2=1165034&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/ExceptionContextTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/ExceptionContextTest.java Sun Sep 4 14:38:40 2011 @@ -35,7 +35,7 @@ import org.junit.Test; public class ExceptionContextTest { @Test public void testMessageChain() { - final ExceptionContext c = new ExceptionContext(); + final ExceptionContext c = new ExceptionContext(new Exception("oops")); final String sep = " | "; // Non-default separator. final String m1 = "column index (0)"; c.addMessage(LocalizedFormats.COLUMN_INDEX, 0); @@ -50,14 +50,14 @@ public class ExceptionContextTest { @Test public void testNoArgAddMessage() { - final ExceptionContext c = new ExceptionContext(); + final ExceptionContext c = new ExceptionContext(new Exception("hello")); c.addMessage(LocalizedFormats.SIMPLE_MESSAGE); Assert.assertEquals(c.getMessage(), "{0}"); } @Test public void testContext() { - final ExceptionContext c = new ExceptionContext(); + final ExceptionContext c = new ExceptionContext(new Exception("bye")); final String[] keys = {"Key 1", "Key 2"}; final Object[] values = {"Value 1", Integer.valueOf(2)}; @@ -82,7 +82,7 @@ public class ExceptionContextTest { public void testSerialize() throws IOException, ClassNotFoundException { - final ExceptionContext cOut = new ExceptionContext(); + final ExceptionContext cOut = new ExceptionContext(new Exception("Apache")); cOut.addMessage(LocalizedFormats.COLUMN_INDEX, 0); cOut.setValue("Key 1", Integer.valueOf(0)); @@ -102,7 +102,7 @@ public class ExceptionContextTest { @Test public void testSerializeUnserializable() { - final ExceptionContext cOut = new ExceptionContext(); + final ExceptionContext cOut = new ExceptionContext(new Exception("Apache Commons Math")); cOut.addMessage(LocalizedFormats.SIMPLE_MESSAGE, "OK"); cOut.addMessage(LocalizedFormats.SIMPLE_MESSAGE, new Unserializable()); String key = "Key 1";