Package org.jzonic.jlo.handler

Source Code of org.jzonic.jlo.handler.HandlerFactory

package org.jzonic.jlo.handler;

import org.jzonic.jlo.error.ErrorHandler;
import java.lang.reflect.Constructor;
/**
* <p>�berschrift: </p>
* <p>Beschreibung: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Organisation: </p>
* @author unbekannt
* @version 1.0
*/

public class HandlerFactory {
   
    private HandlerFactory() {
    }
   
    /**
     * TODO: use a HashMap to store the handlers?
     */
    public static Handler getHandler(String name,String configurationName) {
        if ( name == null ) {
            return new ConsoleHandler(configurationName);
        }
        if ( name.indexOf("."== -1 ) {
            name = "org.jzonic.jlo.handler."+name;
        }
        try {
            Class c = Class.forName(name);
            Constructor con = c.getDeclaredConstructor(new Class[]{String.class});
            Handler hndl = (Handler)con.newInstance(new Object[]{new String(configurationName)});
            return hndl;
        } catch (Exception e) {
            ErrorHandler.reportError("Exception while instantiating the handler: " + name,e);
            return new ConsoleHandler("Default");
        }
    }
}
TOP

Related Classes of org.jzonic.jlo.handler.HandlerFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.