1 package edu.rice.rubis.beans; 2 3 import java.rmi.*; 4 import javax.ejb.*; 5 import javax.rmi.PortableRemoteObject ; 6 import javax.naming.InitialContext ; 7 8 30 31 public class CommentBean implements EntityBean 32 { 33 private EntityContext entityContext; 34 private transient boolean isDirty; 36 37 38 public Integer id; 39 public Integer fromUserId; 40 public Integer toUserId; 41 public Integer itemId; 42 public int rating; 43 public String date; 44 public String comment; 45 46 47 53 public Integer getId() throws RemoteException 54 { 55 return id; 56 } 57 58 64 public Integer getFromUserId() throws RemoteException 65 { 66 return fromUserId; 67 } 68 69 75 public Integer getToUserId() throws RemoteException 76 { 77 return toUserId; 78 } 79 80 86 public Integer getItemId() throws RemoteException 87 { 88 return itemId; 89 } 90 91 97 public float getRating() throws RemoteException 98 { 99 return rating; 100 } 101 102 108 public String getDate() throws RemoteException 109 { 110 return date; 111 } 112 113 119 public String getComment() throws RemoteException 120 { 121 return comment; 122 } 123 124 125 132 public void setFromUserId(Integer id) throws RemoteException 133 { 134 fromUserId = id; 135 isDirty = true; } 137 138 145 public void setToUserId(Integer id) throws RemoteException 146 { 147 toUserId = id; 148 isDirty = true; } 150 151 158 public void setItemId(Integer id) throws RemoteException 159 { 160 itemId = id; 161 isDirty = true; } 163 164 170 public void setRating(int Rating) throws RemoteException 171 { 172 rating = Rating; 173 isDirty = true; } 175 176 182 public void setDate(String newDate) throws RemoteException 183 { 184 date = newDate; 185 isDirty = true; } 187 188 194 public void setComment(String newComment) throws RemoteException 195 { 196 comment = newComment; 197 isDirty = true; } 199 200 201 216 public CommentPK ejbCreate(Integer FromUserId, Integer ToUserId, Integer ItemId, int Rating, String Comment) throws CreateException, RemoteException, RemoveException 217 { 218 IDManagerHome home = null; 220 IDManager idManager = null; 221 222 try 223 { 224 InitialContext initialContext = new InitialContext (); 225 home = (IDManagerHome)PortableRemoteObject.narrow(initialContext.lookup( 226 "java:comp/env/ejb/IDManager"), IDManagerHome.class); 227 } 228 catch (Exception e) 229 { 230 throw new EJBException("Cannot lookup IDManager: " +e); 231 } 232 try 233 { 234 IDManagerPK idPK = new IDManagerPK(); 235 idManager = home.findByPrimaryKey(idPK); 236 id = idManager.getNextCommentID(); 237 fromUserId = FromUserId; 238 toUserId = ToUserId; 239 itemId = ItemId; 240 rating = Rating; 241 date = TimeManagement.currentDateToString(); 242 comment = Comment; 243 } 244 catch (Exception e) 245 { 246 throw new EJBException("Cannot create comment: " +e); 247 } 248 return null; 249 } 250 251 253 public void ejbPostCreate(Integer FromUserId, Integer ToUserId, Integer ItemId, int Rating, String Comment) 254 { 255 isDirty = true; } 257 258 260 public void ejbLoad() throws RemoteException 261 { 262 isDirty = false; 263 } 264 265 267 public void ejbStore() throws RemoteException 268 { 269 isDirty = false; 270 } 271 272 273 public void ejbActivate() throws RemoteException {} 274 275 public void ejbPassivate() throws RemoteException {} 276 277 public void ejbRemove() throws RemoteException, RemoveException {} 278 279 296 public void setEntityContext(EntityContext context) throws RemoteException 297 { 298 entityContext = context; 299 } 300 301 318 public void unsetEntityContext() throws RemoteException 319 { 320 entityContext = null; 321 } 322 323 330 public boolean isModified() 331 { 332 return isDirty; 333 } 334 335 336 343 public String printComment(String userName) throws RemoteException 344 { 345 return "<DT><b><BIG><a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.ViewUserInfo?userId="+fromUserId+"\">"+userName+"</a></BIG></b>"+ 346 " wrote the "+date+"<DD><i>"+comment+"</i><p>\n"; 347 } 348 } 349 | Popular Tags |