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

📄 cartbean.java

📁 JavaeeTutorial5的源代码。
💻 JAVA
字号:
/* * Copyright 2007 Sun Microsystems, Inc. * All rights reserved.  You may not modify, use, * reproduce, or distribute this software except in * compliance with  the terms of the License at: * http://developer.sun.com/berkeley_license.html */package cart.ejb;import cart.util.BookException;import cart.util.IdVerifier;import java.util.ArrayList;import java.util.List;import javax.ejb.Remove;import javax.ejb.Stateful;@Stateful()public class CartBean implements Cart {    List<String> contents;    String customerId;    String customerName;    public void initialize(String person) throws BookException {        if (person == null) {            throw new BookException("Null person not allowed.");        } else {            customerName = person;        }        customerId = "0";        contents = new ArrayList<String>();    }    public void initialize(        String person,        String id) throws BookException {        if (person == null) {            throw new BookException("Null person not allowed.");        } else {            customerName = person;        }        IdVerifier idChecker = new IdVerifier();        if (idChecker.validate(id)) {            customerId = id;        } else {            throw new BookException("Invalid id: " + id);        }        contents = new ArrayList<String>();    }    public void addBook(String title) {        contents.add(title);    }    public void removeBook(String title) throws BookException {        boolean result = contents.remove(title);        if (result == false) {            throw new BookException("\"" + title + "\" not in cart.");        }    }    public List<String> getContents() {        return contents;    }    @Remove()    public void remove() {        contents = null;    }}

⌨️ 快捷键说明

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