KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > Order


1 /*
2  * Created on Oct 7, 2004
3  */

4 package com.openedit.store;
5
6 import java.util.Date JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9
10 import org.openedit.money.Money;
11
12 import com.openedit.store.customer.Customer;
13 import com.openedit.store.orders.SubmittedOrder;
14
15 /**
16  * An order for a number of products contained in a shopping cart at a certain
17  * time.
18  *
19  * @author Eric Galluzzo, egalluzzo@einnovation.com
20  */

21 public class Order implements Comparable JavaDoc
22 {
23     public final static String JavaDoc ACCEPTED = "accepted";
24     public final static String JavaDoc AUTHORIZED = "authorized";
25     public final static String JavaDoc CAPTURED = "captured";
26     public final static String JavaDoc COMPLETED = "completed";
27     public final static String JavaDoc REJECTED = "rejected";
28     
29     protected String JavaDoc fieldId;
30     protected Customer fieldCustomer;
31     protected List JavaDoc fieldItems;
32     protected ShippingMethod fieldShippingMethod;
33     protected Money fieldTotalShipping;
34     protected Money fieldTax;
35     protected Money fieldSubTotal;
36     protected Money fieldTotalPrice;
37
38     protected PaymentMethod fieldPaymentMethod;
39     protected Date JavaDoc fieldDate;
40     protected OrderState fieldOrderState;
41     
42     public Money getTotalShipping()
43     {
44         return fieldTotalShipping;
45     }
46     public void setTotalShipping(Money inTotalShipping)
47     {
48         fieldTotalShipping = inTotalShipping;
49     }
50     public ShippingMethod getShippingMethod()
51     {
52         return fieldShippingMethod;
53     }
54     public void setShippingMethod(ShippingMethod inShippingMethod)
55     {
56         fieldShippingMethod = inShippingMethod;
57     }
58     public Money getSubTotal()
59     {
60         return fieldSubTotal;
61     }
62     public void setSubTotal(Money inSubtotal)
63     {
64         fieldSubTotal = inSubtotal;
65     }
66     public Money getTax()
67     {
68         return fieldTax;
69     }
70     public void setTax(Money inTax)
71     {
72         fieldTax = inTax;
73     }
74     
75     /**
76      * Creates a new order with no ID and today's date.
77      *
78      * <p>FIXME: Should we auto-generate an ID?
79      */

80     public Order()
81     {
82         fieldDate = new Date JavaDoc();
83     }
84
85     /**
86      * Creates a new order with the given ID and date.
87      *
88      * @param inId The order ID
89      * @param inDate The order date
90      */

91     public Order( String JavaDoc inId, Date JavaDoc inDate )
92     {
93         fieldId = inId;
94         fieldDate = inDate;
95     }
96     /**
97      * Returns the date and time at which the order was made.
98      *
99      * @return The order date
100      */

101     public Date JavaDoc getDate()
102     {
103         return fieldDate;
104     }
105
106     /**
107      * Sets the date and time at which the order was made.
108      *
109      * @param inDate The order date
110      */

111     public void setDate( Date JavaDoc inDate )
112     {
113         fieldDate = inDate;
114     }
115
116     /**
117      * Returns the order ID.
118      *
119      * @return The order ID
120      */

121     public String JavaDoc getId()
122     {
123         return fieldId;
124     }
125     public String JavaDoc getOrderNumber()
126     {
127         return getId();
128     }
129
130     /**
131      * Sets the order ID. This should not normally be called. Instead, use a
132      * constructor that accepts an ID.
133      *
134      * @param inId The order ID
135      */

136     public void setId( String JavaDoc inId )
137     {
138         fieldId = inId;
139     }
140
141     /**
142      * Returns the method that the customer used to pay for this order -- e.g. a
143      * Visa credit card with number 4111-1111-1111-1111.
144      *
145      * @return The payment method
146      */

147     public PaymentMethod getPaymentMethod()
148     {
149         if ( fieldPaymentMethod == null )
150         {
151             fieldPaymentMethod = new CreditPaymentMethod();
152         }
153         return fieldPaymentMethod;
154     }
155
156     /**
157      * Sets the method used to pay for this order.
158      *
159      * @param inPaymentMethod The payment method
160      */

161     public void setPaymentMethod( PaymentMethod inPaymentMethod )
162     {
163         fieldPaymentMethod = inPaymentMethod;
164     }
165
166     public String JavaDoc toString()
167     {
168         return "Order " + getId() + " on " + getDate() + ":\n" + getPaymentMethod();
169     }
170     public OrderState getOrderState() //TODO: Rename to getOrderStatus
171
{
172         return fieldOrderState;
173     }
174     public void setOrderState(OrderState inOrderState)
175     {
176         fieldOrderState = inOrderState;
177     }
178     public Customer getCustomer()
179     {
180         return fieldCustomer;
181     }
182     public void setCustomer(Customer inCustomer)
183     {
184         fieldCustomer = inCustomer;
185     }
186     public List JavaDoc getItems()
187     {
188         return fieldItems;
189     }
190     public void setItems(List JavaDoc inItems)
191     {
192         fieldItems = inItems;
193     }
194     public Money getTotalPrice()
195     {
196         return fieldTotalPrice;
197     }
198     public void setTotalPrice(Money inTotalPrice)
199     {
200         fieldTotalPrice = inTotalPrice;
201     }
202     
203     public int compareTo(Object JavaDoc inOrder)
204     {
205         SubmittedOrder order = (SubmittedOrder)inOrder;
206         return order.getOrderNumber().compareTo(getOrderNumber());
207     }
208     public int getNumItems()
209     {
210         int numItems = 0;
211         for (Iterator JavaDoc it = getItems().iterator(); it.hasNext();)
212         {
213             CartItem item = (CartItem)it.next();
214             numItems += item.getQuantity();
215         }
216         return numItems;
217     }
218
219
220 }
Popular Tags