1 27 28 package cart; 29 30 import exception.BookException; 31 import java.util.Vector ; 32 import javax.ejb.*; 33 import util.IdVerifier; 34 35 public class CartBean implements SessionBean, CartRemoteBusiness, CartLocalBusiness { 36 private SessionContext context; 37 String customerName; 38 String customerId; 39 Vector contents; 40 41 47 public void setSessionContext(SessionContext aContext) { 48 context = aContext; 49 } 50 51 54 public void ejbActivate() { 55 56 } 57 58 61 public void ejbPassivate() { 62 63 } 64 65 68 public void ejbRemove() { 69 70 } 71 73 77 public void ejbCreate() { 78 } 83 84 85 86 87 88 91 public void ejbCreate(String person) throws CreateException { 92 if(person == null) { 94 throw new CreateException("Null person not allowed."); 95 }else{ 96 customerName = person; 97 } 98 customerId = "0"; 99 contents = new Vector (); 100 } 101 102 public void ejbCreate(String person, String id) throws CreateException { 103 if(person == null) { 105 throw new CreateException("Null person not allowed."); 106 }else{ 107 customerName = person; 108 } 109 110 IdVerifier idChecker = new IdVerifier(); 111 if(idChecker.validate(id)){ 112 customerId = id; 113 }else{ 114 throw new CreateException("Invalid id: " + id); 115 } 116 contents = new Vector (); 117 } 118 119 public void addBook(String title) { 120 contents.add(title); 122 } 123 124 public void removeBook(String title) throws BookException { 125 boolean result = contents.remove(title); 127 if(result == false) 128 throw new BookException(title + " not in cart."); 129 } 130 131 public Vector getContents() { 132 return contents; 134 } 135 136 } 137 | Popular Tags |