cartbean.java

来自「JavaeeTutorial5的源代码。」· Java 代码 · 共 80 行

JAVA
80
字号
/* * 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.secure.ejb;import java.util.ArrayList;import java.util.List;import javax.ejb.Remove;import javax.ejb.Stateful;import javax.annotation.security.RolesAllowed;@Statefulpublic 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>();    }    @RolesAllowed("CartUser")    public void addBook(String title) {        contents.add(title);    }    @RolesAllowed("CartUser")    public void removeBook(String title) throws BookException {        boolean result = contents.remove(title);        if (result == false) {            throw new BookException("\"" + title + "\" not in cart.");        }    }    @RolesAllowed("CartUser")    public List<String> getContents() {        return contents;    }    @Remove()    public void remove() {        contents = null;    }}

⌨️ 快捷键说明

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