KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > handler > HandlerFactory


1 package org.jzonic.jlo.handler;
2
3 import org.jzonic.jlo.error.ErrorHandler;
4 import java.lang.reflect.Constructor JavaDoc;
5 /**
6  * <p>Überschrift: </p>
7  * <p>Beschreibung: </p>
8  * <p>Copyright: Copyright (c) 2002</p>
9  * <p>Organisation: </p>
10  * @author unbekannt
11  * @version 1.0
12  */

13
14 public class HandlerFactory {
15     
16     private HandlerFactory() {
17     }
18     
19     /**
20      * TODO: use a HashMap to store the handlers?
21      */

22     public static Handler getHandler(String JavaDoc name,String JavaDoc 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 JavaDoc c = Class.forName(name);
31             Constructor JavaDoc con = c.getDeclaredConstructor(new Class JavaDoc[]{String JavaDoc.class});
32             Handler hndl = (Handler)con.newInstance(new Object JavaDoc[]{new String JavaDoc(configurationName)});
33             return hndl;
34         } catch (Exception JavaDoc e) {
35             ErrorHandler.reportError("Exception while instantiating the handler: " + name,e);
36             return new ConsoleHandler("Default");
37         }
38     }
39 }
Popular Tags