KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > store > ProductStatus


1 /*
2  * Created on 30.09.2004
3  *
4  */

5 package com.nightlabs.ipanema.store;
6
7 import java.io.Serializable JavaDoc;
8 import java.util.Date JavaDoc;
9
10 import com.nightlabs.ipanema.security.User;
11
12 /**
13  * ProductStatus is an immutable object which stores a certain status of a
14  * Product at a certain time. If the status changes, a new ProductStatus is
15  * created.
16  *
17  * @author Niklas Schiffler <nick@nightlabs.de>
18  * @author Marco Schulze - marco at nightlabs dot de
19  *
20  * @jdo.persistence-capable
21  * identity-type = "application"
22  * objectid-class = "com.nightlabs.ipanema.store.id.ProductStatusID"
23  * detachable = "true"
24  *
25  * @jdo.inheritance strategy = "new-table"
26  **/

27 public class ProductStatus
28     implements Serializable JavaDoc // InstanceCallbacks
29
{
30     /**
31      * @jdo.field primary-key="true"
32      * @jdo.column length="100"
33      */

34     private String JavaDoc organisationID;
35
36     /**
37      * @jdo.field primary-key="true"
38      * @jdo.column length="100"
39      */

40     private String JavaDoc productID;
41     
42     /**
43      * @jdo.field primary-key="true"
44      */

45     private int statusID;
46
47     /**
48      * @jdo.field persistence-modifier="persistent"
49      */

50     private ProductStatusTracker productStatusTracker;
51
52     /**
53      * @jdo.field persistence-modifier="persistent"
54      */

55     private Product product;
56
57     /**
58     * @jdo.field persistence-modifier="persistent"
59     * @jdo.column length="30"
60     */

61     private String JavaDoc status;
62
63     private Date JavaDoc timestamp;
64
65     /**
66      * The status "blocked" means that the product is available but cannot be
67      * allocated, reserved or sold.
68      */

69     public static final String JavaDoc STATUS_BLOCKED = "blocked";
70
71     /**
72      * The status "available" means that the product can be allocated, reserved
73      * or sold.
74      */

75     public static final String JavaDoc STATUS_AVAILABLE = "available";
76
77     /**
78      * The status "allocated" means sth. like a short-time reservation for a few minutes.
79      * If someone intends to buy a project, it can be allocated, thus noone else can steal
80      * it from him while he is on the way to the cash desk.
81      */

82     public static final String JavaDoc STATUS_ALLOCATED = "allocated";
83
84     /**
85      * The status "reserved" is quite similar to "allocated", but for a long-time reservation
86      * where the end-customer is known.
87      */

88     public static final String JavaDoc STATUS_RESERVED = "reserved";
89
90     /**
91      * The status "sold" means that the product is sold to a known customer (anonymous is
92      * represented by a special customer).
93      */

94     public static final String JavaDoc STATUS_SOLD = "sold";
95
96     /**
97      * If an product is "hollow", it means that the product here in this store is only virtual and
98      * basically means the same as if it's not here. This flag is necessary, because we need to have
99      * the object for satisfying links in orders, offers etc. already before the product is really here
100      * and after it has been refunded.
101      */

102     private boolean hollow;
103
104     public static boolean isValidStatus(String JavaDoc status)
105     {
106         return
107                 STATUS_BLOCKED.equals(status) ||
108                 STATUS_AVAILABLE.equals(status) ||
109                 STATUS_ALLOCATED.equals(status) ||
110                 STATUS_RESERVED.equals(status) ||
111                 STATUS_SOLD.equals(status);
112     }
113     
114     public static void assertValidStatus(String JavaDoc status)
115     {
116         if (!isValidStatus(status))
117             throw new IllegalArgumentException JavaDoc("Status \""+status+"\" is not valid!");
118     }
119
120     /**
121      * Which user has done the last state change and therefore in the cases
122      * allocated, reserved, sold is the one who "owns" the Product.
123      *
124      * @jdo.field persistence-modifier="persistent"
125      */

126     private User user;
127
128     public ProductStatus() { }
129
130     public ProductStatus(ProductStatusTracker productStatusRegistry, User user, int statusID, String JavaDoc status, boolean hollow)
131     {
132         if (productStatusRegistry == null)
133             throw new NullPointerException JavaDoc("productStatusTracker must not be null!");
134         if (productStatusRegistry.getOrganisationID() == null)
135             throw new NullPointerException JavaDoc("productStatusTracker.organisationID must not be null!");
136         if (productStatusRegistry.getProductID() == null)
137             throw new NullPointerException JavaDoc("productStatusTracker.productID must not be null!");
138         
139         if (statusID < 0)
140             throw new IllegalArgumentException JavaDoc("statusID must be >= 0!");
141
142         assertValidStatus(status);
143
144         if (user == null)
145             throw new NullPointerException JavaDoc("user must not be null!");
146
147         this.organisationID = productStatusRegistry.getOrganisationID();
148         this.productID = productStatusRegistry.getProductID();
149         this.statusID = statusID;
150         this.productStatusTracker = productStatusRegistry;
151         this.product = productStatusRegistry.getProduct();
152         this.timestamp = new Date JavaDoc();
153         this.status = status;
154         this.user = user;
155         this.hollow = hollow;
156     }
157     public Product getProduct()
158     {
159         return product;
160     }
161     /**
162      * @return Returns the organisationID.
163      */

164     public String JavaDoc getOrganisationID()
165     {
166         return organisationID;
167     }
168     public String JavaDoc getProductID()
169     {
170         return productID;
171     }
172
173     /**
174      * @return Returns the productStatusTracker.
175      */

176     public ProductStatusTracker getProductStatusTracker()
177     {
178         return productStatusTracker;
179     }
180     /**
181      * @return Returns the status.
182      */

183     public String JavaDoc getStatus()
184     {
185         return status;
186     }
187     /**
188      * @return Returns the statusID.
189      */

190     public int getStatusID()
191     {
192         return statusID;
193     }
194     /**
195      * @return Returns the timestamp.
196      */

197     public Date JavaDoc getTimestamp()
198     {
199         return timestamp;
200     }
201     /**
202      * @return Returns the user.
203      */

204     public User getUser()
205     {
206         return user;
207     }
208     /**
209      * @return Returns the hollow.
210      */

211     public boolean isHollow()
212     {
213         return hollow;
214     }
215     /**
216      * @param hollow The hollow to set.
217      */

218     public void setHollow(boolean hollow)
219     {
220         this.hollow = hollow;
221     }
222 }
223
Popular Tags