001: /**
002: * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017: * USA
018: *
019: * Component of: Red Hat Application Server
020: *
021: * Initial Developers: Aizaz Ahmed
022: * Vivek Lakshmanan
023: * Andrew Overholt
024: * Matthew Wringe
025: *
026: */package olstore.form;
027:
028: import java.util.ArrayList;
029: import java.math.BigDecimal;
030:
031: import olstore.dto.ShoppingCartItem;
032:
033: public class CheckoutForm extends DemoBaseForm {
034:
035: private BigDecimal totalCost = new BigDecimal(0.00f);
036: private int numItems = 0;
037: private String submitType = null;
038: private ArrayList cartEntries = new ArrayList();
039:
040: public BigDecimal getTotalCost() {
041: return totalCost;
042: }
043:
044: public void setTotalCost(BigDecimal cost) {
045: totalCost = cost;
046: }
047:
048: public int getNumItems() {
049: return numItems;
050: }
051:
052: public void setNumItems(int num) {
053: numItems = num;
054: }
055:
056: // If return is "update" then the form is being updated, if "submit" then
057: // the form is being submitted.
058: public String getSubmitType() {
059: return submitType;
060: }
061:
062: public void setSubmitType(String submit) {
063: this .submitType = submit;
064: }
065:
066: /**
067: * This autoincrements the size of the vector, so will not return null
068: * . This is necessary as the struts auto-populater expects
069: * non-null to be retured, and we don't know how many it will
070: * request.
071: *
072: */
073: public ShoppingCartItem getCartItem(int index) {
074: if (index >= cartEntries.size()) {
075: int size = cartEntries.size();
076: for (int i = 0; i < (index - size) + 1; i++) {
077: cartEntries.add(new ShoppingCartItem());
078: }
079: }
080: return (ShoppingCartItem) cartEntries.get(index);
081: }
082:
083: public void setCartItem(int index, ShoppingCartItem item) {
084: numItems++;
085: cartEntries.set(index, item);
086: }
087:
088: public void reset() {
089: totalCost = new BigDecimal(0.00f);
090: numItems = 0;
091: submitType = null;
092: cartEntries.clear();
093: }
094:
095: /**
096: * Returns a reference to the internal Properties, use wisely
097: */
098: public ArrayList getCartEntries() {
099: return cartEntries;
100: }
101:
102: public void setCartEntries(ArrayList cartEntries) {
103: this.cartEntries = cartEntries;
104: setNumItems(cartEntries.size());
105: }
106:
107: }
|