1 package edu.rice.rubis.beans; 2 3 import java.rmi.RemoteException ; 4 import javax.ejb.SessionBean ; 5 import javax.ejb.SessionContext ; 6 import javax.ejb.FinderException ; 7 import javax.ejb.ObjectNotFoundException ; 8 import javax.ejb.CreateException ; 9 import javax.ejb.RemoveException ; 10 import javax.ejb.EJBException ; 11 import javax.naming.Context ; 12 import javax.naming.InitialContext ; 13 import javax.rmi.PortableRemoteObject ; 14 import javax.sql.DataSource ; 15 import java.io.Serializable ; 16 import javax.transaction.UserTransaction ; 17 18 24 25 public class SB_PutBidBean implements SessionBean 26 { 27 protected SessionContext sessionContext; 28 protected Context initialContext = null; 29 protected DataSource dataSource = null; 30 32 33 39 public String getBiddingForm(Integer itemId, String username, String password) throws RemoteException 40 { 41 int userId = -1; 42 String html = ""; 43 44 if ((username != null && !username.equals("")) || (password != null && !password.equals(""))) 46 { 47 SB_AuthHome authHome = null; 48 SB_Auth auth = null; 49 try 50 { 51 authHome = (SB_AuthHome)PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/SB_Auth"), SB_AuthHome.class); 52 auth = authHome.create(); 53 } 54 catch (Exception e) 55 { 56 throw new RemoteException ("Cannot lookup SB_Auth: " +e); 57 } 58 try 59 { 60 userId = auth.authenticate(username, password); 61 } 62 catch (Exception e) 63 { 64 throw new RemoteException ("Authentication failed: " +e); 65 } 66 if (userId == -1) 67 { 68 html = (" You don't have an account on RUBiS!<br>You have to register first.<br>"); 69 return html; 70 } 71 } 72 73 SB_ViewItemHome itemHome; 74 SB_ViewItem viewItem; 75 try 76 { 77 itemHome = (SB_ViewItemHome)PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/ejb/SB_ViewItem"), 78 SB_ViewItemHome.class); 79 viewItem = itemHome.create(); 80 } 81 catch (Exception e) 82 { 83 throw new RemoteException ("Cannot lookup SB_ViewItem: " +e+"<br>"); 84 } 85 try 86 { 87 html = viewItem.getItemDescription(itemId, userId); 88 } 89 catch (Exception e) 90 { 91 throw new RemoteException ("Exception getting the item information: "+ e +"<br>"); 92 } 93 94 return html; 95 } 96 97 98 99 101 104 public void ejbCreate() throws CreateException , RemoteException 105 { 106 } 107 108 109 public void ejbActivate() throws RemoteException {} 110 111 public void ejbPassivate() throws RemoteException {} 112 113 public void ejbRemove() throws RemoteException {} 114 115 116 125 public void setSessionContext(SessionContext sessionContext) throws RemoteException 126 { 127 this.sessionContext = sessionContext; 128 if (dataSource == null) 129 { 130 132 try 133 { 134 initialContext = new InitialContext (); 135 dataSource = (DataSource )initialContext.lookup("java:comp/env/jdbc/rubis"); 136 } 137 catch (Exception e) 138 { 139 throw new RemoteException ("Cannot get JNDI InitialContext"); 140 } 141 } 142 } 143 144 } 145 | Popular Tags |