commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1297032 - in /commons/proper/chain/trunk: configuration/src/test/java/org/apache/commons/chain2/config/ core/src/main/java/org/apache/commons/chain2/ core/src/main/java/org/apache/commons/chain2/generic/ core/src/main/java/org/apache/commo...
Date Mon, 05 Mar 2012 12:35:11 GMT
Author: simonetripodi
Date: Mon Mar  5 12:35:10 2012
New Revision: 1297032

URL: http://svn.apache.org/viewvc?rev=1297032&view=rev
Log:
[CHAIN-67] Refactor of explicit Exception throws to a RuntimeException type - patch submitted
by Elijah Zupancic

Added:
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java
  (with props)
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java
  (with props)
Modified:
    commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/TestCommand.java
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Command.java
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/CopyCommand.java
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchCommand.java
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchLookupCommand.java
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/LookupCommand.java
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/RemoveCommand.java
    commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ChainBase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchCommandTestCase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchLookupCommandTestCase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/LookupCommandTestCase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/AddingCommand.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogFactoryBaseTestCase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ChainBaseTestCase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ContextBaseTestCase.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingCommand.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingFilter.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ExceptionCommand.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingCommand.java
    commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingFilter.java
    commons/proper/chain/trunk/src/changes/changes.xml
    commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractGetLocaleCommand.java
    commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractSetLocaleCommand.java
    commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/portlet/PortletWebContextTestCase.java
    commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/servlet/ServletWebContextTestCase.java

Modified: commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/TestCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/TestCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/TestCommand.java
(original)
+++ commons/proper/chain/trunk/configuration/src/test/java/org/apache/commons/chain2/config/TestCommand.java
Mon Mar  5 12:35:10 2012
@@ -47,7 +47,7 @@ public class TestCommand implements Comm
     }
 
 
-    public boolean execute(Context<String, Object> context) throws Exception {
+    public boolean execute(Context<String, Object> context) {
     return (false);
     }
 

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java (original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Chain.java Mon
Mar  5 12:35:10 2012
@@ -116,7 +116,7 @@ public interface Chain<K, V, C extends M
      *  of this {@link Context} should be delegated to a subsequent
      *  {@link Command} in an enclosing {@link Chain}
      */
-    boolean execute(C context) throws Exception;
+    boolean execute(C context);
 
 
 }

Added: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java?rev=1297032&view=auto
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java
(added)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java
Mon Mar  5 12:35:10 2012
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.chain2;
+
+import java.util.Map;
+
+/**
+ * Runtime Exception that wraps an underlying exception thrown during the
+ * execution of a {@link Command} or {@link Chain}.
+ *
+ * @author Elijah Zupancic
+ * @version $Id$
+ * @since 2.0
+ */
+public class ChainException extends RuntimeException {
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Context used when exception occurred.
+     */
+    private final Map<?, ?> context;
+
+    /**
+     * Command that failed when exception occurred.
+     */
+    private final Command<?, ?, ?> failedCommand;
+
+    public ChainException(String message) {
+        super(message);
+        this.context = null;
+        this.failedCommand = null;
+    }
+
+    public ChainException(String message, Throwable cause) {
+        super(message, cause);
+        this.context = null;
+        this.failedCommand = null;
+    }
+
+    /**
+     * Constructs a new ChainException with references to the {@link Context}
+     * and {@link Command} associated with the exception being wrapped (cause).
+     * @param   message   the detail message. The detail message is saved for
+     *          later retrieval by the {@link #getMessage()} method.
+     * @param cause the cause (which is saved for later retrieval by the
+     *         {@link #getCause()} method).  (A <tt>null</tt> value is
+     *         permitted, and indicates that the cause is nonexistent or
+     *         unknown.)
+     * @param context The Context object passed to the {@link Command} in
+     *                which the exception occurred.
+     * @param failedCommand The Command object in which the exception was
+     *                      thrown.
+     */
+    public <K, V, C extends Map<K, V>> ChainException(String message, Throwable
cause,
+                                                      C context, Command<K, V, C> failedCommand)
{
+        super(message, cause);
+        this.context = context;
+        this.failedCommand = failedCommand;
+    }
+
+    /**
+     * @return The context object passed when the {@link Command}
+     * threw an exception.
+     */
+    public Map<?, ?> getContext() {
+        return context;
+    }
+
+    /**
+     * @return The {@link Command} object in which the original exception was
+     * thrown.
+     */
+    public Command<?, ?, ?> getFailedCommand() {
+        return failedCommand;
+    }
+}

Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/ChainException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Command.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Command.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Command.java (original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/Command.java Mon
Mar  5 12:35:10 2012
@@ -113,7 +113,7 @@ public interface Command<K, V, C extends
      * @param context The {@link Context} to be processed by this
      *  {@link Command}
      *
-     * @exception Exception general purpose exception return
+     * @exception ChainException general purpose exception return
      *  to indicate abnormal termination
      * @exception IllegalArgumentException if <code>context</code>
      *  is <code>null</code>
@@ -123,6 +123,6 @@ public interface Command<K, V, C extends
      *  of this {@link Context} should be delegated to a subsequent
      *  {@link Command} in an enclosing {@link Chain}
      */
-    boolean execute(C context) throws Exception;
+    boolean execute(C context);
 
 }

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/CopyCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/CopyCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/CopyCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/CopyCommand.java
Mon Mar  5 12:35:10 2012
@@ -17,11 +17,11 @@
 package org.apache.commons.chain2.generic;
 
 
-import java.util.Map;
-
 import org.apache.commons.chain2.Command;
 import org.apache.commons.chain2.Context;
 
+import java.util.Map;
+
 
 /**
  * <p>Copy a specified literal value, or a context attribute stored under
@@ -129,9 +129,9 @@ public class CopyCommand<K, V, C extends
      * @param context {@link Context} in which we are operating
      *
      * @return <code>false</code> so that processing will continue
-     * @throws Exception in the if an error occurs during execution.
+     * @throws org.apache.commons.chain2.ChainException in the if an error occurs during
execution.
      */
-    public boolean execute(C context) throws Exception {
+    public boolean execute(C context) {
 
         V value = this.value;
 

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchCommand.java
Mon Mar  5 12:35:10 2012
@@ -59,27 +59,30 @@ public abstract class DispatchCommand<K,
      * @param context The Context to be processed by this Command.
      * @return the result of method being dispatched to.
      * @throws IllegalStateException if neither 'method' nor 'methodKey' properties are defined
-     * @throws Exception if any is thrown by the invocation.  Note that if invoking the method
+     * @throws DispatchException if any is thrown by the invocation. Note that if invoking
the method
      * results in an InvocationTargetException, the cause of that exception is thrown instead
of
      * the exception itself, unless the cause is an <code>Error</code> or other
<code>Throwable</code>
      * which is not an <code>Exception</code>.
      */
-    public boolean execute(C context) throws Exception {
+    public boolean execute(C context) {
 
         if (this.getMethod() == null && this.getMethodKey() == null) {
             throw new IllegalStateException("Neither 'method' nor 'methodKey' properties
are defined ");
         }
 
-        Method methodObject = extractMethod(context);
-
         try {
-            return evaluateResult(methodObject.invoke(this, getArguments(context)));
+
+            Method methodObject = extractMethod(context);
+            return evaluateResult(methodObject.invoke(this,
+                    getArguments(context)));
+
+        } catch (NoSuchMethodException e) {
+            throw new DispatchException("Error extracting method from context", e, context,
this);
+        } catch (IllegalAccessException e) {
+            throw new DispatchException("Error accessing method", e, context, this);
         } catch (InvocationTargetException e) {
             Throwable cause = e.getTargetException();
-            if (cause instanceof Exception) {
-                throw (Exception)cause;
-            }
-            throw e;
+            throw new DispatchException("Error in reflected dispatched command", cause, context,
this);
         }
     }
 

Added: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java?rev=1297032&view=auto
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java
(added)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java
Mon Mar  5 12:35:10 2012
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.chain2.generic;
+
+import java.util.Map;
+
+import org.apache.commons.chain2.ChainException;
+import org.apache.commons.chain2.Command;
+
+/**
+ * Runtime Exception that wraps an underlying exception thrown during the
+ * execution of a {@link org.apache.commons.chain2.Command} or {@link org.apache.commons.chain2.Chain}.
+ *
+ * @author Elijah Zupancic
+ * @version $Id$
+ */
+public class DispatchException extends ChainException {
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    public DispatchException(String message) {
+        super(message);
+    }
+
+    public DispatchException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public <K, V, C extends Map<K, V>> DispatchException(String message, Throwable
cause,
+                                                         C context, Command<K, V, C>
failedCommand) {
+        super(message, cause, context, failedCommand);
+    }
+}

Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchLookupCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchLookupCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchLookupCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/DispatchLookupCommand.java
Mon Mar  5 12:35:10 2012
@@ -22,6 +22,7 @@ import org.apache.commons.chain2.Command
 import org.apache.commons.chain2.Context;
 import org.apache.commons.chain2.Filter;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.WeakHashMap;
 
@@ -140,26 +141,35 @@ public class DispatchLookupCommand<K, V,
      * @return the result of executing the looked-up command's method, or
      * <code>false</code> if no command is found.
      *
-     * @throws Exception if no such {@link Command} can be found and the
+     * @throws DispatchException if no such {@link Command} can be found and the
      *  <code>optional</code> property is set to <code>false</code>
      */
 	@Override
-    public boolean execute(C context) throws Exception {
+    public boolean execute(C context) {
 
         if (this.getMethod() == null && this.getMethodKey() == null) {
-            throw new IllegalStateException(
-                "Neither 'method' nor 'methodKey' properties are defined "
-            );
+            throw new IllegalStateException("Neither 'method' nor 'methodKey' properties
are defined");
         }
 
         Command<K, V, C> command = getCommand(context);
 
         if (command != null) {
-            Method methodObject = extractMethod(command, context);
-            Object obj = methodObject.invoke(command, getArguments(context));
-            Boolean result = (Boolean)obj;
+            try {
+                Method methodObject = extractMethod(command, context);
+                Object obj = methodObject.invoke(command, getArguments(context));
+
+                Boolean result = (Boolean)obj;
+                return (result != null && result);
+
+            } catch (NoSuchMethodException e) {
+                throw new DispatchException("Error extracting method from context", e, context,
this);
+            } catch (IllegalAccessException e) {
+                throw new DispatchException("Error accessing method", e, context, this);
+            } catch (InvocationTargetException e) {
+                Throwable cause = e.getTargetException();
+                throw new DispatchException("Error in reflected dispatched command", cause,
context, this);
+        }
 
-            return (result != null && result.booleanValue());
         } else {
             return false;
         }

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/LookupCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/LookupCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/LookupCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/LookupCommand.java
Mon Mar  5 12:35:10 2012
@@ -300,9 +300,9 @@ public class LookupCommand<K, V, C exten
      * <code>false</code> if no command is found or if the command
      * is found but the <code>ignoreExecuteResult</code> property of this
      * instance is <code>true</code>
-     * @throws Exception if and error occurs in the looked-up Command.
+     * @throws org.apache.commons.chain2.ChainException if and error occurs in the looked-up
Command.
      */
-    public boolean execute(C context) throws Exception {
+    public boolean execute(C context) {
 
         Command<K, V, C> command = getCommand(context);
         if (command != null) {

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/RemoveCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/RemoveCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/RemoveCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/generic/RemoveCommand.java
Mon Mar  5 12:35:10 2012
@@ -74,9 +74,9 @@ public class RemoveCommand<K, V, C exten
      * @param context {@link Context} in which we are operating
      *
      * @return <code>false</code> so that processing will continue
-     * @throws Exception if and error occurs.
+     * @throws org.apache.commons.chain2.ChainException if and error occurs.
      */
-    public boolean execute(C context) throws Exception {
+    public boolean execute(C context) {
 
     context.remove(getFromKey());
     return (false);

Modified: commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ChainBase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ChainBase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ChainBase.java
(original)
+++ commons/proper/chain/trunk/core/src/main/java/org/apache/commons/chain2/impl/ChainBase.java
Mon Mar  5 12:35:10 2012
@@ -16,17 +16,14 @@
  */
 package org.apache.commons.chain2.impl;
 
+import static java.lang.String.format;
+import org.apache.commons.chain2.*;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.chain2.Chain;
-import org.apache.commons.chain2.Command;
-import org.apache.commons.chain2.Context;
-import org.apache.commons.chain2.Filter;
-
 
 /**
  * <p>Convenience base class for {@link Chain} implementations.</p>
@@ -171,11 +168,11 @@ public class ChainBase<K, V, C extends M
      *  of this {@link Context} should be delegated to a subsequent
      *  {@link Command} in an enclosing {@link Chain}
      */
-    public boolean execute(C context) throws Exception {
+    public boolean execute(C context) {
 
         // Verify our parameters
         if (context == null) {
-            throw new IllegalArgumentException();
+            throw new IllegalArgumentException("Can't execute a null context");
         }
 
         // Freeze the configuration of the command list
@@ -187,9 +184,11 @@ public class ChainBase<K, V, C extends M
         Exception saveException = null;
         int i = 0;
         int n = commands.size();
+        Command<K, V, C> lastCommand = null;
         for (i = 0; i < n; i++) {
             try {
-                saveResult = commands.get(i).execute(context);
+                lastCommand = commands.get(i);
+                saveResult = lastCommand.execute(context);
                 if (saveResult) {
                     break;
                 }
@@ -222,7 +221,9 @@ public class ChainBase<K, V, C extends M
 
         // Return the exception or result state from the last execute()
         if ((saveException != null) && !handled) {
-            throw saveException;
+            // Wrap and rethrow exception
+            throw wrapUnhandledExceptions(saveException, context,
+                    lastCommand);
         } else {
             return (saveResult);
         }
@@ -230,6 +231,30 @@ public class ChainBase<K, V, C extends M
     }
 
     /**
+     * Wraps an unhandled exception in a {@link ChainException} class.
+     * @param unhandled Unhandled exception as passed from failing command
+     * @param context Context that was passed to failing command
+     * @param failedCommand The command that failed
+     * @return Original unhandled exception wrapped in a ChainException
+     */
+    protected ChainException wrapUnhandledExceptions(Throwable unhandled, C context, Command<K,
V, C> failedCommand) {
+        /* There should not be a reason to rewrap an exception that is already
+         * wrapped in a ChainException because the first wrapping preserves
+         * the {@link Context} necessary for debugging. Adding more wrapped
+         * exceptions would just make the debugging process more difficult. */
+        if (unhandled instanceof ChainException) {
+            return (ChainException) unhandled;
+        }
+
+        String msg = failedCommand == null ?
+                        "An error occurred when executing the chain" :
+                        format("An error occurred when executing the command %s in the chain",
+                               failedCommand.getClass().getName());
+
+        return new ChainException(msg, unhandled, context, failedCommand);
+    }
+
+    /**
      * Returns true, if the configuration of our commands list
      * has been frozen by a call to the <code>execute()</code> method,
      * false otherwise.

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchCommandTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchCommandTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchCommandTestCase.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchCommandTestCase.java
Mon Mar  5 12:35:10 2012
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.assertTrue;
 
 import org.apache.commons.chain2.Context;
-import org.apache.commons.chain2.generic.DispatchCommand;
 import org.apache.commons.chain2.impl.ContextBase;
 import org.junit.Test;
 

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchLookupCommandTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchLookupCommandTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchLookupCommandTestCase.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/DispatchLookupCommandTestCase.java
Mon Mar  5 12:35:10 2012
@@ -21,7 +21,6 @@ import static org.junit.Assert.*;
 import org.apache.commons.chain2.Catalog;
 import org.apache.commons.chain2.CatalogFactory;
 import org.apache.commons.chain2.Context;
-import org.apache.commons.chain2.generic.DispatchLookupCommand;
 import org.apache.commons.chain2.impl.CatalogBase;
 import org.apache.commons.chain2.impl.CatalogFactoryBase;
 import org.apache.commons.chain2.impl.ContextBase;

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/LookupCommandTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/LookupCommandTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/LookupCommandTestCase.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/generic/LookupCommandTestCase.java
Mon Mar  5 12:35:10 2012
@@ -26,7 +26,6 @@ import org.apache.commons.chain2.Catalog
 import org.apache.commons.chain2.CatalogFactory;
 import org.apache.commons.chain2.Chain;
 import org.apache.commons.chain2.Context;
-import org.apache.commons.chain2.generic.LookupCommand;
 import org.apache.commons.chain2.impl.CatalogBase;
 import org.apache.commons.chain2.impl.CatalogFactoryBase;
 import org.apache.commons.chain2.impl.ChainBase;

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/AddingCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/AddingCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/AddingCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/AddingCommand.java
Mon Mar  5 12:35:10 2012
@@ -57,7 +57,7 @@ public class AddingCommand extends NonDe
 
 
     // Execution method for this Command
-    public boolean execute(Context<String, Object> context, Chain<String, Object,
Context<String, Object>> chain) throws Exception {
+    public boolean execute(Context<String, Object> context, Chain<String, Object,
Context<String, Object>> chain) {
 
         super.execute(context);
         parent.addCommand(new NonDelegatingCommand("NEW")); // Should cause ISE

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogBaseTestCase.java
Mon Mar  5 12:35:10 2012
@@ -26,8 +26,6 @@ import java.util.Iterator;
 import org.apache.commons.chain2.Catalog;
 import org.apache.commons.chain2.Command;
 import org.apache.commons.chain2.Context;
-import org.apache.commons.chain2.impl.CatalogBase;
-import org.apache.commons.chain2.impl.ChainBase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogFactoryBaseTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogFactoryBaseTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogFactoryBaseTestCase.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/CatalogFactoryBaseTestCase.java
Mon Mar  5 12:35:10 2012
@@ -29,7 +29,6 @@ import org.apache.commons.chain2.Catalog
 import org.apache.commons.chain2.CatalogFactory;
 import org.apache.commons.chain2.Command;
 import org.apache.commons.chain2.Context;
-import org.apache.commons.chain2.impl.CatalogBase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ChainBaseTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ChainBaseTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ChainBaseTestCase.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ChainBaseTestCase.java
Mon Mar  5 12:35:10 2012
@@ -26,8 +26,6 @@ import java.util.List;
 import org.apache.commons.chain2.Chain;
 import org.apache.commons.chain2.Command;
 import org.apache.commons.chain2.Context;
-import org.apache.commons.chain2.impl.ChainBase;
-import org.apache.commons.chain2.impl.ContextBase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ContextBaseTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ContextBaseTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ContextBaseTestCase.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ContextBaseTestCase.java
Mon Mar  5 12:35:10 2012
@@ -34,7 +34,6 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.chain2.Context;
-import org.apache.commons.chain2.impl.ContextBase;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingCommand.java
Mon Mar  5 12:35:10 2012
@@ -50,7 +50,7 @@ public class DelegatingCommand extends N
 
 
     // Execution method for this Command
-    public boolean execute(Context<String, Object> context) throws Exception {
+    public boolean execute(Context<String, Object> context) {
 
         super.execute(context);
         return (false);

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingFilter.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingFilter.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/DelegatingFilter.java
Mon Mar  5 12:35:10 2012
@@ -51,7 +51,7 @@ public class DelegatingFilter extends No
 
     // Execution method for this Command
     @Override
-    public boolean execute(Context<String, Object> context) throws Exception {
+    public boolean execute(Context<String, Object> context) {
 
         super.execute(context);
         return (false);

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ExceptionCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ExceptionCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ExceptionCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/ExceptionCommand.java
Mon Mar  5 12:35:10 2012
@@ -50,7 +50,7 @@ public class ExceptionCommand extends No
 
 
     // Execution method for this Command
-    public void execute(Context<String, Object> context, Chain<String, Object, Context<String,
Object>> chain) throws Exception {
+    public void execute(Context<String, Object> context, Chain<String, Object, Context<String,
Object>> chain) {
 
         super.execute(context);
         throw new ArithmeticException(this.id);

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingCommand.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingCommand.java
Mon Mar  5 12:35:10 2012
@@ -65,7 +65,7 @@ public class NonDelegatingCommand implem
 
 
     // Execution method for this Command
-    public boolean execute(Context<String, Object> context) throws Exception {
+    public boolean execute(Context<String, Object> context) {
 
         if (context == null) {
             throw new IllegalArgumentException();

Modified: commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingFilter.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingFilter.java
(original)
+++ commons/proper/chain/trunk/core/src/test/java/org/apache/commons/chain2/impl/NonDelegatingFilter.java
Mon Mar  5 12:35:10 2012
@@ -65,7 +65,7 @@ public class NonDelegatingFilter
 
     // Execution method for this Command
     @Override
-    public boolean execute(Context<String, Object> context) throws Exception {
+    public boolean execute(Context<String, Object> context) {
 
         super.execute(context);
         return (true);

Modified: commons/proper/chain/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/changes/changes.xml?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/src/changes/changes.xml (original)
+++ commons/proper/chain/trunk/src/changes/changes.xml Mon Mar  5 12:35:10 2012
@@ -40,6 +40,9 @@ The <action> type attribute can be add,u
   <body>
 
     <release version="2.0" description="Major release">
+      <action dev="simonetripodi" type="add" issue="CHAIN-67" due-to="Elijah Zupancic">
+        Refactor of explicit Exception throws to a RuntimeException type
+      </action>
       <action dev="simonetripodi" type="add" issue="CHAIN-65" due-to="Elijah Zupancic">
         Rename package org.apache.commons.chain to org.apache.commons.chain2 for v2 of chain.
       </action>

Modified: commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractGetLocaleCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractGetLocaleCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractGetLocaleCommand.java
(original)
+++ commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractGetLocaleCommand.java
Mon Mar  5 12:35:10 2012
@@ -17,11 +17,11 @@
 package org.apache.commons.chain2.web;
 
 
-import java.util.Locale;
-
 import org.apache.commons.chain2.Command;
 import org.apache.commons.chain2.Context;
 
+import java.util.Locale;
+
 
 /**
  * <p>Abstract base {@link Command} implementation for retrieving the
@@ -83,9 +83,9 @@ public abstract class AbstractGetLocaleC
      * @param context The {@link Context} we are operating on
      *
      * @return <code>false</code> so that processng will continue
-     * @throws Exception If an error occurs during execution.
+     * @throws org.apache.commons.chain2.ChainException If an error occurs during execution.
      */
-    public boolean execute(C context) throws Exception {
+    public boolean execute(C context) {
 
     context.put(getLocaleKey(), getLocale(context));
     return (false);

Modified: commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractSetLocaleCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractSetLocaleCommand.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractSetLocaleCommand.java
(original)
+++ commons/proper/chain/trunk/web/src/main/java/org/apache/commons/chain2/web/AbstractSetLocaleCommand.java
Mon Mar  5 12:35:10 2012
@@ -17,11 +17,11 @@
 package org.apache.commons.chain2.web;
 
 
-import java.util.Locale;
-
 import org.apache.commons.chain2.Command;
 import org.apache.commons.chain2.Context;
 
+import java.util.Locale;
+
 
 /**
  * <p>Abstract base {@link Command} implementation for setting the
@@ -83,10 +83,10 @@ public abstract class AbstractSetLocaleC
      *
      * @param context The {@link Context} we are operating on
      *
-     * @return <code>false</code> so that processng will continue
-     * @throws Exception If an error occurs during execution.
+     * @return <code>false</code> so that processing will continue
+     * @throws org.apache.commons.chain2.ChainException If an error occurs during execution.
      */
-    public boolean execute(C context) throws Exception {
+    public boolean execute(C context) {
 
     setLocale(context,
           (Locale) context.get(getLocaleKey()));

Modified: commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/portlet/PortletWebContextTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/portlet/PortletWebContextTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/portlet/PortletWebContextTestCase.java
(original)
+++ commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/portlet/PortletWebContextTestCase.java
Mon Mar  5 12:35:10 2012
@@ -21,7 +21,6 @@ import static org.junit.Assert.*;
 import org.apache.commons.chain2.Context;
 import org.apache.commons.chain2.impl.ContextBaseTestCase;
 import org.apache.commons.chain2.web.WebContext;
-import org.apache.commons.chain2.web.portlet.PortletWebContext;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;

Modified: commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/servlet/ServletWebContextTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/servlet/ServletWebContextTestCase.java?rev=1297032&r1=1297031&r2=1297032&view=diff
==============================================================================
--- commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/servlet/ServletWebContextTestCase.java
(original)
+++ commons/proper/chain/trunk/web/src/test/java/org/apache/commons/chain2/web/servlet/ServletWebContextTestCase.java
Mon Mar  5 12:35:10 2012
@@ -39,7 +39,6 @@ import javax.servlet.http.HttpSession;
 import org.apache.commons.chain2.Context;
 import org.apache.commons.chain2.impl.ContextBaseTestCase;
 import org.apache.commons.chain2.web.WebContext;
-import org.apache.commons.chain2.web.servlet.ServletWebContext;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;



Mime
View raw message