package com.openbanking.eai.common.token.client;

import java.util.concurrent.ConcurrentHashMap;

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

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

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

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

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

		return service;
	}
}
