KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cart > CartBean


1 /*
2  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. U.S.
3  * Government Rights - Commercial software. Government users are subject
4  * to the Sun Microsystems, Inc. standard license agreement and
5  * applicable provisions of the FAR and its supplements. Use is subject
6  * to license terms.
7  *
8  * This distribution may include materials developed by third parties.
9  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
10  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
11  * other countries.
12  *
13  * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
14  *
15  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
16  * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
17  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
18  * en vigueur de la FAR (Federal Acquisition Regulations) et des
19  * supplements a celles-ci. Distribue par des licences qui en
20  * restreignent l'utilisation.
21  *
22  * Cette distribution peut comprendre des composants developpes par des
23  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
24  * sont des marques de fabrique ou des marques deposees de Sun
25  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
26  */

27
28 package cart;
29
30 import exception.BookException;
31 import java.util.Vector JavaDoc;
32 import javax.ejb.*;
33 import util.IdVerifier;
34
35 public class CartBean implements SessionBean, CartRemoteBusiness, CartLocalBusiness {
36     private SessionContext context;
37     String JavaDoc customerName;
38     String JavaDoc customerId;
39     Vector JavaDoc contents;
40     
41     // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click the + sign on the left to edit the code.">
42
// TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
43
// TODO Add business methods
44
/**
45      * @see SessionBean#setSessionContext(SessionContext)
46      */

47     public void setSessionContext(SessionContext aContext) {
48         context = aContext;
49     }
50     
51     /**
52      * @see SessionBean#ejbActivate()
53      */

54     public void ejbActivate() {
55         
56     }
57     
58     /**
59      * @see SessionBean#ejbPassivate()
60      */

61     public void ejbPassivate() {
62         
63     }
64     
65     /**
66      * @see SessionBean#ejbRemove()
67      */

68     public void ejbRemove() {
69         
70     }
71     // </editor-fold>
72

73     /**
74      * See section 7.10.3 of the EJB 2.0 specification
75      * See section 7.11.3 of the EJB 2.1 specification
76      */

77     public void ejbCreate() {
78         // TODO implement ejbCreate if necessary, acquire resources
79
// This method has access to the JNDI context so resource aquisition
80
// spanning all methods can be performed here such as home interfaces
81
// and data sources.
82
}
83     
84     
85     
86     
87     
88     // Enter business methods below. (Right-click in editor and choose
89
// EJB Methods > Add Business Method)
90

91     public void ejbCreate(String JavaDoc person) throws CreateException {
92         //TODO implement
93
if(person == null) {
94             throw new CreateException("Null person not allowed.");
95         }else{
96             customerName = person;
97         }
98         customerId = "0";
99         contents = new Vector JavaDoc();
100     }
101
102     public void ejbCreate(String JavaDoc person, String JavaDoc id) throws CreateException {
103         //TODO implement
104
if(person == null) {
105             throw new CreateException("Null person not allowed.");
106         }else{
107             customerName = person;
108         }
109         
110         IdVerifier idChecker = new IdVerifier();
111         if(idChecker.validate(id)){
112             customerId = id;
113         }else{
114             throw new CreateException("Invalid id: " + id);
115         }
116         contents = new Vector JavaDoc();
117     }
118
119     public void addBook(String JavaDoc title) {
120         //TODO implement addBook
121
contents.add(title);
122     }
123
124     public void removeBook(String JavaDoc title) throws BookException {
125         //TODO implement removeBook
126
boolean result = contents.remove(title);
127         if(result == false)
128             throw new BookException(title + " not in cart.");
129     }
130
131     public Vector JavaDoc getContents() {
132         //TODO implement getContents
133
return contents;
134     }
135     
136 }
137
Popular Tags