/Users/lyon/j4p/src/net/server/sessions/DummyCart.java

1    /* 
2     * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved. 
3     * 
4     * This software is the confidential and proprietary information of Sun 
5     * Microsystems, Inc. ("Confidential Information").  You shall not 
6     * disclose such Confidential Information and shall use it only in 
7     * accordance with the terms of the license agreement you entered into 
8     * with Sun. 
9     * 
10    * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE 
11    * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
12    * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
13    * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES 
14    * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING 
15    * THIS SOFTWARE OR ITS DERIVATIVES. 
16    * 
17    */ 
18    
19   package net.server.sessions; 
20    
21   import javax.servlet.http.HttpServletRequest; 
22   import java.util.Vector; 
23    
24   public class DummyCart { 
25       Vector v = new Vector(); 
26       String submit = null; 
27       String item = null; 
28    
29       private void addItem(String name) { 
30           v.addElement(name); 
31       } 
32    
33       private void removeItem(String name) { 
34           v.removeElement(name); 
35       } 
36    
37       public void setItem(String name) { 
38           item = name; 
39       } 
40    
41       public void setSubmit(String s) { 
42           submit = s; 
43       } 
44    
45       public String[] getItems() { 
46           String[] s = new String[v.size()]; 
47           v.copyInto(s); 
48           return s; 
49       } 
50    
51       public void processRequest(HttpServletRequest request) { 
52           // null value for submit - user hit enter instead of clicking on 
53           // "add" or "remove" 
54           if (submit == null) 
55               addItem(item); 
56    
57           if (submit.equals("add")) 
58               addItem(item); 
59           else if (submit.equals("remove")) 
60               removeItem(item); 
61    
62           // reset at the end of the request 
63           reset(); 
64       } 
65    
66       // reset 
67       private void reset() { 
68           submit = null; 
69           item = null; 
70       } 
71   } 
72