View Javadoc

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