package com.sun.j2ee.blueprints.petstore.controller.ejb;
import java.util.Collection;
import java.util.HashMap;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.RemoveException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.FinderException;
import com.sun.j2ee.blueprints.waf.exceptions.GeneralFailureException;
import com.sun.j2ee.blueprints.cart.ejb.ShoppingCartLocal;
import com.sun.j2ee.blueprints.cart.ejb.ShoppingCartLocalHome;
import com.sun.j2ee.blueprints.customer.ejb.CustomerLocal;
import com.sun.j2ee.blueprints.customer.ejb.CustomerLocalHome;
import com.sun.j2ee.blueprints.servicelocator.ejb.ServiceLocator;
import com.sun.j2ee.blueprints.servicelocator.ServiceLocatorException;
import com.sun.j2ee.blueprints.petstore.util.JNDINames;
public class ShoppingClientFacadeLocalEJB implements SessionBean {
private SessionContext sc = null;
private ShoppingCartLocal cart = null;
private CustomerLocal customer = null;
private String userId = null;
public ShoppingClientFacadeLocalEJB() {}
public void ejbCreate() {
}
public void setSessionContext(SessionContext sc) {
this.sc = sc;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public CustomerLocal getCustomer() throws FinderException {
if (userId == null) {
throw new GeneralFailureException("ShoppingClientFacade: failed to look up name of customer: userId is not set" );
}
try {
ServiceLocator sl = new ServiceLocator();
CustomerLocalHome home =(CustomerLocalHome)sl.getLocalHome(JNDINames.CUSTOMER_EJBHOME);
customer = home.findByPrimaryKey(userId);
} catch (ServiceLocatorException slx) {
throw new GeneralFailureException("ShoppingClientFacade: failed to look up name of customer: caught " + slx);
}
return customer;
}
public CustomerLocal createCustomer(String userId) {
try {
ServiceLocator sl = new ServiceLocator();
CustomerLocalHome home =(CustomerLocalHome)sl.getLocalHome(JNDINames.CUSTOMER_EJBHOME);
customer = home.create(userId);
this.userId = userId;
} catch (javax.ejb.CreateException ce) {
throw new GeneralFailureException("ShoppingClientFacade: failed to create customer: caught " + ce);
} catch (ServiceLocatorException slx) {
throw new GeneralFailureException("ShoppingClientFacade: failed to look up name of customer: caught " + slx);
}
return customer;
}
public ShoppingCartLocal getShoppingCart() {
if (cart == null) {
try {
ServiceLocator sl = new ServiceLocator();
ShoppingCartLocalHome home =(ShoppingCartLocalHome)sl.getLocalHome(JNDINames.SHOPPING_CART_EJBHOME);
cart = home.create();
} catch (javax.ejb.CreateException cx) {
throw new GeneralFailureException("ShoppingClientFacade: failed to create cart: caught " + cx);
} catch (ServiceLocatorException slx) {
throw new GeneralFailureException("ShoppingClientFacade: failed to look up name of cart: caught " + slx);
}
}
return cart;
}
public void ejbRemove() {
}
public void ejbActivate() {}
public void ejbPassivate() {}
}