KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > opc > purchaseorder > ejb > PurchaseOrderBean


1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any
21 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
22 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
24 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
25 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
27 * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
28 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
29 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
30 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
31 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that Software is not designed, licensed or intended
34 * for use in the design, construction, operation or maintenance of
35 * any nuclear facility.
36 */

37 package com.sun.j2ee.blueprints.opc.purchaseorder.ejb;
38
39 import javax.ejb.*;
40 import java.util.*;
41
42 import com.sun.j2ee.blueprints.opc.purchaseorder.*;
43 import com.sun.j2ee.blueprints.servicelocator.*;
44 import com.sun.j2ee.blueprints.servicelocator.ejb.*;
45
46 /**
47  * Implementation class for the PurchaseOrderBean .
48  * PurchaseOrderBean is a CMP Entity Bean representing
49  * a purchase order . It has a 1:1 relationship
50  * with ContactInfoBean , CreditCardBean, LodgingBean,
51  * TransportationBean and a 1:many relationship with
52  * ActivityBean
53  **/

54
55 public abstract class PurchaseOrderBean implements EntityBean {
56
57   private EntityContext entityContext = null;
58
59   public String JavaDoc ejbCreate(PurchaseOrder po) throws CreateException {
60
61     setPoId(po.getPoId());
62     setUserId(po.getUserId());
63     setEmailId(po.getEmailId());
64     setLocale(po.getLocale());
65     setOrderDate(po.getOrderDate().getTimeInMillis());
66     setTotalPrice(po.getTotalPrice());
67     setHeadCount(po.getHeadCount());
68     setStartDate(po.getStartDate().getTimeInMillis());
69     setEndDate(po.getEndDate().getTimeInMillis());
70     setDepartureCity(po.getDepartureCity());
71
72     return null;
73   }
74
75   public void ejbPostCreate(PurchaseOrder po) throws CreateException {
76
77       try {
78       ServiceLocator sl = new ServiceLocator();
79      
80       //set shipping and billing info
81
ContactInfoLocalHome cilh = (ContactInfoLocalHome) sl.getLocalHome(JNDINames.CINFO_EJB);
82       ContactInfoLocal cil = (ContactInfoLocal) cilh.create(po.getShippingInfo());
83       setShippingInfo(cil);
84       cil = (ContactInfoLocal) cilh.create(po.getBillingInfo());
85       setBillingInfo(cil);
86   
87       //set credit card
88
CreditCardLocalHome cclh = (CreditCardLocalHome) sl.getLocalHome(
89           JNDINames.CCARD_EJB);
90       CreditCardLocal ccl = (CreditCardLocal) cclh.create(po.
91           getCreditCard());
92       setCreditCard(ccl);
93
94       //set lodging
95
if(po.getLodging() != null){
96       LodgingLocalHome llh = (LodgingLocalHome) sl.getLocalHome(
97           JNDINames.LDG_EJB);
98       LodgingLocal ll = (LodgingLocal) llh.create(po.getLodging());
99       setLodging(ll);
100       }
101
102       //set transportation
103
if(po.getDepartureFlightInfo() != null){
104       TransportationLocalHome tlh = (TransportationLocalHome) sl.getLocalHome(
105           JNDINames.TRPN_EJB);
106       TransportationLocal tl = (TransportationLocal) tlh.create(po. getDepartureFlightInfo());
107       setDepartureFlightInfo(tl);
108   }
109   
110   if(po.getReturnFlightInfo() != null){
111   TransportationLocalHome tlh = (TransportationLocalHome) sl.getLocalHome(
112           JNDINames.TRPN_EJB);
113       TransportationLocal tl =(TransportationLocal) tlh.create(po.getReturnFlightInfo());
114       setReturnFlightInfo(tl);
115   }
116
117       //set activities
118
if(po.getActivities() != null){
119       ActivityLocalHome alh = (ActivityLocalHome) sl.getLocalHome(JNDINames.ACTY_EJB);
120       Activity[] activities = po.getActivities();
121       for(int i=0; i < activities.length; i++) {
122         ActivityLocal al = (ActivityLocal) alh.create(activities[i]);
123         addActivity(al);
124       }
125       }
126
127     }
128     catch (ServiceLocatorException se) {
129       throw new CreateException(" Exception saving PO:" +
130                                 se.getMessage());
131     }
132
133   }
134
135   //getters and setters for CMP fields
136
public abstract void setPoId(String JavaDoc poId);
137
138   public abstract void setUserId(String JavaDoc userId);
139
140   public abstract void setEmailId(String JavaDoc emailId);
141
142   public abstract void setLocale(String JavaDoc locale);
143
144   public abstract void setOrderDate(long orderDate);
145
146   public abstract void setTotalPrice(float totalPrice);
147
148   public abstract void setHeadCount(int headCount);
149
150   public abstract void setStartDate(long startDate);
151
152   public abstract void setEndDate(long endDate);
153
154   public abstract void setDepartureCity(String JavaDoc departureCity);
155
156   public abstract String JavaDoc getPoId();
157
158   public abstract String JavaDoc getUserId();
159
160   public abstract String JavaDoc getEmailId();
161
162   public abstract String JavaDoc getLocale();
163
164   public abstract long getOrderDate();
165
166   public abstract float getTotalPrice();
167
168   public abstract int getHeadCount();
169
170   public abstract long getStartDate();
171
172   public abstract long getEndDate();
173
174   public abstract String JavaDoc getDepartureCity();
175
176   //getters and setters for CMR fields
177
public abstract void setShippingInfo(ContactInfoLocal shippingInfo);
178
179   public abstract void setCreditCard(CreditCardLocal creditCard);
180
181   public abstract void setLodging(LodgingLocal lodging);
182
183   public abstract void setBillingInfo(ContactInfoLocal billingInfo);
184
185   public abstract void setDepartureFlightInfo(TransportationLocal
186                                               departureFlightInfo);
187
188   public abstract void setReturnFlightInfo(TransportationLocal returnFlightInfo);
189
190   public abstract void setActivities(Collection activities);
191
192   public abstract ContactInfoLocal getShippingInfo();
193
194   public abstract CreditCardLocal getCreditCard();
195
196   public abstract LodgingLocal getLodging();
197
198   public abstract ContactInfoLocal getBillingInfo();
199
200   public abstract TransportationLocal getDepartureFlightInfo();
201
202   public abstract TransportationLocal getReturnFlightInfo();
203
204   public abstract Collection getActivities();
205
206   public void addActivity(ActivityLocal activity) {
207     getActivities().add(activity);
208   }
209
210   public PurchaseOrder getPO() {
211     PurchaseOrder purchaseOrder = new PurchaseOrder();
212     purchaseOrder.setPoId(getPoId());
213     purchaseOrder.setUserId(getUserId());
214     purchaseOrder.setEmailId(getEmailId());
215     Calendar cal = Calendar.getInstance();
216     cal.setTimeInMillis(getOrderDate());
217     purchaseOrder.setOrderDate(cal);
218     purchaseOrder.setLocale(getLocale());
219     purchaseOrder.setTotalPrice(getTotalPrice());
220     purchaseOrder.setBillingInfo(getBillingInfo().getDetails());
221     purchaseOrder.setShippingInfo(getShippingInfo().getDetails());
222     purchaseOrder.setCreditCard(getCreditCard().getDetails());
223     Collection activities = getActivities();
224     if(activities != null){
225     Activity[] acts = new Activity[activities.size()];
226     int i = 0;
227     for (Iterator iter = activities.iterator(); iter.hasNext(); i++) {
228       ActivityLocal activity = (ActivityLocal) iter.next();
229       acts[i] = activity.getDetails();
230     }
231     purchaseOrder.setActivities(acts);
232     }
233     purchaseOrder.setHeadCount(getHeadCount());
234     cal.setTimeInMillis(getStartDate());
235     purchaseOrder.setStartDate(cal);
236     cal.setTimeInMillis(getEndDate());
237     purchaseOrder.setEndDate(cal);
238     purchaseOrder.setDepartureCity(getDepartureCity());
239     if(getDepartureFlightInfo() != null)
240     purchaseOrder.setDepartureFlightInfo(getDepartureFlightInfo().getDetails());
241     if(getReturnFlightInfo() != null)
242     purchaseOrder.setReturnFlightInfo(getReturnFlightInfo().getDetails());
243     if(getLodging() != null)
244     purchaseOrder.setLodging(getLodging().getDetails());
245
246     return purchaseOrder;
247   }
248
249   public void ejbRemove() throws RemoveException {
250   }
251
252   public void ejbLoad() {
253   }
254
255   public void ejbStore() {
256   }
257
258   public void ejbActivate() {
259   }
260
261   public void ejbPassivate() {
262   }
263
264   public void unsetEntityContext() {
265     this.entityContext = null;
266   }
267
268   public void setEntityContext(EntityContext entityContext) {
269     this.entityContext = entityContext;
270   }
271
272 }
273
Popular Tags