KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > cart > DummyCart


1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */

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