package com.eactive.eai.adapter.http.dynamic;

import java.util.concurrent.ConcurrentHashMap;

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

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

	/**
	 * 
	 */
	public HttpAdapterServiceFactory() {
		super();
	}

	/**
	 * 공통코드 HTTP_ADAPTER_SERVICE_CLASS 에 정의된 구현체를 생성 한다.
	 * 
	 * @param className
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static HttpAdapterService createFactory(String className) {
		if (h.containsKey(className)) {
			return h.get(className);
		}

		HttpAdapterService service = null;
		try {
			Class cl = Class.forName(className);
			service = (HttpAdapterService) cl.newInstance();
			if (service != null) {
				h.put(className, service);
			}
		} catch (Exception e) {
			logger.error("Cannot create a HttpAdapterService. - {}", className);
		}

		return service;
	}
}
