commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r829404 - in /commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception: ContextedException.java ContextedRuntimeException.java DefaultExceptionContext.java ExceptionContext.java ExceptionUtils.java
Date Sat, 24 Oct 2009 16:38:09 GMT
Author: scolebourne
Date: Sat Oct 24 16:38:08 2009
New Revision: 829404

URL: http://svn.apache.org/viewvc?rev=829404&view=rev
Log:
Allow contexted exception to store non-serializable objects (more flexible, and doesn't prevent
serialization)

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedException.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedRuntimeException.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/DefaultExceptionContext.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionContext.java
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedException.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedException.java?rev=829404&r1=829403&r2=829404&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedException.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedException.java
Sat Oct 24 16:38:08 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.lang.exception;
 
-import java.io.Serializable;
 import java.util.Set;
 
 /**
@@ -141,15 +140,13 @@
      * the problem.  For the information to be meaningful, the value passed
      * should have a reasonable toString() implementation.
      * <p>
-     * Note:  If the value provided isn't Serializable, one solution would be
-     * to provide its toString() if it has a meaningful implementation or 
-     * individual properties of the value object instead.
+     * Note: This exception is only serializable if the object added is serializable.
      * 
      * @param label  a textual label associated with information, null not recommended
      * @param value  information needed to understand exception, may be null
      * @return this, for method chaining
      */
-    public ContextedException addLabeledValue(String label, Serializable value) {       

+    public ContextedException addLabeledValue(String label, Object value) {        
         exceptionContext.addLabeledValue(label, value);
         return this;
     }
@@ -160,7 +157,7 @@
      * @param label  the label to get the contextual value for, may be null
      * @return the contextual value associated with the label, may be null
      */
-    public Serializable getLabeledValue(String label) {
+    public Object getLabeledValue(String label) {
         return exceptionContext.getLabeledValue(label);
     }
 

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedRuntimeException.java?rev=829404&r1=829403&r2=829404&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedRuntimeException.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ContextedRuntimeException.java
Sat Oct 24 16:38:08 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.commons.lang.exception;
 
-import java.io.Serializable;
 import java.util.Set;
 
 /**
@@ -142,15 +141,13 @@
      * the problem.  For the information to be meaningful, the value passed
      * should have a reasonable toString() implementation.
      * <p>
-     * Note:  If the value provided isn't Serializable, one solution would be
-     * to provide its toString() if it has a meaningful implementation or 
-     * individual properties of the value object instead.
+     * Note: This exception is only serializable if the object added is serializable.
      * 
      * @param label  a textual label associated with information, null not recommended
      * @param value  information needed to understand exception, may be null
      * @return this, for method chaining
      */
-    public ContextedRuntimeException addLabeledValue(String label, Serializable value) {
       
+    public ContextedRuntimeException addLabeledValue(String label, Object value) {      
 
         exceptionContext.addLabeledValue(label, value);
         return this;
     }
@@ -161,7 +158,7 @@
      * @param label  the label to get the contextual value for, may be null
      * @return the contextual value associated with the label, may be null
      */
-    public Serializable getLabeledValue(String label) {
+    public Object getLabeledValue(String label) {
         return exceptionContext.getLabeledValue(label);
     }
 

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/DefaultExceptionContext.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/DefaultExceptionContext.java?rev=829404&r1=829403&r2=829404&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/DefaultExceptionContext.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/DefaultExceptionContext.java
Sat Oct 24 16:38:08 2009
@@ -25,16 +25,19 @@
 
 /**
  * Default implementation of the context storing the label-value pairs for contexted exceptions.
+ * <p>
+ * This implementation is serializable, however this is dependent on the values that
+ * are added also being serializable.
  * 
  * @author D. Ashmore
  * @since 3.0
  */
-class DefaultExceptionContext implements ExceptionContext {
+class DefaultExceptionContext implements ExceptionContext, Serializable {
 
     /** The serialization version. */
     private static final long serialVersionUID = 293747957535772807L;
     /** The ordered map storing the label-data pairs. */
-    private Map<String, Serializable> contextValueMap = new LinkedHashMap<String,
Serializable>();
+    private Map<String, Object> contextValueMap = new LinkedHashMap<String, Object>();
 
     /**
      * Adds a contextual label-value pair into this context.
@@ -45,7 +48,7 @@
      * @param value  the value of item to add, may be null
      * @return this, for method chaining
      */
-    public ExceptionContext addLabeledValue(String label, Serializable value) {        
+    public ExceptionContext addLabeledValue(String label, Object value) {        
         contextValueMap.put(label, value);
         return this;
     }
@@ -56,7 +59,7 @@
      * @param label  the label to get the contextual value for, may be null
      * @return the contextual value associated with the label, may be null
      */
-    public Serializable getLabeledValue(String label) {
+    public Object getLabeledValue(String label) {
         return contextValueMap.get(label);
     }
 

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionContext.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionContext.java?rev=829404&r1=829403&r2=829404&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionContext.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionContext.java
Sat Oct 24 16:38:08 2009
@@ -16,21 +16,18 @@
  */
 package org.apache.commons.lang.exception;
 
-import java.io.Serializable;
 import java.util.Set;
 
-
 /**
- * Provides context information for exceptions. It is available as separate interface to
allow
- * it usage independently from the {@link ContextedException} and
- * {@link ContextedRuntimeException}.
+ * Allows the storage and retrieval of contextual information based on label-value
+ * pairs for exceptions.
  * 
  * @see ContextedException
  * @see ContextedRuntimeException
  * @author D. Ashmore
  * @since 3.0
  */
-public interface ExceptionContext extends Serializable {
+public interface ExceptionContext {
 
     /**
      * Adds a contextual label-value pair into this context.
@@ -41,7 +38,7 @@
      * @param value  the value of item to add, may be null
      * @return context itself to allow method chaining
      */
-    public ExceptionContext addLabeledValue(String label, Serializable value);
+    public ExceptionContext addLabeledValue(String label, Object value);
 
     /**
      * Retrieves a contextual data value associated with the label.
@@ -49,7 +46,7 @@
      * @param label  the label to get the contextual value for, may be null
      * @return the contextual value associated with the label, may be null
      */
-    public Serializable getLabeledValue(String label);
+    public Object getLabeledValue(String label);
 
     /**
      * Retrieves the labels defined in the contextual data.

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java?rev=829404&r1=829403&r2=829404&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/exception/ExceptionUtils.java
Sat Oct 24 16:38:08 2009
@@ -18,7 +18,6 @@
 
 import java.io.PrintStream;
 import java.io.PrintWriter;
-import java.io.Serializable;
 import java.io.StringWriter;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
@@ -26,14 +25,9 @@
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 import java.util.StringTokenizer;
 
-//import net.jcip.annotations.GuardedBy;
-//import net.jcip.annotations.ThreadSafe;
-
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.ClassUtils;
 import org.apache.commons.lang.StringUtils;
@@ -88,37 +82,10 @@
      * <p>The Method object for Java 1.4 getCause.</p>
      */
     private static final Method THROWABLE_CAUSE_METHOD;
-
     /**
      * <p>The Method object for Java 1.4 initCause.</p>
      */
     private static final Method THROWABLE_INITCAUSE_METHOD;
-    
-    /**
-     * An empty {@link ExceptionContext}.
-     * @since 3.0
-     */
-    public static final ExceptionContext EMPTY_CONTEXT = new ExceptionContext() {
-
-        private static final long serialVersionUID = 1L;
-
-        public ExceptionContext addLabeledValue(String label, Serializable value) {
-          throw new UnsupportedOperationException();
-        }
-
-        public Serializable getLabeledValue(String label) {
-          return null;
-        }
-
-        public Set<String> getLabelSet() {
-          return Collections.<String>emptySet();
-        }
-
-        public String getFormattedExceptionMessage(String baseMessage) {
-          return baseMessage;
-        }
-
-      };    
     static {
         Method causeMethod;
         try {
@@ -134,7 +101,7 @@
         }
         THROWABLE_INITCAUSE_METHOD = causeMethod;
     }
-    
+
     /**
      * <p>
      * Public constructor allows an instance of <code>ExceptionUtils</code> to
be created, although that is not



Mime
View raw message