KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olstore > form > CheckoutForm


1 /**
2  * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA
18  *
19  * Component of: Red Hat Application Server
20  *
21  * Initial Developers: Aizaz Ahmed
22  * Vivek Lakshmanan
23  * Andrew Overholt
24  * Matthew Wringe
25  *
26  */

27 package olstore.form;
28
29 import java.util.ArrayList;
30 import java.math.BigDecimal;
31
32 import olstore.dto.ShoppingCartItem;
33
34 public class CheckoutForm extends DemoBaseForm {
35     
36     private BigDecimal totalCost = new BigDecimal(0.00f);
37     private int numItems = 0;
38     private String submitType = null;
39     private ArrayList cartEntries = new ArrayList() ;
40     
41     
42     public BigDecimal getTotalCost () {
43         return totalCost;
44     }
45     
46     public void setTotalCost ( BigDecimal cost ) {
47         totalCost = cost;
48     }
49     
50     public int getNumItems () {
51         return numItems;
52     }
53     
54     public void setNumItems ( int num ) {
55         numItems = num;
56     }
57     
58     // If return is "update" then the form is being updated, if "submit" then
59
// the form is being submitted.
60
public String getSubmitType () {
61         return submitType;
62     }
63     
64     public void setSubmitType ( String submit ) {
65         this.submitType = submit;
66     }
67     
68     /**
69      * This autoincrements the size of the vector, so will not return null
70      * . This is necessary as the struts auto-populater expects
71      * non-null to be retured, and we don't know how many it will
72      * request.
73      *
74      */

75     public ShoppingCartItem getCartItem (int index) {
76         if ( index >= cartEntries.size() ) {
77             int size = cartEntries.size();
78             for ( int i =0; i < (index-size) + 1 ; i++ ) {
79                 cartEntries.add ( new ShoppingCartItem() );
80             }
81         }
82         return (ShoppingCartItem) cartEntries.get ( index );
83     }
84     
85     public void setCartItem ( int index, ShoppingCartItem item ) {
86         numItems++;
87         cartEntries.set ( index, item );
88     }
89     
90     public void reset(){
91         totalCost = new BigDecimal(0.00f);
92         numItems = 0;
93         submitType = null;
94         cartEntries.clear();
95     }
96     
97     /**
98      * Returns a reference to the internal Properties, use wisely
99      */

100     public ArrayList getCartEntries( ) {
101         return cartEntries;
102     }
103     
104     public void setCartEntries ( ArrayList cartEntries ) {
105         this.cartEntries = cartEntries;
106         setNumItems(cartEntries.size());
107     }
108     
109     
110 }
111
Popular Tags