package managedbean.profile;

import java.util.Properties;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;

import ejb.profile.ProfileFacadeRemote;

/***
 * 
 * @author Marcos García Núñez (mgarcianun@uoc.edu)
 *
 */
@Named("profileMBean")
public class ProfileMBeanBase {
	@EJB
	protected ProfileFacadeRemote remoteManager;

	/**
	 * Inicializa la conexión con el EJB Remoto
	 * 
	 * @throws Exception
	 */
	protected void initializeProfileFacadeRemote() throws Exception {
		Properties props = System.getProperties();
		Context ctx = new InitialContext(props);
		remoteManager = (ProfileFacadeRemote) ctx.lookup("java:app/MyHealth.jar/ProfileFacadeBean!ejb.profile.ProfileFacadeRemote");
	}

	protected void addFacesMessage(FacesMessage.Severity severity, String summary, String detail) {
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, summary, detail));
	}

	protected void manageException(Exception ex) {
		this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Se ha producido un error inesperado", "Descripción del error: " + ex.getLocalizedMessage());
	}
}
