Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 229   Methods: 9
NCLOC: 90   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DroolsException.java 62.5% 67.6% 77.8% 67.7%
coverage coverage
 1    package org.drools;
 2   
 3    /*
 4    * $Id: DroolsException.java,v 1.18 2005/01/09 23:49:24 memelet Exp $
 5    *
 6    * Copyright 2001-2004 (C) The Werken Company. All Rights Reserved.
 7    *
 8    * Redistribution and use of this software and associated documentation
 9    * ("Software"), with or without modification, are permitted provided that the
 10    * following conditions are met:
 11    *
 12    * 1. Redistributions of source code must retain copyright statements and
 13    * notices. Redistributions must also contain a copy of this document.
 14    *
 15    * 2. Redistributions in binary form must reproduce the above copyright notice,
 16    * this list of conditions and the following disclaimer in the documentation
 17    * and/or other materials provided with the distribution.
 18    *
 19    * 3. The name "drools" must not be used to endorse or promote products derived
 20    * from this Software without prior written permission of The Werken Company.
 21    * For written permission, please contact bob@werken.com.
 22    *
 23    * 4. Products derived from this Software may not be called "drools" nor may
 24    * "drools" appear in their names without prior written permission of The Werken
 25    * Company. "drools" is a registered trademark of The Werken Company.
 26    *
 27    * 5. Due credit should be given to The Werken Company.
 28    * (http://drools.werken.com/).
 29    *
 30    * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
 31    * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 32    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 33    * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
 34    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 35    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 36    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 37    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 38    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 39    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 40    * POSSIBILITY OF SUCH DAMAGE.
 41    *
 42    */
 43   
 44    import java.io.PrintStream;
 45    import java.io.PrintWriter;
 46   
 47    /**
 48    * Base <code>drools Logic Engine</code> exception.
 49    *
 50    * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter </a>
 51    *
 52    * @version $Id: DroolsException.java,v 1.18 2005/01/09 23:49:24 memelet Exp $
 53    */
 54    public class DroolsException extends Exception
 55    {
 56    // ------------------------------------------------------------
 57    // Instance members
 58    // ------------------------------------------------------------
 59   
 60    /** Root cause, if any. */
 61    private final Throwable rootCause;
 62   
 63    // ------------------------------------------------------------
 64    // Constructors
 65    // ------------------------------------------------------------
 66   
 67    /**
 68    * Construct.
 69    */
 70  19 public DroolsException( )
 71    {
 72  19 this.rootCause = null;
 73    }
 74   
 75    /**
 76    * Construct with a message.
 77    *
 78    * @param msg
 79    * The message.
 80    */
 81  18 public DroolsException( String msg )
 82    {
 83  18 super( msg );
 84  18 this.rootCause = null;
 85    }
 86   
 87    /**
 88    * Construct with a root cause.
 89    *
 90    * @param rootCause
 91    * The root cause of this exception.
 92    */
 93  15 public DroolsException( Throwable rootCause )
 94    {
 95  15 this.rootCause = rootCause;
 96    }
 97   
 98    /**
 99    * Construct with a message and root cause.
 100    *
 101    * @param rootCause
 102    * The root cause of this exception.
 103    */
 104  4 public DroolsException( String msg, Throwable rootCause )
 105    {
 106  4 super( msg );
 107  4 this.rootCause = rootCause;
 108    }
 109    // ------------------------------------------------------------
 110    // Instance methods
 111    // ------------------------------------------------------------
 112   
 113    /**
 114    * Get the root cause, if any.
 115    *
 116    * @return The root cause of this exception, as a <code>Throwable</code>,
 117    * if this exception has a root cause, else <code>null</code>.
 118    */
 119  30 public Throwable getRootCause( )
 120    {
 121  30 return this.rootCause;
 122    }
 123   
 124    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 125    // java.lang.Exception
 126    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 127   
 128    /**
 129    * Retrieve the error message.
 130    *
 131    * @return The error message.
 132    */
 133  16 public String getMessage( )
 134    {
 135  16 String selfMessage = super.getMessage( );
 136   
 137  16 StringBuffer msg = new StringBuffer( );
 138   
 139  16 if ( selfMessage != null )
 140    {
 141  14 msg.append( selfMessage );
 142    }
 143   
 144  16 Throwable rootCause = getRootCause( );
 145   
 146  16 if ( rootCause != null )
 147    {
 148  1 if ( selfMessage != null )
 149    {
 150  0 msg.append( " : " );
 151    }
 152   
 153  1 msg.append( rootCause.getMessage( ) );
 154    }
 155   
 156  16 if ( msg.length( ) > 0 )
 157    {
 158  15 return msg.toString( );
 159    }
 160   
 161  1 return null;
 162    }
 163   
 164    /**
 165    * Retrieve the error message localized to the default locale.
 166    *
 167    * @return The error message.
 168    */
 169  2 public String getLocalizedMessage( )
 170    {
 171  2 StringBuffer msg = new StringBuffer( );
 172   
 173  2 Throwable rootCause = getRootCause( );
 174   
 175  2 if ( rootCause != null )
 176    {
 177  1 msg.append( rootCause.getLocalizedMessage( ) );
 178    }
 179    else
 180    {
 181  1 msg.append( super.getLocalizedMessage( ) );
 182    }
 183   
 184  2 if ( msg.length( ) > 0 )
 185    {
 186  2 return msg.toString( );
 187    }
 188   
 189  0 return null;
 190    }
 191   
 192    /**
 193    * Print the stack trace.
 194    *
 195    * @param s
 196    * The output sink.
 197    */
 198  0 public void printStackTrace( PrintStream s )
 199    {
 200  0 super.printStackTrace( s );
 201   
 202  0 Throwable rootCause = getRootCause( );
 203   
 204  0 if ( rootCause != null )
 205    {
 206  0 System.err.println( "Nested exception was: " );
 207  0 rootCause.printStackTrace( s );
 208    }
 209    }
 210   
 211    /**
 212    * Print the stack trace.
 213    *
 214    * @param s
 215    * The output sink.
 216    */
 217  0 public void printStackTrace( PrintWriter s )
 218    {
 219  0 super.printStackTrace( s );
 220   
 221  0 Throwable rootCause = getRootCause( );
 222   
 223  0 if ( rootCause != null )
 224    {
 225  0 System.err.println( "Nested exception was: " );
 226  0 rootCause.printStackTrace( s );
 227    }
 228    }
 229    }