DummyCart.java
上传用户:bj_pst
上传日期:2019-07-07
资源大小:7353k
文件大小:2k
源码类别:

Java编程

开发平台:

Java

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements.  See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License.  You may obtain a copy of the License at
  8. *
  9. *     http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package sessions;
  18. import java.util.Vector;
  19. public class DummyCart {
  20.     Vector v = new Vector();
  21.     String submit = null;
  22.     String item = null;
  23.     
  24.     private void addItem(String name) {
  25.         v.addElement(name);
  26.     }
  27.     private void removeItem(String name) {
  28.         v.removeElement(name);
  29.     }
  30.     public void setItem(String name) {
  31.         item = name;
  32.     }
  33.     
  34.     public void setSubmit(String s) {
  35.         submit = s;
  36.     }
  37.     public String[] getItems() {
  38.         String[] s = new String[v.size()];
  39.         v.copyInto(s);
  40.         return s;
  41.     }
  42.     
  43.     public void processRequest() {
  44.         // null value for submit - user hit enter instead of clicking on 
  45.         // "add" or "remove"
  46.         if (submit == null || submit.equals("add"))
  47.             addItem(item);
  48.         else if (submit.equals("remove")) 
  49.             removeItem(item);
  50.         
  51.         // reset at the end of the request
  52.         reset();
  53.     }
  54.     // reset
  55.     private void reset() {
  56.         submit = null;
  57.         item = null;
  58.     }
  59. }