001: /*
002: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. U.S.
003: * Government Rights - Commercial software. Government users are subject
004: * to the Sun Microsystems, Inc. standard license agreement and
005: * applicable provisions of the FAR and its supplements. Use is subject
006: * to license terms.
007: *
008: * This distribution may include materials developed by third parties.
009: * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
010: * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
011: * other countries.
012: *
013: * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
014: *
015: * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
016: * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
017: * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
018: * en vigueur de la FAR (Federal Acquisition Regulations) et des
019: * supplements a celles-ci. Distribue par des licences qui en
020: * restreignent l'utilisation.
021: *
022: * Cette distribution peut comprendre des composants developpes par des
023: * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
024: * sont des marques de fabrique ou des marques deposees de Sun
025: * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
026: */
027:
028: package cart;
029:
030: import exception.BookException;
031: import java.util.Vector;
032: import javax.ejb.*;
033: import util.IdVerifier;
034:
035: public class CartBean implements SessionBean, CartRemoteBusiness,
036: CartLocalBusiness {
037: private SessionContext context;
038: String customerName;
039: String customerId;
040: Vector contents;
041:
042: // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">
043: // TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
044: // TODO Add business methods
045: /**
046: * @see SessionBean#setSessionContext(SessionContext)
047: */
048: public void setSessionContext(SessionContext aContext) {
049: context = aContext;
050: }
051:
052: /**
053: * @see SessionBean#ejbActivate()
054: */
055: public void ejbActivate() {
056:
057: }
058:
059: /**
060: * @see SessionBean#ejbPassivate()
061: */
062: public void ejbPassivate() {
063:
064: }
065:
066: /**
067: * @see SessionBean#ejbRemove()
068: */
069: public void ejbRemove() {
070:
071: }
072:
073: // </editor-fold>
074:
075: /**
076: * See section 7.10.3 of the EJB 2.0 specification
077: * See section 7.11.3 of the EJB 2.1 specification
078: */
079: public void ejbCreate() {
080: // TODO implement ejbCreate if necessary, acquire resources
081: // This method has access to the JNDI context so resource aquisition
082: // spanning all methods can be performed here such as home interfaces
083: // and data sources.
084: }
085:
086: // Enter business methods below. (Right-click in editor and choose
087: // EJB Methods > Add Business Method)
088:
089: public void ejbCreate(String person) throws CreateException {
090: //TODO implement
091: if (person == null) {
092: throw new CreateException("Null person not allowed.");
093: } else {
094: customerName = person;
095: }
096: customerId = "0";
097: contents = new Vector();
098: }
099:
100: public void ejbCreate(String person, String id)
101: throws CreateException {
102: //TODO implement
103: if (person == null) {
104: throw new CreateException("Null person not allowed.");
105: } else {
106: customerName = person;
107: }
108:
109: IdVerifier idChecker = new IdVerifier();
110: if (idChecker.validate(id)) {
111: customerId = id;
112: } else {
113: throw new CreateException("Invalid id: " + id);
114: }
115: contents = new Vector();
116: }
117:
118: public void addBook(String title) {
119: //TODO implement addBook
120: contents.add(title);
121: }
122:
123: public void removeBook(String title) throws BookException {
124: //TODO implement removeBook
125: boolean result = contents.remove(title);
126: if (result == false)
127: throw new BookException(title + " not in cart.");
128: }
129:
130: public Vector getContents() {
131: //TODO implement getContents
132: return contents;
133: }
134:
135: }
|