KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > domain > Order


1 /*
2  * Created on Feb 22, 2003
3  */

4 package xpetstore.domain;
5
6 import java.io.Serializable JavaDoc;
7
8 import java.util.Date JavaDoc;
9 import java.util.HashSet JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.Set JavaDoc;
12
13
14 /**
15  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
16  *
17  * @hibernate.class
18  * table="T_ORDER"
19  */

20 public class Order
21     implements Serializable JavaDoc
22 {
23     //~ Static fields/initializers ---------------------------------------------
24

25     public static final String JavaDoc PENDING = "pending";
26     public static final String JavaDoc DELIVERED = "delivered";
27     public static final String JavaDoc CANCELLED = "cancelled";
28
29     //~ Instance fields --------------------------------------------------------
30

31     private Address _address;
32     private CreditCard _creditCard;
33     private Customer _customer;
34     private Date JavaDoc _orderDate;
35     private long _orderId;
36     private Set JavaDoc _orderItems = new HashSet JavaDoc( );
37     private String JavaDoc _status = PENDING;
38
39     //~ Constructors -----------------------------------------------------------
40

41     public Order( )
42     {
43         _customer = new Customer( );
44         _address = new Address( );
45         _creditCard = new CreditCard( );
46     }
47
48     public Order( Customer customer )
49     {
50         _customer = customer;
51         _address = new Address( customer.getAddress( ) );
52         _creditCard = new CreditCard( customer.getCreditCard( ) );
53     }
54
55     //~ Methods ----------------------------------------------------------------
56

57     public void add( Item item,
58                      int quantity )
59     {
60         _orderItems.add( new OrderItem( item, quantity ) );
61     }
62
63     public double getTotal( )
64     {
65         double total = 0;
66         Iterator JavaDoc it = _orderItems.iterator( );
67
68         while ( it.hasNext( ) )
69         {
70             total += ( ( OrderItem ) it.next( ) ).getSubTotal( );
71         }
72
73         return total;
74     }
75
76     /**
77      * @return Address
78      *
79      * @hibernate.component
80      */

81     public Address getAddress( )
82     {
83         return _address;
84     }
85
86     /**
87      * @return CreditCard
88      *
89      * @hibernate.component
90      */

91     public CreditCard getCreditCard( )
92     {
93         return _creditCard;
94     }
95
96     /**
97      * @return Customer
98      *
99      * @hibernate.many-to-one
100      * column="customer_fk"
101      * cascade="none"
102      */

103     public Customer getCustomer( )
104     {
105         return _customer;
106     }
107
108     /**
109      * @return Date
110      *
111      * @hibernate.property
112      */

113     public Date JavaDoc getOrderDate( )
114     {
115         return _orderDate;
116     }
117
118     /**
119      * @return long
120      *
121      * @hibernate.id
122      * generator-class="vm.long"
123      */

124     public long getOrderId( )
125     {
126         return _orderId;
127     }
128
129     /**
130      * @return Set
131      *
132      * @hibernate.set
133      * role="orderItems"
134      * lazy="true"
135      * cascade="all"
136      * @hibernate.collection-key
137      * column="order_fk"
138      * @hibernate.collection-one-to-many
139      * class="xpetstore.domain.OrderItem"
140      */

141     public Set JavaDoc getOrderItems( )
142     {
143         return _orderItems;
144     }
145
146     /**
147      * @return String
148      *
149      * @hibernate.property
150      * length="10"
151      */

152     public String JavaDoc getStatus( )
153     {
154         return _status;
155     }
156
157     /**
158      * Sets the address.
159      * @param address The address to set
160      */

161     public void setAddress( Address address )
162     {
163         _address = address;
164     }
165
166     /**
167      * Sets the creditCard.
168      * @param creditCard The creditCard to set
169      */

170     public void setCreditCard( CreditCard creditCard )
171     {
172         _creditCard = creditCard;
173     }
174
175     /**
176      * Sets the customer.
177      * @param customer The customer to set
178      */

179     public void setCustomer( Customer customer )
180     {
181         _customer = customer;
182     }
183
184     /**
185      * Sets the orderDate.
186      * @param orderDate The orderDate to set
187      */

188     public void setOrderDate( Date JavaDoc orderDate )
189     {
190         _orderDate = orderDate;
191     }
192
193     /**
194      * Sets the orderId.
195      * @param orderId The orderId to set
196      */

197     public void setOrderId( long orderId )
198     {
199         _orderId = orderId;
200     }
201
202     /**
203      * Sets the orderItems.
204      * @param orderItems The orderItems to set
205      */

206     public void setOrderItems( Set JavaDoc orderItems )
207     {
208         _orderItems = orderItems;
209     }
210
211     /**
212      * Sets the status.
213      * @param status The status to set
214      */

215     public void setStatus( String JavaDoc status )
216     {
217         _status = status;
218     }
219 }
220
Popular Tags