You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/12/29 02:18:23 UTC

cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections FunctorException.java

scolebourne    2003/12/28 17:18:23

  Modified:    collections/src/java/org/apache/commons/collections/functors
                        NullIsExceptionPredicate.java ExceptionClosure.java
                        InstantiateTransformer.java PrototypeFactory.java
                        TransformerPredicate.java InstantiateFactory.java
                        InvokerTransformer.java ExceptionFactory.java
                        ExceptionPredicate.java ExceptionTransformer.java
               collections/src/test/org/apache/commons/collections
                        TestPredicateUtils.java TestFactoryUtils.java
                        TestClosureUtils.java TestCollectionUtils.java
                        TestTransformerUtils.java
               collections/src/java/org/apache/commons/collections
                        FunctorException.java
  Removed:     collections/src/java/org/apache/commons/collections/functors
                        FunctorException.java
  Log:
  Reinstate FunctorException in main package, as it is specified by the functor interfaces
  
  Revision  Changes    Path
  1.2       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java
  
  Index: NullIsExceptionPredicate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/NullIsExceptionPredicate.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NullIsExceptionPredicate.java	23 Nov 2003 19:11:21 -0000	1.1
  +++ NullIsExceptionPredicate.java	29 Dec 2003 01:18:23 -0000	1.2
  @@ -59,6 +59,7 @@
   
   import java.io.Serializable;
   
  +import org.apache.commons.collections.FunctorException;
   import org.apache.commons.collections.Predicate;
   
   /**
  
  
  
  1.2       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/ExceptionClosure.java
  
  Index: ExceptionClosure.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/ExceptionClosure.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExceptionClosure.java	23 Nov 2003 17:01:35 -0000	1.1
  +++ ExceptionClosure.java	29 Dec 2003 01:18:23 -0000	1.2
  @@ -60,6 +60,7 @@
   import java.io.Serializable;
   
   import org.apache.commons.collections.Closure;
  +import org.apache.commons.collections.FunctorException;
   
   /**
    * Closure implementation that always throws an exception.
  
  
  
  1.3       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java
  
  Index: InstantiateTransformer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/InstantiateTransformer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InstantiateTransformer.java	27 Nov 2003 23:57:09 -0000	1.2
  +++ InstantiateTransformer.java	29 Dec 2003 01:18:23 -0000	1.3
  @@ -61,6 +61,7 @@
   import java.lang.reflect.Constructor;
   import java.lang.reflect.InvocationTargetException;
   
  +import org.apache.commons.collections.FunctorException;
   import org.apache.commons.collections.Transformer;
   
   /**
  
  
  
  1.3       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/PrototypeFactory.java
  
  Index: PrototypeFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/PrototypeFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PrototypeFactory.java	27 Nov 2003 23:57:09 -0000	1.2
  +++ PrototypeFactory.java	29 Dec 2003 01:18:23 -0000	1.3
  @@ -67,6 +67,7 @@
   import java.lang.reflect.Method;
   
   import org.apache.commons.collections.Factory;
  +import org.apache.commons.collections.FunctorException;
   
   /**
    * Factory implementation that creates a new instance each time based on a prototype.
  
  
  
  1.2       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/TransformerPredicate.java
  
  Index: TransformerPredicate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/TransformerPredicate.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TransformerPredicate.java	23 Nov 2003 22:05:24 -0000	1.1
  +++ TransformerPredicate.java	29 Dec 2003 01:18:23 -0000	1.2
  @@ -59,6 +59,7 @@
   
   import java.io.Serializable;
   
  +import org.apache.commons.collections.FunctorException;
   import org.apache.commons.collections.Predicate;
   import org.apache.commons.collections.Transformer;
   
  
  
  
  1.3       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/InstantiateFactory.java
  
  Index: InstantiateFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/InstantiateFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InstantiateFactory.java	27 Nov 2003 23:57:09 -0000	1.2
  +++ InstantiateFactory.java	29 Dec 2003 01:18:23 -0000	1.3
  @@ -62,6 +62,7 @@
   import java.lang.reflect.InvocationTargetException;
   
   import org.apache.commons.collections.Factory;
  +import org.apache.commons.collections.FunctorException;
   
   /**
    * Factory implementation that creates a new object instance by reflection.
  
  
  
  1.3       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/InvokerTransformer.java
  
  Index: InvokerTransformer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/InvokerTransformer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InvokerTransformer.java	27 Nov 2003 23:57:09 -0000	1.2
  +++ InvokerTransformer.java	29 Dec 2003 01:18:23 -0000	1.3
  @@ -61,6 +61,7 @@
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
   
  +import org.apache.commons.collections.FunctorException;
   import org.apache.commons.collections.Transformer;
   
   /**
  
  
  
  1.2       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/ExceptionFactory.java
  
  Index: ExceptionFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/ExceptionFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExceptionFactory.java	23 Nov 2003 17:01:35 -0000	1.1
  +++ ExceptionFactory.java	29 Dec 2003 01:18:23 -0000	1.2
  @@ -60,6 +60,7 @@
   import java.io.Serializable;
   
   import org.apache.commons.collections.Factory;
  +import org.apache.commons.collections.FunctorException;
   
   /**
    * Factory implementation that always throws an exception.
  
  
  
  1.2       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/ExceptionPredicate.java
  
  Index: ExceptionPredicate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/ExceptionPredicate.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExceptionPredicate.java	23 Nov 2003 17:01:35 -0000	1.1
  +++ ExceptionPredicate.java	29 Dec 2003 01:18:23 -0000	1.2
  @@ -59,6 +59,7 @@
   
   import java.io.Serializable;
   
  +import org.apache.commons.collections.FunctorException;
   import org.apache.commons.collections.Predicate;
   
   /**
  
  
  
  1.2       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/functors/ExceptionTransformer.java
  
  Index: ExceptionTransformer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/functors/ExceptionTransformer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExceptionTransformer.java	23 Nov 2003 17:01:35 -0000	1.1
  +++ ExceptionTransformer.java	29 Dec 2003 01:18:23 -0000	1.2
  @@ -59,6 +59,7 @@
   
   import java.io.Serializable;
   
  +import org.apache.commons.collections.FunctorException;
   import org.apache.commons.collections.Transformer;
   
   /**
  
  
  
  1.5       +2 -3      jakarta-commons/collections/src/test/org/apache/commons/collections/TestPredicateUtils.java
  
  Index: TestPredicateUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestPredicateUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestPredicateUtils.java	23 Nov 2003 14:41:27 -0000	1.4
  +++ TestPredicateUtils.java	29 Dec 2003 01:18:23 -0000	1.5
  @@ -62,7 +62,6 @@
   import java.util.Collections;
   import java.util.List;
   
  -import org.apache.commons.collections.functors.FunctorException;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  
  
  
  1.9       +2 -3      jakarta-commons/collections/src/test/org/apache/commons/collections/TestFactoryUtils.java
  
  Index: TestFactoryUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestFactoryUtils.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestFactoryUtils.java	27 Nov 2003 23:57:09 -0000	1.8
  +++ TestFactoryUtils.java	29 Dec 2003 01:18:23 -0000	1.9
  @@ -72,7 +72,6 @@
   import junit.textui.TestRunner;
   
   import org.apache.commons.collections.functors.ConstantFactory;
  -import org.apache.commons.collections.functors.FunctorException;
   
   /**
    * Tests the org.apache.commons.collections.FactoryUtils class.
  
  
  
  1.7       +2 -3      jakarta-commons/collections/src/test/org/apache/commons/collections/TestClosureUtils.java
  
  Index: TestClosureUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestClosureUtils.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestClosureUtils.java	27 Nov 2003 23:57:09 -0000	1.6
  +++ TestClosureUtils.java	29 Dec 2003 01:18:23 -0000	1.7
  @@ -67,7 +67,6 @@
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
   
  -import org.apache.commons.collections.functors.FunctorException;
   import org.apache.commons.collections.functors.NOPClosure;
   
   /**
  
  
  
  1.33      +2 -3      jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java
  
  Index: TestCollectionUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- TestCollectionUtils.java	23 Nov 2003 14:41:27 -0000	1.32
  +++ TestCollectionUtils.java	29 Dec 2003 01:18:23 -0000	1.33
  @@ -80,7 +80,6 @@
   import org.apache.commons.collections.collection.SynchronizedCollection;
   import org.apache.commons.collections.collection.TransformedCollection;
   import org.apache.commons.collections.collection.UnmodifiableCollection;
  -import org.apache.commons.collections.functors.FunctorException;
   
   /**
    * Tests for CollectionUtils.
  
  
  
  1.8       +2 -3      jakarta-commons/collections/src/test/org/apache/commons/collections/TestTransformerUtils.java
  
  Index: TestTransformerUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestTransformerUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestTransformerUtils.java	27 Nov 2003 23:57:09 -0000	1.7
  +++ TestTransformerUtils.java	29 Dec 2003 01:18:23 -0000	1.8
  @@ -70,7 +70,6 @@
   import junit.textui.TestRunner;
   
   import org.apache.commons.collections.functors.ConstantTransformer;
  -import org.apache.commons.collections.functors.FunctorException;
   import org.apache.commons.collections.functors.NOPTransformer;
   
   /**
  
  
  
  1.4       +105 -8    jakarta-commons/collections/src/java/org/apache/commons/collections/FunctorException.java
  
  Index: FunctorException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/FunctorException.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FunctorException.java	23 Nov 2003 14:41:27 -0000	1.3
  +++ FunctorException.java	29 Dec 2003 01:18:23 -0000	1.4
  @@ -4,7 +4,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -57,32 +57,129 @@
    */
   package org.apache.commons.collections;
   
  +import java.io.PrintStream;
  +import java.io.PrintWriter;
  +
   /**
  - * Exception thrown from functors.
  + * Runtime exception thrown from functors.
    * If required, a root cause error can be wrapped within this one.
    * 
  - * @deprecated TO BE DELETED BEFORE v3.0
    * @since Commons Collections 3.0
    * @version $Revision$ $Date$
    *
    * @author Stephen Colebourne
    */
  -public class FunctorException extends org.apache.commons.collections.functors.FunctorException {
  +public class FunctorException extends RuntimeException {
  +    
  +    /**
  +     * Does JDK support nested exceptions
  +     */
  +    private static final boolean JDK_SUPPORTS_NESTED;
  +    
  +    static {
  +        boolean flag = false;
  +        try {
  +            Throwable.class.getDeclaredMethod("getCause", new Class[0]);
  +            flag = true;
  +        } catch (NoSuchMethodException ex) {
  +            flag = false;
  +        }
  +        JDK_SUPPORTS_NESTED = flag;
  +    }
       
  +    /**
  +     * Root cause of the exception
  +     */
  +    private final Throwable rootCause;
  +
  +    /**
  +     * Constructs a new <code>FunctorException</code> without specified
  +     * detail message.
  +     */
       public FunctorException() {
           super();
  +        this.rootCause = null;
       }
   
  +    /**
  +     * Constructs a new <code>FunctorException</code> with specified
  +     * detail message.
  +     *
  +     * @param msg  the error message.
  +     */
       public FunctorException(String msg) {
           super(msg);
  +        this.rootCause = null;
       }
   
  +    /**
  +     * Constructs a new <code>FunctorException</code> with specified
  +     * nested <code>Throwable</code> root cause.
  +     *
  +     * @param rootCause  the exception or error that caused this exception
  +     *                   to be thrown.
  +     */
       public FunctorException(Throwable rootCause) {
  -        super(rootCause);
  +        super((rootCause == null ? null : rootCause.getMessage()));
  +        this.rootCause = rootCause;
       }
   
  +    /**
  +     * Constructs a new <code>FunctorException</code> with specified
  +     * detail message and nested <code>Throwable</code> root cause.
  +     *
  +     * @param msg        the error message.
  +     * @param rootCause  the exception or error that caused this exception
  +     *                   to be thrown.
  +     */
       public FunctorException(String msg, Throwable rootCause) {
  -        super(msg, rootCause);
  +        super(msg);
  +        this.rootCause = rootCause;
  +    }
  +
  +    /**
  +     * Gets the cause of this throwable.
  +     * 
  +     * @return  the cause of this throwable, or <code>null</code>
  +     */
  +    public Throwable getCause() {
  +        return rootCause;
  +    }
  +
  +    /**
  +     * Prints the stack trace of this exception to the standard error stream.
  +     */
  +    public void printStackTrace() {
  +        printStackTrace(System.err);
  +    }
  +
  +    /**
  +     * Prints the stack trace of this exception to the specified stream.
  +     *
  +     * @param out  the <code>PrintStream</code> to use for output
  +     */
  +    public void printStackTrace(PrintStream out) {
  +        synchronized (out) {
  +            PrintWriter pw = new PrintWriter(out, false);
  +            printStackTrace(pw);
  +            // Flush the PrintWriter before it's GC'ed.
  +            pw.flush();
  +        }
  +    }
  +
  +    /**
  +     * Prints the stack trace of this exception to the specified writer.
  +     *
  +     * @param out  the <code>PrintWriter</code> to use for output
  +     */
  +    public void printStackTrace(PrintWriter out) {
  +        synchronized (out) {
  +            super.printStackTrace(out);
  +            if (rootCause != null && JDK_SUPPORTS_NESTED == false) {
  +                out.print("Caused by: ");
  +                rootCause.printStackTrace(out);
  +            }
  +        }
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org