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

📄 cartejb.java

📁 一个优秀的供应商管理系统
💻 JAVA
字号:
package apusic.myshop.cart.ejb;import java.util.List;import java.util.Iterator;import java.util.ArrayList;import java.util.Set;import java.util.Collection;import java.util.HashMap;import java.rmi.RemoteException;import javax.ejb.FinderException;import javax.ejb.SessionBean;import javax.ejb.SessionContext;import javax.ejb.EJBException;import javax.ejb.CreateException;import apusic.myshop.util.EJBUtil;import apusic.myshop.control.GeneralFailureException;import apusic.myshop.util.Debug;import apusic.myshop.product.ejb.ProductHome;import apusic.myshop.product.ejb.Product;import apusic.myshop.cart.model.CartModel;import apusic.myshop.cart.model.CartItem;public class CartEJB implements SessionBean  {  private HashMap cart;  public CartEJB() {    cart = new HashMap();  }  public CartModel getDetails() {    ArrayList items = new ArrayList();    try {      ProductHome productHome = EJBUtil.getProductHome();      Set keys = null;      if (cart != null) keys = cart.keySet();      Iterator it = null;      if (keys != null) it = keys.iterator();      while ((it != null) &&  it.hasNext()) {        String itemId = (String) it.next();        int qtyNeeded = ((Integer) cart.get(itemId)).intValue();        try {          Product product = productHome.findByProductId(itemId);          String cataId = product.getCatalog();          String productName = product.getName();          String style = product.getStyle();          double listPrice = product.getListPrice();          CartItem cartItem = new CartItem(            itemId, cataId, productName,            style, qtyNeeded, listPrice);          items.add(cartItem);        } catch (FinderException fe) {          throw new GeneralFailureException(fe);        }      }    } catch (RemoteException re) {      throw new GeneralFailureException(re);    }    CartModel model = new CartModel(items);    return model;  }  public void addItem (String itemNo) {    cart.put(itemNo, new Integer(1));  }  public void addItem (String itemNo,int qty) {    cart.put(itemNo, new Integer(qty));  }  public void deleteItem (String itemNo) {    cart.remove(itemNo);  }  public void updateItemQty (String itemNo, int newQty) {    cart.remove(itemNo);    cart.put(itemNo, new Integer(newQty));  }  public void empty () {    cart.clear();  }  public void ejbCreate() {    cart = new HashMap();  }  public void ejbCreate(HashMap starting) {    cart = (HashMap) starting.clone();  }  public void setSessionContext(SessionContext sc) {}  public void ejbRemove() {}  public void ejbActivate() {}  public void ejbPassivate() {}}

⌨️ 快捷键说明

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