View Javadoc

1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.ibatis.jpetstore.domain;
17  
18  import java.io.Serializable;
19  import java.math.BigDecimal;
20  
21  
22  public class LineItem implements Serializable {
23  
24    /* Private Fields */
25  
26    private int orderId;
27    private int lineNumber;
28    private int quantity;
29    private String itemId;
30    private BigDecimal unitPrice;
31    private Item item;
32    private BigDecimal total;
33  
34    /* Constructors */
35  
36    public LineItem() {
37    }
38  
39    public LineItem(int lineNumber, CartItem cartItem) {
40      this.lineNumber = lineNumber;
41      this.quantity = cartItem.getQuantity();
42      this.itemId = cartItem.getItem().getItemId();
43      this.unitPrice = cartItem.getItem().getListPrice();
44      this.item = cartItem.getItem();
45    }
46  
47    /* JavaBeans Properties */
48  
49    public int getOrderId() {
50      return orderId;
51    }
52  
53    public void setOrderId(int orderId) {
54      this.orderId = orderId;
55    }
56  
57    public int getLineNumber() {
58      return lineNumber;
59    }
60  
61    public void setLineNumber(int lineNumber) {
62      this.lineNumber = lineNumber;
63    }
64  
65    public String getItemId() {
66      return itemId;
67    }
68  
69    public void setItemId(String itemId) {
70      this.itemId = itemId;
71    }
72  
73    public BigDecimal getUnitPrice() {
74      return unitPrice;
75    }
76  
77    public void setUnitPrice(BigDecimal unitprice) {
78      this.unitPrice = unitprice;
79    }
80  
81    public BigDecimal getTotal() {
82      return total;
83    }
84  
85    public Item getItem() {
86      return item;
87    }
88  
89    public void setItem(Item item) {
90      this.item = item;
91      calculateTotal();
92    }
93  
94    public int getQuantity() {
95      return quantity;
96    }
97  
98    public void setQuantity(int quantity) {
99      this.quantity = quantity;
100     calculateTotal();
101   }
102 
103   /* Private methods */
104 
105   private void calculateTotal() {
106     if (item != null && item.getListPrice() != null) {
107       total = item.getListPrice().multiply(new BigDecimal(quantity));
108     } else {
109       total = null;
110     }
111   }
112 
113 
114 }