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

📄 modelmanager.java

📁 一个优秀的供应商管理系统
💻 JAVA
字号:
package apusic.myshop.control.web;import java.util.HashMap;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import java.rmi.RemoteException;import javax.ejb.CreateException;import javax.ejb.FinderException;import javax.servlet.http.HttpSession;import javax.servlet.ServletContext;import apusic.myshop.util.EJBUtil;import apusic.myshop.cart.ejb.Cart;import apusic.myshop.control.ejb.ShoppingClientController;import apusic.myshop.control.web.ShoppingClientControllerWebImpl;import apusic.myshop.cart.web.CartWebImpl;import apusic.myshop.cart.model.CartModel;import apusic.myshop.customer.ejb.Customer;import apusic.myshop.customer.ejb.CustomerHome;import apusic.myshop.customer.model.CustomerModel;import apusic.myshop.customer.web.CustomerWebImpl;import apusic.myshop.order.ejb.Order;import apusic.myshop.util.WebKeys;import apusic.myshop.util.Debug;import apusic.myshop.control.GeneralFailureException;//具体的主题public class ModelManager extends ModelUpdateNotifier {//初始化  private ServletContext context;  private HttpSession session;  private ShoppingClientController sccEjb = null;  private ShoppingClientControllerWebImpl scc = null;  private Cart cartEjb = null;  private Customer custEjb = null;//构造函数空  public ModelManager() { }//初始化操作  public void init(ServletContext context,HttpSession session) {    Debug.println("Init model manager");    this.session = session;    this.context = context;    getCustomerModel();    Debug.println("Init model manager end");  }  public void setSCC(ShoppingClientControllerWebImpl scc) {    this.scc = scc;  }  public ShoppingClientController getSCCEJB() {    if (sccEjb == null) {      try {        sccEjb = EJBUtil.getSCCHome().create();      } catch (CreateException ce) {        throw new GeneralFailureException(ce);      } catch (RemoteException re) {        throw new GeneralFailureException(re);      }    }    return sccEjb;  }  public Order getOrderEJB(int requestId) {	  if (scc == null) {	    throw new GeneralFailureException("Can not get order EJB");	  } else {	    return scc.getOrderEJB(requestId);	  }  }/*  public Customer getCustomerEJB() {    if (custEjb == null) {	    if (scc == null) {        throw new GeneralFailureException("Can not get Customer EJB");	    } else {        custEjb = scc.getCustomerEJB();	    }    }    return custEjb;  }*/  public Customer getCustomerEJB() {    try {      String userId = (String)session.getAttribute(WebKeys.UserIdKey);      if (userId != null && (!userId.equals(""))) {        CustomerHome home = EJBUtil.getCustomerHome();        custEjb = home.findByUserId(userId);      }    } catch (FinderException fe) {      throw new GeneralFailureException(fe);    } catch (RemoteException re) {      throw new GeneralFailureException(re);    }    return custEjb;  }  public CustomerModel getCustomerModel() {	  CustomerModel cust = (CustomerModel)session.getAttribute(WebKeys.CustomerModelKey);    if (cust == null) {	    cust = new CustomerWebImpl(this);	    session.setAttribute(WebKeys.CustomerModelKey, cust);	  }	  return cust;  }  public Cart getCartEJB() {	  if (cartEjb == null) {      if (scc == null) {        throw new GeneralFailureException("Can not get shopping cart EJB");      } else {        cartEjb = scc.getCartEJB();      }    }    return cartEjb;  }  public CartModel getCartModel() {    CartWebImpl cart = (CartWebImpl)session.getAttribute(WebKeys.CartModelKey);    if (cart == null) {      cart = new CartWebImpl();      cart.init(session);      session.setAttribute(WebKeys.CartModelKey, cart);    }    return cart;  }}

⌨️ 快捷键说明

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