1 11 package org.jboss.portlet.forums.impl; 12 13 import javax.naming.InitialContext ; 14 import javax.naming.NamingException ; 15 16 import org.jboss.portal.core.model.User; 17 import org.jboss.portal.core.modules.ModuleConstants; 18 import org.jboss.portal.core.modules.ModuleException; 19 import org.jboss.portal.core.modules.UserModule; 20 import org.jboss.portlet.forums.model.Poster; 21 22 29 public class PosterImpl 30 implements Poster 31 { 32 private Integer id; 33 private Integer userID; 34 private String userName; 35 private User user; 36 private int nbPosts = 0; 37 38 41 public PosterImpl() 42 { 43 } 44 45 public PosterImpl(Integer userId) 46 { 47 setUserID(userId); 48 } 49 50 55 public User getUser() 56 { 57 if (user == null) 58 { 59 try 60 { 61 UserModule userModule = (UserModule) new InitialContext ().lookup(ModuleConstants.USERMODULE_JNDINAME); 62 user = userModule.findUserByID(userID); 63 } 64 catch (NamingException e) 65 { 66 return null; 67 } 68 catch (IllegalArgumentException e) 69 { 70 e.printStackTrace(); 71 return null; 72 } 73 catch (ModuleException e) 74 { 75 e.printStackTrace(); 76 return null; 77 } 78 } 79 return user; 80 } 81 82 88 public Integer getID() 89 { 90 return id; 91 } 92 93 96 public void setID(Integer id) 97 { 98 this.id = id; 99 } 100 101 109 public Integer getUserID() 110 { 111 return userID; 112 } 113 114 117 public void setUserID(Integer userID) 118 { 119 this.userID = userID; 120 } 121 122 126 public int getPostCount() 127 { 128 return nbPosts; 129 } 130 131 private void setPostCount(int nbPosts) 132 { 133 this.nbPosts = nbPosts; 134 } 135 136 139 public void incrementPostCount() 140 { 141 setPostCount(nbPosts + 1); 142 } 143 } | Popular Tags |