01: package org.jzonic.jlo.handler;
02:
03: import org.jzonic.jlo.error.ErrorHandler;
04: import java.lang.reflect.Constructor;
05:
06: /**
07: * <p>Überschrift: </p>
08: * <p>Beschreibung: </p>
09: * <p>Copyright: Copyright (c) 2002</p>
10: * <p>Organisation: </p>
11: * @author unbekannt
12: * @version 1.0
13: */
14:
15: public class HandlerFactory {
16:
17: private HandlerFactory() {
18: }
19:
20: /**
21: * TODO: use a HashMap to store the handlers?
22: */
23: public static Handler getHandler(String name,
24: String configurationName) {
25: if (name == null) {
26: return new ConsoleHandler(configurationName);
27: }
28: if (name.indexOf(".") == -1) {
29: name = "org.jzonic.jlo.handler." + name;
30: }
31: try {
32: Class c = Class.forName(name);
33: Constructor con = c
34: .getDeclaredConstructor(new Class[] { String.class });
35: Handler hndl = (Handler) con
36: .newInstance(new Object[] { new String(
37: configurationName) });
38: return hndl;
39: } catch (Exception e) {
40: ErrorHandler.reportError(
41: "Exception while instantiating the handler: "
42: + name, e);
43: return new ConsoleHandler("Default");
44: }
45: }
46: }
|