commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
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 GMT
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<Localizable> msgPatterns = new ArrayList<Localizable>();
+    private List<Localizable> msgPatterns;
     /**
      * Various informations that enrich the informative message.
      * The arguments will replace the corresponding place-holders in
      * {@link #msgPatterns}.
      */
-    private List<Object[]> msgArguments = new ArrayList<Object[]>();
+    private List<Object[]> msgArguments;
     /**
      * Arbitrary context information.
      */
-    private Map<String, Object> context = new HashMap<String, Object>();
+    private Map<String, Object> context;
+
+    /** Simple constructor.
+     * @param throwable the exception this context refers too
+     */
+    public ExceptionContext(final Throwable throwable) {
+        this.throwable = throwable;
+        msgPatterns    = new ArrayList<Localizable>();
+        msgArguments   = new ArrayList<Object[]>();
+        context        = new HashMap<String, Object>();
+    }
+
+    /** 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";



Mime
View raw message