KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > impl > PosterImpl


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Forums JBoss Portlet *
6  * *
7  * Distributable under LGPL license. *
8  * See terms of license at gnu.org. *
9  * *
10  *****************************************/

11 package org.jboss.portlet.forums.impl;
12
13 import javax.naming.InitialContext JavaDoc;
14 import javax.naming.NamingException JavaDoc;
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 /**
23  * @hibernate.class table="jbp_forums_posters"
24  *
25  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
26  * @author <a HREF="mailto:theute@jboss.org">Thomas Heute</a>
27  * @version $Revision: 1.8 $
28  */

29 public class PosterImpl
30    implements Poster
31 {
32    private Integer JavaDoc id;
33    private Integer JavaDoc userID;
34    private String JavaDoc userName;
35    private User user;
36    private int nbPosts = 0;
37
38    /**
39     * Creates a new {@link PosterImpl} object.
40     */

41    public PosterImpl()
42    {
43    }
44
45    public PosterImpl(Integer JavaDoc userId)
46    {
47       setUserID(userId);
48    }
49
50    /**
51     * DOCUMENT_ME
52     *
53     * @return DOCUMENT_ME
54     */

55    public User getUser()
56    {
57       if (user == null)
58       {
59          try
60          {
61             UserModule userModule = (UserModule) new InitialContext JavaDoc().lookup(ModuleConstants.USERMODULE_JNDINAME);
62             user = userModule.findUserByID(userID);
63          }
64          catch (NamingException JavaDoc e)
65          {
66             return null;
67          }
68          catch (IllegalArgumentException JavaDoc 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    /**
83     * @hibernate.id
84     * column="jbp_id"
85     * generator-class="native"
86     * @return Returns the id.
87     */

88    public Integer JavaDoc getID()
89    {
90       return id;
91    }
92    
93    /**
94     * @param id The id to set.
95     */

96    public void setID(Integer JavaDoc id)
97    {
98       this.id = id;
99    }
100
101    /**
102     * This column has the unique constraints as it reflects the user id.
103     *
104     * @hibernate.property
105     * column="jbp_user_id"
106     * unique="true"
107     * @return Returns the id.
108     */

109    public Integer JavaDoc getUserID()
110    {
111       return userID;
112    }
113
114    /**
115     * @param userID The id to set.
116     */

117    public void setUserID(Integer JavaDoc userID)
118    {
119       this.userID = userID;
120    }
121    
122    /**
123     * @hibernate.property
124     * column="jbp_post_count"
125     */

126    public int getPostCount()
127    {
128       return nbPosts;
129    }
130
131    private void setPostCount(int nbPosts)
132    {
133       this.nbPosts = nbPosts;
134    }
135
136    /**
137     * DOCUMENT_ME
138     */

139    public void incrementPostCount()
140    {
141       setPostCount(nbPosts + 1);
142    }
143 }
Popular Tags