package com.eactive.eai.adapter.handler;

import java.util.concurrent.ConcurrentHashMap;

import com.eactive.eai.common.util.Logger;

public class AdapterErrorMessageHandlerFactory { 
    static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
	static private ConcurrentHashMap<String, AdapterErrorMessageHandler> h = new ConcurrentHashMap<String, AdapterErrorMessageHandler>();

	@SuppressWarnings("rawtypes")
	public static AdapterErrorMessageHandler createHandler(String handlerClassName) {
		if (h.containsKey(handlerClassName)) {
			return (AdapterErrorMessageHandler) h.get(handlerClassName);
		}

		AdapterErrorMessageHandler handler = null;
		try {
			Class cl = Class.forName(handlerClassName);
			handler = (AdapterErrorMessageHandler) cl.newInstance();
		} catch (Exception e) {
			logger.error("Cannot create a AdapterErrorMessageHandler. - {}", handlerClassName);
		}
		if (handler != null) {
			h.put(handlerClassName, handler);
			return handler;
		} else {
			return null;
		}
	}
} 
