KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > trade > Order


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

5 package com.nightlabs.ipanema.trade;
6
7 import java.io.Serializable JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Map JavaDoc;
10
11 import com.nightlabs.ipanema.accounting.Currency;
12
13
14 /**
15  * @author Niklas Schiffler <nick@nightlabs.de>
16  * @author marco schulze - marco at nightlabs dot de
17  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
18  *
19  * @jdo.persistence-capable
20  * identity-type = "application"
21  * objectid-class = "com.nightlabs.ipanema.trade.id.OrderID"
22  * detachable = "true"
23  *
24  * @jdo.inheritance strategy = "new-table"
25  */

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

33     private String JavaDoc organisationID;
34
35     /**
36      * @jdo.field primary-key="true"
37      */

38     private long orderID;
39     
40     /**
41      * @jdo.field persistence-modifier="persistent"
42      */

43     private Currency currency;
44
45     /**
46      * @jdo.field persistence-modifier="persistent"
47      */

48     private OrganisationLegalEntity vendor;
49
50     /**
51      * @jdo.field persistence-modifier="persistent"
52      */

53     private LegalEntity customer;
54
55     /**
56      * After the first payment or delivery, the customer is not changeable anymore.
57      */

58     protected boolean customerChangeable = true;
59
60     /**
61      * key: String productPK (organisationID + / + productID)<br/>
62      * value: OrderItem orderItem
63      * <br/><br/>
64      *
65      * @jdo.field
66      * persistence-modifier="persistent"
67      * collection-type="map"
68      * key-type="java.lang.String"
69      * value-type="OrderItem"
70      *
71      * @jdo.join
72      */

73     private Map JavaDoc items = new HashMap JavaDoc();
74
75     /**
76      * key: String offerPK<br/>
77      * value: Offer offer
78      * <br/><br/>
79      *
80      * @jdo.field
81      * persistence-modifier="persistent"
82      * collection-type="map"
83      * key-type="java.lang.String"
84      * value-type="Offer"
85      * mapped-by="order"
86      *
87      * @jdo.map-vendor-extension vendor-name="jpox" key="key-field" value="primaryKey"
88      */

89     private Map JavaDoc offers = new HashMap JavaDoc();
90
91     public Order() {}
92
93     public Order(OrganisationLegalEntity vendor, LegalEntity customer, long orderID, Currency currency)
94     {
95         if (vendor == null)
96             throw new NullPointerException JavaDoc("vendor");
97         
98         if (customer == null)
99             throw new NullPointerException JavaDoc("customer");
100
101         if (currency == null)
102             throw new NullPointerException JavaDoc("currency");
103
104         this.vendor = vendor;
105         this.customer = customer;
106         this.organisationID = vendor.getOrganisationID();
107         this.orderID = orderID;
108         this.currency = currency;
109     }
110
111     /**
112      * @return Returns the organisationID.
113      */

114     public String JavaDoc getOrganisationID()
115     {
116         return organisationID;
117     }
118     /**
119      * @return Returns the orderID.
120      */

121     public long getOrderID()
122     {
123         return orderID;
124     }
125
126     public static String JavaDoc getPrimaryKey(String JavaDoc organisationID, long orderID)
127     {
128         return organisationID + '/' + Long.toHexString(orderID);
129     }
130     public String JavaDoc getPrimaryKey()
131     {
132         return organisationID + '/' + Long.toHexString(orderID);
133     }
134
135     /**
136      * @return Returns the currency.
137      */

138     public Currency getCurrency()
139     {
140         return currency;
141     }
142     /**
143      * @return Returns the vendor.
144      */

145     public OrganisationLegalEntity getVendor()
146     {
147         return vendor;
148     }
149     /**
150      * @return Returns the customer.
151      */

152     public LegalEntity getCustomer()
153     {
154         return customer;
155     }
156     /**
157      * @param customer The customer to set.
158      */

159     public void setCustomer(LegalEntity customer)
160     {
161         if (!customerChangeable)
162             throw new IllegalStateException JavaDoc("Customer cannot be changed anymore!");
163
164         this.customer = customer;
165     }
166     /**
167      * @return Returns the customerChangeable.
168      */

169     public boolean isCustomerChangeable()
170     {
171         return customerChangeable;
172     }
173 }
174
Popular Tags