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 32 33 public class UserBean implements EntityBean 34 { 35 private EntityContext entityContext; 36 private transient boolean isDirty; 38 39 40 public Integer id; 41 public String firstName; 42 public String lastName; 43 public String nickName; 44 public String password; 45 public String email; 46 public int rating; 47 public float balance; 48 public String creationDate; 49 public Integer regionId; 50 51 52 58 public Integer getId() throws RemoteException 59 { 60 return id; 61 } 62 63 69 public String getFirstName() throws RemoteException 70 { 71 return firstName; 72 } 73 74 80 public String getLastName() throws RemoteException 81 { 82 return lastName; 83 } 84 85 91 public String getNickName() throws RemoteException 92 { 93 return nickName; 94 } 95 96 102 public String getPassword() throws RemoteException 103 { 104 return password; 105 } 106 107 113 public String getEmail() throws RemoteException 114 { 115 return email; 116 } 117 118 124 public int getRating() throws RemoteException 125 { 126 return rating; 127 } 128 129 136 public float getBalance() throws RemoteException 137 { 138 return balance; 139 } 140 141 147 public String getCreationDate() throws RemoteException 148 { 149 return creationDate; 150 } 151 152 158 public Integer getRegionId() throws RemoteException 159 { 160 return regionId; 161 } 162 163 164 170 public void setFirstName(String newName) throws RemoteException 171 { 172 firstName = newName; 173 isDirty = true; } 175 176 182 public void setLastName(String newName) throws RemoteException 183 { 184 lastName = newName; 185 isDirty = true; } 187 188 194 public void setNickName(String newName) throws RemoteException 195 { 196 nickName = newName; 197 isDirty = true; } 199 200 206 public void setPassword(String newPassword) throws RemoteException 207 { 208 password = newPassword; 209 isDirty = true; } 211 212 218 public void setEmail(String newEmail) throws RemoteException 219 { 220 email = newEmail; 221 isDirty = true; } 223 224 230 public void setCreationDate(String newCreationDate) throws RemoteException 231 { 232 creationDate = newCreationDate; 233 isDirty = true; } 235 236 243 public void setRegionId(Integer id) throws RemoteException 244 { 245 regionId = id; 246 isDirty = true; } 248 249 255 public void setRating(int newRating) throws RemoteException 256 { 257 rating = newRating; 258 isDirty = true; } 260 261 268 public void updateRating(int diff) throws RemoteException 269 { 270 rating += diff; 271 isDirty = true; } 273 274 281 public void setBalance(float newBalance) throws RemoteException 282 { 283 balance = newBalance; 284 isDirty = true; } 286 287 288 295 public String getHTMLGeneralUserInformation() throws RemoteException 296 { 297 String result = new String (); 298 299 result = result+"<h2>Information about "+nickName+"<br></h2>"; 300 result = result+"Real life name : "+firstName+" "+lastName+"<br>"; 301 result = result+"Email address : "+email+"<br>"; 302 result = result+"User since : "+creationDate+"<br>"; 303 result = result+"Current rating : <b>"+rating+"</b><br>"; 304 return result; 305 } 306 307 308 310 327 public UserPK ejbCreate(String userFirstName, String userLastName, String userNickName, String userEmail, 328 String userPassword, Integer userRegionId) throws CreateException, RemoteException, RemoveException 329 { 330 IDManagerHome home = null; 332 IDManager idManager = null; 333 334 try 335 { 336 InitialContext initialContext = new InitialContext (); 337 home = (IDManagerHome)PortableRemoteObject.narrow(initialContext.lookup( 338 "java:comp/env/ejb/IDManager"), IDManagerHome.class); 339 } 340 catch (Exception e) 341 { 342 throw new EJBException("Cannot lookup IDManager: " +e); 343 } 344 try 345 { 346 IDManagerPK idPK = new IDManagerPK(); 347 idManager = home.findByPrimaryKey(idPK); 348 id = idManager.getNextUserID(); 349 firstName = userFirstName; 350 lastName = userLastName; 351 nickName = userNickName; 352 password = userPassword; 353 email = userEmail; 354 regionId = userRegionId; 355 creationDate = TimeManagement.currentDateToString(); 356 } 357 catch (Exception e) 358 { 359 throw new EJBException("Cannot create user: " +e); 360 } 361 return null; 362 } 363 364 365 367 public void ejbPostCreate(String userFirstName, String userLastName, String userNickName, String userEmail, 368 String userPassword, Integer userRegionId) 369 { 370 isDirty = true; } 372 373 375 public void ejbLoad() throws RemoteException 376 { 377 isDirty = false; 378 } 379 380 382 public void ejbStore() throws RemoteException 383 { 384 isDirty = false; 385 } 386 387 388 public void ejbActivate() throws RemoteException {} 389 390 public void ejbPassivate() throws RemoteException {} 391 392 public void ejbRemove() throws RemoteException, RemoveException {} 393 394 411 public void setEntityContext(EntityContext context) throws RemoteException 412 { 413 entityContext = context; 414 } 415 416 433 public void unsetEntityContext() throws RemoteException 434 { 435 entityContext = null; 436 } 437 438 439 446 public boolean isModified() 447 { 448 return isDirty; 449 } 450 451 } 452 | Popular Tags |