package br.com.senac.dao;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.beans.factory.access.SingletonBeanFactoryLocator;

/**
 * Singleton FacadeJPA
 * 
 * @author Ismael H F Santos
 */
public class DAOFactory {
	public static DAOFactory getInstance() {
		if (instance == null) {
			instance = new DAOFactory();
		}
		return instance;
	}

	// --------------------------------------------------
	// Public methods
	// --------------------------------------------------
	public void setClienteDAO(ClienteDAO cDAO) {
		this.clienteDAO = cDAO;
	}

	public ClienteDAO getClienteDAO() {
		return clienteDAO;
	}

	public void setEmailDAO(EmailDAO eDAO) {
		this.emailDAO = eDAO;
	}

	public EmailDAO getEmailDAO() {
		return emailDAO;
	}
	// --------------------------------------------------
	// Private methods
	// --------------------------------------------------
	private DAOFactory() {
		BeanFactoryLocator bfLocator = SingletonBeanFactoryLocator
				.getInstance();
		BeanFactoryReference bfReference = bfLocator
				.useBeanFactory("spring.config");
		BeanFactory factory = bfReference.getFactory();

		clienteDAO = (ClienteDAO) factory.getBean("clienteDAO");
		emailDAO = (EmailDAO) factory.getBean("emailDAO");
	}

	// --------------------------------------------------
	// Private attributes
	// --------------------------------------------------
	 private static DAOFactory instance = null;
	 private ClienteDAO clienteDAO;
	 private EmailDAO emailDAO;
}
