Clover coverage report - Replica - 1.0-Alpha
Coverage timestamp: Dom Fev 1 2004 17:00:58 WET
file stats: LOC: 267   Methods: 46
NCLOC: 178   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
Log.java 0% 0% 0% 0%
coverage
 1   
 package nmp.util;
 2   
 
 3   
 import java.util.*;
 4   
 import java.io.*;
 5   
 
 6   
 /**
 7   
  * Class for logging.
 8   
  * There is a defaultLog, but application may have their own instance of the log.
 9   
  * It is supposed to be used in all projects. It is expected to evolve over time.
 10   
  */
 11   
 public class Log
 12   
 {
 13   
     static Log defaultLog;
 14   
 
 15   
     static {
 16  0
         defaultLog = new Log();
 17   
     }
 18   
     
 19   
     Vector v;
 20   
     
 21  0
     public Log() {
 22  0
         v = new Vector();
 23  0
         v.addElement( new PrintWriter( System.err));
 24   
     }
 25   
     
 26  0
     public void cleanSinkP() {
 27  0
         v.removeAllElements();
 28   
     }
 29   
     
 30  0
     public PrintWriter getWriterP() {
 31  0
         return new PrintWriter( new Writer() {
 32  0
             public void close() {
 33  0
                 for( int i = 0; i < v.size(); i++) {
 34  0
                     PrintWriter pw = (PrintWriter)v.elementAt( i);
 35  0
                     pw.close();
 36   
                 }
 37   
             }
 38  0
             public void flush() {
 39  0
                 for( int i = 0; i < v.size(); i++) {
 40  0
                     PrintWriter pw = (PrintWriter)v.elementAt( i);
 41  0
                     pw.flush();
 42   
                 }
 43   
             }
 44  0
             public void write(char[] cbuf, int off, int len) {
 45  0
                 for( int i = 0; i < v.size(); i++) {
 46  0
                     PrintWriter pw = (PrintWriter)v.elementAt( i);
 47  0
                     pw.write( cbuf, off, len );
 48  0
                     pw.flush();
 49   
                 }
 50   
             }
 51   
         });
 52   
     }
 53   
     
 54  0
     public void addSinkP( PrintWriter writer) {
 55  0
         v.addElement( writer);
 56   
     }
 57   
 
 58  0
     public void addSinkP( String filename, boolean append) throws IOException {
 59  0
         addSinkP( new PrintWriter( new FileWriter( filename, append)));
 60   
     }
 61   
 
 62  0
     public void addSinkP( String filename) throws IOException {
 63  0
         addSinkP( filename, false);
 64   
     }
 65   
 
 66   
     /**
 67   
      * Dums the error message. To be used only internally.
 68   
      */
 69  0
     private void messageP( String msg) {
 70  0
         for( int i = 0; i < v.size(); i++) {
 71  0
             PrintWriter pw = (PrintWriter)v.elementAt( i);
 72  0
             pw.println( msg);
 73  0
             pw.flush();
 74   
         }
 75   
     }
 76   
 
 77  0
     private void messageP( Throwable th) {
 78  0
         for( int i = 0; i < v.size(); i++) {
 79  0
             PrintWriter pw = (PrintWriter)v.elementAt( i);
 80  0
             th.printStackTrace( pw);
 81  0
             pw.flush();
 82   
         }
 83   
     }
 84   
 
 85   
     /**
 86   
      * Dumps a log message.
 87   
      */
 88  0
     public void logP( String msg) {
 89  0
         messageP( msg);
 90   
     }
 91   
     /**
 92   
      * Dumps a log message.
 93   
      */
 94  0
     public void logTraceP( String msg) {
 95  0
         messageP( msg);
 96  0
         messageP( new Throwable());
 97   
     }
 98   
 
 99   
 
 100   
     /**
 101   
      * Dumps an wanring message.
 102   
      */
 103  0
     public void warningP( String msg) {
 104  0
         messageP( "WARN:" + msg);
 105   
     }
 106   
 
 107   
     /**
 108   
      * Dumps an error message. Throws the given exception (if given).
 109   
      */
 110  0
     public void errorP( String msg) {
 111  0
         messageP( "ERROR:" + msg);
 112   
     }
 113   
 
 114  0
     public void errorP( Throwable th) {
 115  0
         messageP( "ERROR:" + th.getMessage());
 116   
     }
 117   
 
 118  0
     public void errorP( String msg, Throwable th) {
 119  0
         errorP( msg);
 120  0
         errorP( th);
 121   
     }
 122   
 
 123  0
     public void errorDumpP( Throwable th) {
 124  0
         errorP( th);
 125  0
         messageP( th);
 126   
     }
 127   
 
 128  0
     public void errorDumpP( String msg, Throwable th) {
 129  0
         errorP( msg);
 130  0
         messageP( th);
 131   
     }
 132   
 
 133  0
     public void errorThP( Throwable th) throws Throwable {
 134  0
         messageP( "ERROR:" + th.getMessage());
 135  0
         throw th;
 136   
     }
 137   
 
 138   
     /**
 139   
      * Dumps an internal error message. Throws the given exception (if given).
 140   
      */
 141  0
     public void internalErrorP( String msg) {
 142  0
         messageP( "INTERNAL ERROR:" + msg);
 143   
     }
 144   
 
 145  0
     public void internalErrorP( Throwable th) {
 146  0
         messageP( "INTERNAL ERROR:" + th.getMessage());
 147   
     }
 148   
 
 149  0
     public void internalErrorDumpP( Throwable th) {
 150  0
         internalErrorP( th);
 151  0
         messageP( th);
 152   
     }
 153   
 
 154  0
     public void internalErrorThP( Throwable th) throws Throwable {
 155  0
         messageP( "INTERNAL ERROR:" + th.getMessage());
 156  0
         throw th;
 157   
     }
 158   
 
 159   
     /**
 160   
      * Dumps a  fatal error message. Exits virtual machine.
 161   
      */
 162  0
     public void fatalErrorP( String msg) {
 163  0
         messageP( "FATAL ERROR:" + msg);
 164  0
         System.exit( 0);
 165   
     }
 166   
 
 167  0
     public void fatalErrorP( Throwable th) {
 168  0
         messageP( th);
 169  0
         System.exit( 0);
 170   
     }
 171   
 
 172  0
     public static void cleanSink() {
 173  0
         defaultLog.cleanSinkP();
 174   
     }
 175   
     
 176  0
     public static PrintWriter getWriter() {
 177  0
         return defaultLog.getWriterP();
 178   
     }
 179   
     
 180  0
     public static void addSink( PrintWriter writer) {
 181  0
         defaultLog.addSinkP( writer);
 182   
     }
 183   
 
 184  0
     public static void addSink( String filename, boolean append) throws IOException {
 185  0
         defaultLog.addSinkP( filename, append);
 186   
     }
 187   
 
 188  0
     public static void addSink( String filename) throws IOException {
 189  0
         defaultLog.addSinkP( filename);
 190   
     }
 191   
 
 192   
     /**
 193   
      * Dumps a log message.
 194   
      */
 195  0
     public static void log( String msg) {
 196  0
         defaultLog.logP( msg);
 197   
     }
 198  0
     public static void logTrace( String msg) {
 199  0
         defaultLog.logTraceP( msg);
 200   
     }
 201   
 
 202   
 
 203   
     /**
 204   
      * Dumps an wanring message.
 205   
      */
 206  0
     public static void warning( String msg) {
 207  0
         defaultLog.warningP( msg);
 208   
     }
 209   
 
 210   
     /**
 211   
      * Dumps an error message. Throws the given exception (if given).
 212   
      */
 213  0
     public static void error( String msg) {
 214  0
         defaultLog.errorP( msg);
 215   
     }
 216   
 
 217  0
     public static void error( String msg, Throwable th) {
 218  0
         defaultLog.errorP( msg, th);
 219   
     }
 220   
 
 221  0
     public static void error( Throwable th) {
 222  0
         defaultLog.errorP( th);
 223   
     }
 224   
 
 225  0
     public static void errorDump( String msg, Throwable th) {
 226  0
         defaultLog.errorDumpP( msg, th);
 227   
     }
 228   
 
 229  0
     public static void errorDump( Throwable th) {
 230  0
         defaultLog.errorDumpP( th);
 231   
     }
 232   
 
 233  0
     public static void errorTh( Throwable th) throws Throwable {
 234  0
         defaultLog.errorThP( th);
 235   
     }
 236   
 
 237   
     /**
 238   
      * Dumps an internal error message. Throws the given exception (if given).
 239   
      */
 240  0
     public static void internalError( String msg) {
 241  0
         defaultLog.internalErrorP( msg);
 242   
     }
 243   
 
 244  0
     public static void internalError( Throwable th) {
 245  0
         defaultLog.internalErrorP( th);
 246   
     }
 247   
 
 248  0
     public static void internalErrorDump( Throwable th) {
 249  0
         defaultLog.internalErrorDumpP( th);
 250   
     }
 251   
 
 252  0
     public static void internalErrorTh( Throwable th) throws Throwable {
 253  0
         defaultLog.internalErrorThP( th);
 254   
     }
 255   
 
 256   
     /**
 257   
      * Dumps a  fatal error message. Exits virtual machine.
 258   
      */
 259  0
     public static void fatalError( String msg) {
 260  0
         defaultLog.fatalErrorP( msg);
 261   
     }
 262   
 
 263  0
     public static void fatalError( Throwable th) {
 264  0
         defaultLog.fatalErrorP( th);
 265   
     }
 266   
 }
 267