package juno2Beans.acctList;

import Juno2.AccountListCVO;
import Juno2.CmdDAO;
import Juno2.CmdDAOFactory;

/**
 * Bean implementation class for Enterprise Bean: CmdAccountList
 */
public class CmdAccountListBean implements javax.ejb.SessionBean {
	private javax.ejb.SessionContext mySessionCtx;
	/**
	 * getSessionContext
	 */
	public javax.ejb.SessionContext getSessionContext() {
		return mySessionCtx;
	}
	/**
	 * setSessionContext
	 */
	public void setSessionContext(javax.ejb.SessionContext ctx) {
		mySessionCtx = ctx;
	}
	/**
	 * ejbActivate
	 */
	public void ejbActivate() {
	}
	/**
	 * ejbCreate
	 */
	public void ejbCreate() throws javax.ejb.CreateException {
	}
	/**
	 * ejbPassivate
	 */
	public void ejbPassivate() {
	}
	/**
	 * ejbRemove
	 */
	public void ejbRemove() {
	}
	
	public AccountListCVO doAccountList(String userId, String userPassword) throws java.lang.Exception
	{

		AccountListCVO alcvo = new Juno2.AccountListCVO();
		
        ////If session already exists call session.invalidate();
		CmdDAOFactory daoFactory = CmdDAOFactory.getInstance();
        CmdDAO cdao = daoFactory.getDAO();
		alcvo.setLoginVO(cdao.getLogin(userId, userPassword));

		if(alcvo.getLoginState()) {
			alcvo.setAccountList(cdao.getAccountList(alcvo.getUserId()));	     
        }
        //// in the event of error return alcvo with the bad login state
        ////else
        ////{
        ////    throw new CmdException("Fatal error Session and Request user conflict.");
        ////}
        
        System.out.println("***Printing from within the EJB result***");
        String strFirstName = alcvo.getFirstName();
        String strLastName = alcvo.getLastName();
        System.out.println("lastName " + strLastName);
		System.out.println("the first name is :" + strFirstName);
		System.out.println("the last name is :" + strLastName);
		//return strFirstName;
		
		return(alcvo);        
 	}
}
