1 37 38 package com.sun.j2ee.blueprints.creditcard.ejb; 39 40 import javax.ejb.EntityContext; 41 import javax.ejb.RemoveException; 42 import javax.ejb.CreateException; 43 44 public abstract class CreditCardEJB implements javax.ejb.EntityBean { 45 46 private EntityContext context = null; 47 48 public abstract String getCardNumber(); 51 public abstract void setCardNumber(String cardNumber); 52 53 public abstract String getCardType(); 54 public abstract void setCardType(String cardType); 55 56 public abstract String getExpiryDate(); 57 public abstract void setExpiryDate(String expiryDate); 58 59 60 public Object ejbCreate(String cardNumber, String cardType, 63 String expiryDate) throws CreateException { 64 setCardNumber(cardNumber); 65 setCardType(cardType); 66 setExpiryDate(expiryDate); 67 return null; 68 } 69 70 public void ejbPostCreate(String cardNumber, String cardType, 71 String expiryDate) throws CreateException { } 72 73 public Object ejbCreate(CreditCard creditCard) throws CreateException { 74 setCardNumber(creditCard.getCardNumber()); 75 setCardType(creditCard.getCardType()); 76 setExpiryDate(creditCard.getExpiryDate()); 77 return null; 78 } 79 80 public void ejbPostCreate(CreditCard creditCard) throws CreateException { } 81 82 public Object ejbCreate() throws CreateException { 83 return null; 84 } 85 86 public void ejbPostCreate() throws CreateException { } 87 88 public String getExpiryMonth() { 89 String dateString = getExpiryDate(); 90 if (dateString != null) { 91 int slashStart = dateString.indexOf("/"); 93 if (slashStart != -1) return dateString.substring(0,slashStart); 94 } 95 return "01"; 96 } 97 98 public String getExpiryYear() { 99 String dateString = getExpiryDate(); 100 if (dateString != null) { 101 int slashStart = dateString.indexOf("/"); 103 if (slashStart != -1) return dateString.substring(slashStart +1, dateString.length()); 104 105 } 106 return "2010"; 107 } 108 109 public CreditCard getData() { 110 CreditCard creditCard = new CreditCard(); 111 creditCard.setCardNumber(getCardNumber()); 112 creditCard.setCardType(getCardType()); 113 creditCard.setExpiryDate(getExpiryDate()); 114 return creditCard; 115 } 116 117 public void setEntityContext(EntityContext c) { 120 context = c; 121 } 122 public void unsetEntityContext() { 123 context = null; 124 } 125 public void ejbRemove() throws RemoveException { } 126 public void ejbActivate() { } 127 public void ejbPassivate() { } 128 public void ejbStore() { } 129 public void ejbLoad() { } 130 } 131 | Popular Tags |