1 package edu.rice.rubis.beans; 2 3 import java.rmi.*; 4 import javax.ejb.*; 5 import javax.naming.Context ; 6 import javax.naming.InitialContext ; 7 import javax.rmi.PortableRemoteObject ; 8 import java.util.GregorianCalendar ; 9 10 39 40 public class OldItemBean implements EntityBean 41 { 42 private EntityContext entityContext; 43 private transient boolean isDirty; 45 46 47 public Integer id; 48 public String name; 49 public String description; 50 public float initialPrice; 51 public int quantity; 52 public float reservePrice; 53 public float buyNow; 54 public int nbOfBids; 55 public float maxBid; 56 public String startDate; 57 public String endDate; 58 public Integer sellerId; 59 public Integer categoryId; 60 61 68 public Integer getId() throws RemoteException 69 { 70 return id; 71 } 72 73 80 public String getName() throws RemoteException 81 { 82 return name; 83 } 84 85 92 public String getDescription() throws RemoteException 93 { 94 return description; 95 } 96 97 104 public float getInitialPrice() throws RemoteException 105 { 106 return initialPrice; 107 } 108 109 116 public int getQuantity() throws RemoteException 117 { 118 return quantity; 119 } 120 121 128 public float getReservePrice() throws RemoteException 129 { 130 return reservePrice; 131 } 132 133 140 public float getBuyNow() throws RemoteException 141 { 142 return buyNow; 143 } 144 145 152 public float getMaxBid() throws RemoteException 153 { 154 return maxBid; 155 } 156 157 164 public int getNbOfBids() throws RemoteException 165 { 166 return nbOfBids; 167 } 168 169 176 public String getStartDate() throws RemoteException 177 { 178 return startDate; 179 } 180 181 188 public String getEndDate() throws RemoteException 189 { 190 return endDate; 191 } 192 193 200 public Integer getSellerId() throws RemoteException 201 { 202 return sellerId; 203 } 204 205 206 213 public Integer getCategoryId() throws RemoteException 214 { 215 return categoryId; 216 } 217 218 219 227 public String getSellerNickname() throws RemoteException 228 { 229 Context initialContext = null; 230 try 231 { 232 initialContext = new InitialContext (); 233 } 234 catch (Exception e) 235 { 236 System.err.print("Cannot get initial context for JNDI: " + e); 237 return null; 238 } 239 240 UserHome uHome; 242 try 243 { 244 uHome = (UserHome)PortableRemoteObject.narrow(initialContext.lookup("UserHome"), 245 UserHome.class); 246 } 247 catch (Exception e) 248 { 249 System.err.print("Cannot lookup User: " +e); 250 return null; 251 } 252 try 253 { 254 User u = uHome.findByPrimaryKey(new UserPK(sellerId)); 255 return u.getNickName(); 256 } 257 catch (Exception e) 258 { 259 System.err.print("This user does not exist (got exception: " +e+")<br>"); 260 return null; 261 } 262 } 263 264 265 272 public String getCategoryName() throws RemoteException 273 { 274 Context initialContext = null; 275 try 276 { 277 initialContext = new InitialContext (); 278 } 279 catch (Exception e) 280 { 281 System.err.print("Cannot get initial context for JNDI: " + e); 282 return null; 283 } 284 285 CategoryHome cHome; 287 try 288 { 289 cHome = (CategoryHome)PortableRemoteObject.narrow(initialContext.lookup("CategoryHome"), 290 CategoryHome.class); 291 } 292 catch (Exception e) 293 { 294 System.err.print("Cannot lookup Category: " +e); 295 return null; 296 } 297 try 298 { 299 Category c = cHome.findByPrimaryKey(new CategoryPK(id)); 300 return c.getName(); 301 } 302 catch (Exception e) 303 { 304 System.err.print("This category does not exist (got exception: " +e+")<br>"); 305 return null; 306 } 307 } 308 309 310 317 public void setId(Integer newId) throws RemoteException 318 { 319 id = newId; 320 isDirty = true; } 322 323 330 public void setName(String newName) throws RemoteException 331 { 332 name = newName; 333 isDirty = true; } 335 336 343 public void setDescription(String newDescription) throws RemoteException 344 { 345 description = newDescription; 346 isDirty = true; } 348 349 356 public void setInitialPrice(float newInitialPrice) throws RemoteException 357 { 358 initialPrice = newInitialPrice; 359 isDirty = true; } 361 362 369 public void setQuantity(int qty) throws RemoteException 370 { 371 quantity = qty; 372 isDirty = true; } 374 375 382 public void setReservePrice(float newReservePrice) throws RemoteException 383 { 384 reservePrice = newReservePrice; 385 isDirty = true; } 387 388 395 public void setBuyNow(float newBuyNow) throws RemoteException 396 { 397 buyNow = newBuyNow; 398 isDirty = true; } 400 401 409 public void setMaxBid(float newMaxBid) throws RemoteException 410 { 411 if (newMaxBid > maxBid) 412 maxBid = newMaxBid; 413 isDirty = true; } 415 416 423 public void setNbOfBids(int newNbOfBids) throws RemoteException 424 { 425 nbOfBids = newNbOfBids; 426 isDirty = true; } 428 429 435 public void addOneBid() throws RemoteException 436 { 437 nbOfBids++; 438 isDirty = true; } 440 441 448 public void setStartDate(String newDate) throws RemoteException 449 { 450 startDate = newDate; 451 isDirty = true; } 453 454 461 public void setEndDate(String newDate) throws RemoteException 462 { 463 endDate = newDate; 464 isDirty = true; } 466 467 475 public void setSellerId(Integer id) throws RemoteException 476 { 477 sellerId = id; 478 isDirty = true; } 480 481 489 public void setCategoryId(Integer id) throws RemoteException 490 { 491 categoryId = id; 492 isDirty = true; } 494 495 496 519 public OldItemPK ejbCreate(Integer itemId, String itemName, String itemDescription, float itemInitialPrice, 520 int itemQuantity, float itemReservePrice, float itemBuyNow, int duration, 521 Integer itemSellerId, Integer itemCategoryId) throws CreateException, RemoteException, RemoveException 522 { 523 GregorianCalendar start = new GregorianCalendar (); 524 525 id = itemId; 526 name = itemName; 527 description = itemDescription; 528 initialPrice = itemInitialPrice; 529 quantity = itemQuantity; 530 reservePrice = itemReservePrice; 531 buyNow = itemBuyNow; 532 sellerId = itemSellerId; 533 categoryId = itemCategoryId; 534 nbOfBids = 0; 535 maxBid = 0; 536 startDate = TimeManagement.dateToString(start); 537 endDate = TimeManagement.dateToString(TimeManagement.addDays(start, duration)); 538 return null; 539 } 540 541 542 public void ejbPostCreate(Integer itemId, String itemName, String itemDescription, float itemInitialPrice, 543 int itemQuantity, float itemReservePrice, float itemBuyNow, int duration, 544 Integer itemSellerId, Integer itemCategoryId) {} 545 546 548 public void ejbLoad() throws RemoteException 549 { 550 isDirty = false; 551 } 552 553 555 public void ejbStore() throws RemoteException 556 { 557 isDirty = false; 558 } 559 560 561 public void ejbActivate() throws RemoteException {} 562 563 public void ejbPassivate() throws RemoteException {} 564 565 public void ejbRemove() throws RemoteException, RemoveException {} 566 567 584 public void setEntityContext(EntityContext context) throws RemoteException 585 { 586 entityContext = context; 587 } 588 589 606 public void unsetEntityContext() throws RemoteException 607 { 608 entityContext = null; 609 } 610 611 612 619 public boolean isModified() 620 { 621 return isDirty; 622 } 623 } 624 | Popular Tags |