package dao;

import javax.servlet.http.HttpServlet;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class FacadeDAO {

	private static FacadeDAO instance = null;
	private WebApplicationContext context = null;

	public static FacadeDAO getInstance(HttpServlet servlet) {
		if (instance == null) {
			instance = new FacadeDAO(servlet);
		}
		return instance;
	}

	private FacadeDAO(HttpServlet servlet) {
		super();
		context = WebApplicationContextUtils
				.getRequiredWebApplicationContext(servlet.getServletContext());
	}

	private Object getBean(String nomeBean) {
		return context.getBean(nomeBean);
	}

	public AlunoDAO getAlunoDAO() {
		return (AlunoDAO)getBean("alunoDao");
	}

	public CursoDAO getCursoDAO() {
		return (CursoDAO)getBean("cursoDao");
	}

	public DisciplinaDAO getDisciplinaDAO() {
		return (DisciplinaDAO)getBean("disciplinaDao");
	}

	public EmentaDAO getEmentaDAO() {
		return (EmentaDAO)getBean("ementaDao");
	}

	public MensalidadeDAO getMensalidadeDAO() {
		return (MensalidadeDAO)getBean("mensalidadeDao");
	}

	public ProfessorDAO getProfessorDAO() {
		return (ProfessorDAO)getBean("professorDao");
	}

	public SalaDAO getSalaDAO() {
		return (SalaDAO)getBean("salaDao");
	}

	public TurmaDAO getTurmaDAO() {
		return (TurmaDAO)getBean("turmaDao");
	}

	public UsuarioDAO getUsuarioDAO() {
		return (UsuarioDAO)getBean("usuarioDao");
	}

}
