1 package org.jzonic.jlo.handler; 2 3 import org.jzonic.jlo.error.ErrorHandler; 4 import java.lang.reflect.Constructor ; 5 13 14 public class HandlerFactory { 15 16 private HandlerFactory() { 17 } 18 19 22 public static Handler getHandler(String name,String configurationName) { 23 if ( name == null ) { 24 return new ConsoleHandler(configurationName); 25 } 26 if ( name.indexOf(".") == -1 ) { 27 name = "org.jzonic.jlo.handler."+name; 28 } 29 try { 30 Class c = Class.forName(name); 31 Constructor con = c.getDeclaredConstructor(new Class []{String .class}); 32 Handler hndl = (Handler)con.newInstance(new Object []{new String (configurationName)}); 33 return hndl; 34 } catch (Exception e) { 35 ErrorHandler.reportError("Exception while instantiating the handler: " + name,e); 36 return new ConsoleHandler("Default"); 37 } 38 } 39 } | Popular Tags |