⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shoppingclientcontrollerejb.java

📁 一个优秀的供应商管理系统
💻 JAVA
字号:
package apusic.myshop.control.ejb;import java.util.Collection;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 apusic.myshop.util.Debug;import apusic.myshop.util.EJBUtil;import apusic.myshop.cart.ejb.Cart;import apusic.myshop.cart.ejb.CartHome;import apusic.myshop.customer.ejb.Customer;import apusic.myshop.customer.ejb.CustomerHome;import apusic.myshop.control.event.BaseEvent;import apusic.myshop.control.EventException;import apusic.myshop.control.ejb.StateMachine;import apusic.myshop.order.ejb.OrderHome;import apusic.myshop.order.ejb.Order;/** * Session Bean implementation for ShoppingClientController EJB. */public class ShoppingClientControllerEJB implements SessionBean {  private StateMachine sm;  private SessionContext sc;  private Cart cart;  private Customer customer;  public ShoppingClientControllerEJB() {}  public Collection handleEvent(BaseEvent be)    throws EventException {    try {      return (sm.handleEvent(be));    } catch (RemoteException re) {//      re.printStackTrace();      throw new EJBException (re);    }  }  public Collection getOrders(String userId)	  throws FinderException {    Collection orders = null;	  try {      OrderHome home = EJBUtil.getOrderHome();      orders = home.findUserOrders(userId);	  } catch (RemoteException re) {	    throw new EJBException (re);	  }    return orders;  }  public Order getOrder(int requestId)    throws FinderException {    Order order = null;    int orderId = sm.getOrderId(requestId);    try {        if (requestId != -1) {          OrderHome home = EJBUtil.getOrderHome();          order= home.findByOrderId(orderId);        }	  } catch (RemoteException re) {	    throw new EJBException (re);	  }    return order;  }  /** @return the session EJB associated with this session. */  public Cart getCart() {    if (cart == null) {      try {        CartHome cartHome = EJBUtil.getCartHome();        cart = cartHome.create();      } catch (CreateException ce) {        throw new EJBException(ce);      } catch (RemoteException re) {        throw new EJBException(re);	    }    }    return cart;  }  public Customer getCustomer() {    if (customer == null) {      try {        String userId = sc.getCallerPrincipal().getName();        CustomerHome home = EJBUtil.getCustomerHome();        customer = home.findByUserId(userId);      } catch (FinderException fe) {        throw new EJBException(fe);      } catch (RemoteException re) {        throw new EJBException(re);	    }    }    return customer;  }  public void ejbCreate() {    sm = new StateMachine(this);  }  public void setSessionContext(SessionContext sc) {    this.sc = sc;  }  public void ejbRemove() {    //sm = null;    // this method will be called at the time of sign off.    // destroy all the EJB's created by the shopping client	  // controller.    if (cart != null) {      try {        cart.remove();        cart = null;      } catch (RemoteException re) {        throw new EJBException(re);      } catch (RemoveException re) {        throw new EJBException(re);      }    }    //acct = null;  }  public void ejbActivate() {}  public void ejbPassivate() {}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -