1 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 54 55 public abstract class PurchaseOrderBean implements EntityBean { 56 57 private EntityContext entityContext = null; 58 59 public String 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 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 CreditCardLocalHome cclh = (CreditCardLocalHome) sl.getLocalHome( 89 JNDINames.CCARD_EJB); 90 CreditCardLocal ccl = (CreditCardLocal) cclh.create(po. 91 getCreditCard()); 92 setCreditCard(ccl); 93 94 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 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 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 public abstract void setPoId(String poId); 137 138 public abstract void setUserId(String userId); 139 140 public abstract void setEmailId(String emailId); 141 142 public abstract void setLocale(String 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 departureCity); 155 156 public abstract String getPoId(); 157 158 public abstract String getUserId(); 159 160 public abstract String getEmailId(); 161 162 public abstract String 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 getDepartureCity(); 175 176 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 |