Coverage Report - wjhk.jupload2.exception.JUploadException
 
Classes in this File Line Coverage Branch Coverage Complexity
JUploadException
56 %
17/30
20 %
2/10
2,2
 
 1  
 //
 2  
 // $Id: JUploadException.java 95 2007-05-02 03:27:05Z
 3  
 // /C=DE/ST=Baden-Wuerttemberg/O=ISDN4Linux/OU=Fritz
 4  
 // Elfert/CN=svn-felfert@isdn4linux.de/emailAddress=fritz@fritz-elfert.de $
 5  
 //
 6  
 // jupload - A file upload applet.
 7  
 // Copyright 2007 The JUpload Team
 8  
 //
 9  
 // Created: 2006-05-09
 10  
 // Creator: etienne_sf
 11  
 // Last modified: $Date: 2009-11-06 22:07:21 +0100 (ven., 06 nov. 2009) $
 12  
 //
 13  
 // This program is free software; you can redistribute it and/or modify it under
 14  
 // the terms of the GNU General Public License as published by the Free Software
 15  
 // Foundation; either version 2 of the License, or (at your option) any later
 16  
 // version. This program is distributed in the hope that it will be useful, but
 17  
 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 18  
 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 19  
 // details. You should have received a copy of the GNU General Public License
 20  
 // along with this program; if not, write to the Free Software Foundation, Inc.,
 21  
 // 675 Mass Ave, Cambridge, MA 02139, USA.
 22  
 
 23  
 package wjhk.jupload2.exception;
 24  
 
 25  
 /**
 26  
  * A new kind of exceptions. Currently : no other specialization than its name.
 27  
  * 
 28  
  * @author etienne_sf
 29  
  * @version $Revision: 887 $
 30  
  */
 31  
 public class JUploadException extends Exception {
 32  
     /** A generated serialVersionUID, to avoid warning during compilation */
 33  
     private static final long serialVersionUID = -6386378085666411905L;
 34  
 
 35  216
     private String location = null;
 36  
 
 37  
     /**
 38  
      * Creates a new instance with a specified message.
 39  
      * 
 40  
      * @param message The message to be associated with this instance.
 41  
      */
 42  
     public JUploadException(String message) {
 43  18
         super(message);
 44  18
         StackTraceElement[] trace = super.getStackTrace();
 45  18
         if (trace.length > 0) {
 46  18
             StackTraceElement se = trace[0];
 47  18
             this.location = se.getClassName() + "." + se.getMethodName()
 48  18
                     + " in " + se.getFileName() + ", line "
 49  18
                     + se.getLineNumber();
 50  
         }
 51  18
     }
 52  
 
 53  
     /**
 54  
      * Creates a new instance with a specified original exception.
 55  
      * 
 56  
      * @param ex The exception that was originally thrown.
 57  
      */
 58  
     public JUploadException(Exception ex) {
 59  198
         super(ex);
 60  198
         StackTraceElement[] trace = ex.getStackTrace();
 61  198
         if (trace.length > 0) {
 62  198
             StackTraceElement se = trace[0];
 63  198
             this.location = se.getClassName() + "." + se.getMethodName()
 64  198
                     + " in " + se.getFileName() + ", line "
 65  198
                     + se.getLineNumber();
 66  
         }
 67  198
     }
 68  
 
 69  
     /**
 70  
      * Creates a new instance with a specified message and original exception.
 71  
      * 
 72  
      * @param message The message to be associated with this instance.
 73  
      * @param ex The exception that was originally thrown.
 74  
      */
 75  
     public JUploadException(String message, Throwable ex) {
 76  0
         super(message, ex);
 77  0
         StackTraceElement[] trace = ex.getStackTrace();
 78  0
         if (trace.length > 0) {
 79  0
             StackTraceElement se = trace[0];
 80  0
             this.location = se.getClassName() + "." + se.getMethodName()
 81  0
                     + " in " + se.getFileName() + ", line "
 82  0
                     + se.getLineNumber();
 83  
         }
 84  0
     }
 85  
 
 86  
     /**
 87  
      * Retrieves the human readable location of this exception (Class.method,
 88  
      * filename, linenumber)
 89  
      * 
 90  
      * @return The location where this exception was thrown.
 91  
      */
 92  
     public String getLocation() {
 93  0
         return (null == this.location) ? "unknown location" : this.location;
 94  
     }
 95  
 
 96  
     /**
 97  
      * Returns JUploadExceptionClassName:CauseClassName. For instance:<BR>
 98  
      * wjhk.jupload2.exception.JUploadIOException:FileNotFoundException <BR>
 99  
      * or<BR>
 100  
      * wjhk.jupload2.exception.JUploadIOException (if there is no cause given to
 101  
      * the JUploadException constructor).
 102  
      * 
 103  
      * @return The class name(s) that can be displayed in an error message.
 104  
      */
 105  
     public String getClassNameAndClause() {
 106  0
         if (getCause() == null) {
 107  0
             return this.getClass().getName();
 108  
         } else {
 109  0
             return this.getClass().getName() + ":"
 110  0
                     + this.getCause().getClass().getName();
 111  
         }
 112  
     }
 113  
 }