KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sessions > DummyCart


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27 package sessions;
28
29 import javax.servlet.http.*;
30 import java.util.Vector JavaDoc;
31 import java.util.Enumeration JavaDoc;
32
33 public class DummyCart {
34     Vector JavaDoc v = new Vector JavaDoc();
35     String JavaDoc submit = null;
36     String JavaDoc item = null;
37     
38     private void addItem(String JavaDoc name) {
39     v.addElement(name);
40     }
41
42     private void removeItem(String JavaDoc name) {
43     v.removeElement(name);
44     }
45
46     public void setItem(String JavaDoc name) {
47     item = name;
48     }
49     
50     public void setSubmit(String JavaDoc s) {
51     submit = s;
52     }
53
54     public String JavaDoc[] getItems() {
55     String JavaDoc[] s = new String JavaDoc[v.size()];
56     v.copyInto(s);
57     return s;
58     }
59     
60     public void processRequest(HttpServletRequest request) {
61     // null value for submit - user hit enter instead of clicking on
62
// "add" or "remove"
63
if (submit == null)
64         addItem(item);
65
66     if (submit.equals("add"))
67         addItem(item);
68     else if (submit.equals("remove"))
69         removeItem(item);
70     
71     // reset at the end of the request
72
reset();
73     }
74
75     // reset
76
private void reset() {
77     submit = null;
78     item = null;
79     }
80 }
81
Popular Tags