?? modelmanager.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 + -