View Javadoc

1   /*
2    * Copyright (c) 2001 - 2005 ivata limited.
3    * All rights reserved.
4    * -----------------------------------------------------------------------------
5    * ivata masks may be redistributed under the GNU General Public
6    * License as published by the Free Software Foundation;
7    * version 2 of the License.
8    *
9    * These programs are free software; you can redistribute them and/or
10   * modify them under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; version 2 of the License.
12   *
13   * These programs are distributed in the hope that they will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16   *
17   * See the GNU General Public License in the file LICENSE.txt for more
18   * details.
19   *
20   * If you would like a copy of the GNU General Public License write to
21   *
22   * Free Software Foundation, Inc.
23   * 59 Temple Place - Suite 330
24   * Boston, MA 02111-1307, USA.
25   *
26   *
27   * To arrange commercial support and licensing, contact ivata at
28   *                  http://www.ivata.com/contact.jsp
29   * -----------------------------------------------------------------------------
30   * $Log: ProductDO.java,v $
31   * Revision 1.6  2005/04/09 18:04:13  colinmacleod
32   * Changed copyright text to GPL v2 explicitly.
33   *
34   * Revision 1.5  2005/01/19 12:17:02  colinmacleod
35   * Added logging to catch form clear bug.
36   *
37   * Revision 1.4  2005/01/07 09:13:04  colinmacleod
38   * Added newline to end of file.
39   *
40   * Revision 1.3  2005/01/07 08:08:18  colinmacleod
41   * Moved up a version number.
42   * Changed copyright notices to 2005.
43   * Updated the documentation:
44   *   - started working on multiproject:site docu.
45   *   - changed the logo.
46   * Added checkstyle and fixed LOADS of style issues.
47   * Added separate third-party subproject.
48   * Added struts (in web), util and webgui (in webtheme) from ivata op.
49   *
50   * Revision 1.2  2004/11/11 13:17:13  colinmacleod
51   * Changed to extend DemoValueObject.
52   *
53   * Revision 1.1.1.1  2004/05/16 20:40:07  colinmacleod
54   * Ready for 0.1 release
55   * -----------------------------------------------------------------------------
56   */
57  package com.ivata.mask.web.demo.product;
58  import java.math.BigDecimal;
59  
60  import org.apache.log4j.Logger;
61  
62  import com.ivata.mask.web.demo.valueobject.DemoValueObject;
63  /***
64   * <p>
65   * Represents a single product which can be ordered.
66   * </p>
67   *
68   * @author Colin MacLeod
69   * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
70   * @since ivata masks 0.1 (2004-05-09)
71   * @version $Revision: 1.6 $
72   */
73  public final class ProductDO extends DemoValueObject {
74      /***
75       * Refer to {@link Logger}.
76       */
77      private static Logger log = Logger.getLogger(ProductDO.class);
78  
79      /***
80       * <p>
81       * Full text description of the product.
82       * </p>
83       */
84      private String description;
85      /***
86       * <p>
87       * Name of the product. Clear text name, should be unique, though this is
88       * not enforced.
89       * </p>
90       */
91      private String name;
92      /***
93       * <p>
94       * Cost of each item of this product.
95       * </p>
96       */
97      private BigDecimal price;
98      /***
99       * <p>
100      * Construct a new product instance with no id.
101      * </p>
102      */
103     public ProductDO() {
104         super();
105     }
106     /***
107      * <p>
108      * Construct a new product instance with the given unique identifier.
109      * </p>
110      *
111      * @param id
112      *            unique identifier of this product.
113      */
114     public ProductDO(final int id) {
115         super(id);
116     }
117     /***
118      * The product's description is a long text designed to make you desperate
119      * to own one immediately.
120      *
121      * @return long text designed to make you drool.
122      */
123     public String getDescription() {
124         return description;
125     }
126 
127     /***
128      * For products, the value displayed is always the product's name.
129      *
130      * @return just returns the product's name.
131      * @see com.ivata.mask.valueobject.ValueObject#getStringValue()
132      */
133     public String getDisplayValue() {
134         return name;
135     }
136     /***
137      * The name of a product is unique among products - that short text which
138      * uniquely identifies it.
139      *
140      * @return unique name of this product.
141      */
142     public String getName() {
143         return name;
144     }
145     /***
146      * What price quality? This is the cost of a single unit of the product.
147      *
148      * @return cost of a single unit of the product.
149      */
150     public BigDecimal getPrice() {
151         return price;
152     }
153     /***
154      * The product's description is a long text designed to make you desperate
155      * to own one immediately.
156      *
157      * @param descriptionParam long text designed to make you drool.
158      */
159     public void setDescription(final String descriptionParam) {
160         if (log.isDebugEnabled()) {
161             log.debug("Set description was '"
162                     + description
163                     + "', now '"
164                     + descriptionParam
165                     + "'");
166         }
167         description = descriptionParam;
168     }
169     /***
170      * The name of a product is unique among products - that short text which
171      * uniquely identifies it.
172      *
173      * @param nameParam unique name of this product.
174      */
175     public void setName(final String nameParam) {
176         if (log.isDebugEnabled()) {
177             log.debug("Set name was '"
178                     + name
179                     + "', now '"
180                     + nameParam
181                     + "'");
182         }
183         name = nameParam;
184     }
185     /***
186      * Set the cost of one unit of this product.
187      *
188      * @param priceParam cost of a single unit of this product.
189      */
190     public void setPrice(final BigDecimal priceParam) {
191         if (log.isDebugEnabled()) {
192             log.debug("Set price was '"
193                     + price
194                     + "', now '"
195                     + priceParam
196                     + "'");
197         }
198         if ((price != null)
199                 && (priceParam == null)) {
200             throw new NullPointerException();
201         }
202         price = priceParam;
203     }
204 }
205