1 5 package org.jzonic.jlo.error; 6 7 import java.io.InputStream ; 8 import java.util.Properties ; 9 10 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 tmp = System.getProperty("jlo.errorhandler"); 22 if ( tmp != null ) { 23 try { 24 er = (ErrorReporter)Class.forName(tmp).newInstance(); 25 } 26 catch (Exception e) { 27 e.printStackTrace(); 28 er = defaultReporter; 29 } 30 } 31 else { 32 try { 33 ClassLoader cl = ErrorHandlerFactory.class.getClass().getClassLoader(); 34 InputStream fis = cl.getResourceAsStream("jlo.properties"); 35 if ( fis == null ) { 36 er = defaultReporter; 37 } 38 else { 39 Properties properties = new Properties (); 40 properties.load(fis); 41 String 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 e) { 51 er = defaultReporter; 52 } 53 } 54 } 55 return er; 56 } 57 } 58 | Popular Tags |