package com.eactive.eai.authoutbound.client;

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

import java.util.concurrent.ConcurrentHashMap;

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

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

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

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

		return service;
	}
}
