KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > error > ErrorHandlerFactory


1 /*
2  * Created on 05.07.2004
3  * Created by crappy eclipse.
4  */

5 package org.jzonic.jlo.error;
6
7 import java.io.InputStream JavaDoc;
8 import java.util.Properties JavaDoc;
9
10 /**
11  * @author Mecky
12  */

13 public class ErrorHandlerFactory {
14     
15     private static final ErrorReporter defaultReporter = new NullDeviceErrorReporter();
16     
17     private static ErrorReporter er = null;
18     
19     public static ErrorReporter getErrorReporter() {
20         if ( er == null ) {
21             String JavaDoc tmp = System.getProperty("jlo.errorhandler");
22             if ( tmp != null ) {
23                 try {
24                     er = (ErrorReporter)Class.forName(tmp).newInstance();
25                 }
26                 catch (Exception JavaDoc e) {
27                     e.printStackTrace();
28                     er = defaultReporter;
29                 }
30             }
31             else {
32                 try {
33                     ClassLoader JavaDoc cl = ErrorHandlerFactory.class.getClass().getClassLoader();
34                     InputStream JavaDoc fis = cl.getResourceAsStream("jlo.properties");
35                     if ( fis == null ) {
36                         er = defaultReporter;
37                     }
38                     else {
39                         Properties JavaDoc properties = new Properties JavaDoc();
40                         properties.load(fis);
41                         String JavaDoc ptype = properties.getProperty("jlo.errorhandler");
42                         if ( ptype != null ) {
43                             er = (ErrorReporter)Class.forName(ptype).newInstance();
44                         }
45                         else {
46                             er = defaultReporter;
47                         }
48                     }
49                 }
50                 catch (Exception JavaDoc e) {
51                     er = defaultReporter;
52                 }
53             }
54         }
55         return er;
56     }
57 }
58
Popular Tags