View Javadoc

1   /***
2    *  The contents of this file are subject to the Mozilla Public
3    *  License Version 1.1 (the "License"); you may not use this file
4    *  except in compliance with the License. You may obtain a copy of
5    *  the License at http://www.mozilla.org/MPL/
6    *
7    *  Software distributed under the License is distributed on an "AS
8    *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9    *  implied. See the License for the specific language governing
10   *  rights and limitations under the License.
11   *
12   *  The Original Code is pow2toolkit library.
13   *
14   *  The Initial Owner of the Original Code is
15   *  Power Of Two S.R.L. (www.pow2.com)
16   *
17   *  Portions created by Power Of Two S.R.L. are
18   *  Copyright (C) Power Of Two S.R.L.
19   *  All Rights Reserved.
20   *
21   * Contributor(s):
22   */
23  
24  package com.pow2.user;
25  
26  
27  import org.apache.log4j.Category;
28  
29  import com.pow2.user.dao.*;
30  
31  /***
32   *  Pow2 User class.
33   *  <br>
34   *  This class encapsulates the basic user informations; if you'd like
35   *  to have a more specialized User entity, extend this class and provide
36   *  your own implementation.
37   *
38   * @author  Luca Fossato
39   * @created  22 aprile 2002
40   */
41  public class User
42  {
43    /***
44     *  user id value for user objects that are not yet
45     *  persisted into the database.
46     */
47    public final String USER_ID_NOTPERSISTED = "-1";
48  
49    /***  Log4J category */
50    protected Category cat = Category.getInstance(this.getClass());
51  
52    /***  user authentication flag */
53    protected boolean authenticated = false;
54  
55    /*** user city */
56    protected String city = "";
57  
58    /*** the single instance of the UserDAO object */
59    protected UserDAO dao = null;
60  
61    /***  user email */
62    protected String email = "";
63  
64    /*** user fax number */
65    protected String fax = "";
66  
67    /***  user first name */
68    protected String firstName = "";
69  
70    /*** user identifier */
71    protected String id = USER_ID_NOTPERSISTED;
72  
73    /***  user last name */
74    protected String lastName = "";
75  
76    /***  user login */
77    protected String login = null;
78  
79    /*** user mobile number */
80    protected String mobile = "";
81  
82    /***  user password */
83    protected String passwd = null;
84  
85    /*** user phone number */
86    protected String phone = "";
87  
88    /*** user state */
89    protected String state;
90  
91    /*** user street */
92    protected String street;
93  
94    /*** user zip code */
95    protected String zipCode;
96  
97  
98    /*** Default User constructor. */
99    public User()
100   {
101     // get the data access provider;
102     dao = UserDAOFactory.instance().getUserDAO();
103   }
104 
105 
106   /***
107    *  User constructor.
108    *  <br>
109    *  Initialize the User object using the <code>login</code> and <code>passwd</code>
110    *  properties to retrieve the user informations from the database.
111    *  <br>
112    *  If the authentication fails (<code>login</code> and <code>password</code>
113    *  user properties don't match the database properties),
114    *  {@link #isAuthenticated() isAuthenticated} method returns false.
115    *
116    * @param  login Description of the Parameter
117    * @param  passwd Description of the Parameter
118    */
119   public User(String login, String passwd)
120   {
121     this();
122 
123     this.login  = login;
124     this.passwd = passwd;
125 
126     getProfile();
127   }
128 
129 
130   /***
131    *  Gets the city attribute of the User object
132    *
133    * @return  The city value
134    */
135   public String getCity()
136   {
137     return city;
138   }
139 
140 
141   /***
142    *  Gets the email attribute of the User object
143    *
144    * @return  The email value
145    */
146   public String getEmail()
147   {
148     return email;
149   }
150 
151 
152   /***
153    *  Gets the fax attribute of the User object
154    *
155    * @return  The fax value
156    */
157   public String getFax()
158   {
159     return fax;
160   }
161 
162 
163   /***
164    *  Gets the firstName attribute of the User object
165    *
166    * @return  The firstName value
167    */
168   public String getFirstName()
169   {
170     return firstName;
171   }
172 
173 
174   /***
175    *  Gets the id attribute of the User object
176    *
177    * @return  The id value
178    */
179   public String getId()
180   {
181     return id;
182   }
183 
184 
185   /***
186    *  Gets the lastName attribute of the User object
187    *
188    * @return  The lastName value
189    */
190   public String getLastName()
191   {
192     return lastName;
193   }
194 
195 
196   /***
197    *  Gets the login attribute of the User object
198    *
199    * @return  The login value
200    */
201   public String getLogin()
202   {
203     return login;
204   }
205 
206 
207   /***
208    *  Gets the mobile attribute of the User object
209    *
210    * @return  The mobile value
211    */
212   public String getMobile()
213   {
214     return mobile;
215   }
216 
217 
218   /***
219    *  Gets the passwd attribute of the User object
220    *
221    * @return  The passwd value
222    */
223   public String getPasswd()
224   {
225     return passwd;
226   }
227 
228 
229   /***
230    *  Gets the phone attribute of the User object
231    *
232    * @return  The phone value
233    */
234   public String getPhone()
235   {
236     return phone;
237   }
238 
239 
240   /***
241    *  Gets the user profile (its informations) from the database.
242    *  <br>
243    *  This method uses the <code>login</code> and <code>passwd</code>
244    *  properties to retrieve the user informations from the database.
245    *  <br>
246    *  If the user authentication fails (<code>login</code> and <code>password</code>
247    *  user properties don't match the database properties),
248    *  {@link #isAuthenticated() isAuthenticated} method returns false.
249    */
250   public void getProfile()
251   {
252     try
253     {
254       dao.getUser(this);
255     }
256     catch (Exception e)
257     {
258       authenticated = false;
259       cat.error("::getUser - cannot get the user profile: ", e);
260     }
261   }
262 
263 
264   /***
265    *  Gets the state attribute of the User object
266    *
267    * @return  The state value
268    */
269   public String getState()
270   {
271     return state;
272   }
273 
274 
275   /***
276    *  Gets the street attribute of the User object
277    *
278    * @return  The street value
279    */
280 
281   public String getStreet()
282   {
283     return street;
284   }
285 
286 
287   /***
288    *  Gets the zipCode attribute of the User object
289    *
290    * @return  The zipCode value
291    */
292   public String getZipCode()
293   {
294     return zipCode;
295   }
296 
297 
298   /***
299    *  Tests if the user is authenticated
300    *
301    * @return  true if the user is authenticated; false otherwise.
302    */
303   public boolean isAuthenticated()
304   {
305     return authenticated;
306   }
307 
308 
309   /***
310    *  Sets the user authentication flag.
311    *  <br>
312    *  An user is authenticated if its informations are retrieved from the
313    *  underlying database, using a <code>login</code> and <code>password</code>
314    *  couple that matches with the same database properties.
315    *
316    * @param  v true if the user is authenticated versus the database; false
317    *            otherwise.
318    */
319   public void setAuthentication(boolean v)
320   {
321     authenticated = v;
322   }
323 
324 
325   /***
326    *  Sets the city attribute of the User object
327    *
328    * @param  city The new city value
329    */
330   public void setCity(String city)
331   {
332     this.city = city;
333   }
334 
335 
336   /***
337    *  Sets the email attribute of the User object
338    *
339    * @param  v The new email value
340    */
341   public void setEmail(String v)
342   {
343     email = v;
344   }
345 
346 
347   /***
348    *  Sets the fax attribute of the User object
349    *
350    * @param  fax The new fax value
351    */
352   public void setFax(String fax)
353   {
354     this.fax = fax;
355   }
356 
357 
358   /***
359    *  Sets the firstName attribute of the User object
360    *
361    * @param  v The new firstName value
362    */
363   public void setFirstName(String v)
364   {
365     firstName = v;
366   }
367 
368 
369   /***
370    *  Sets the id attribute of the User object
371    *
372    * @param  v The new id value
373    */
374   public void setId(String v)
375   {
376     id = v;
377   }
378 
379 
380   /***
381    *  Sets the lastName attribute of the User object
382    *
383    * @param  v The new lastName value
384    */
385   public void setLastName(String v)
386   {
387     lastName = v;
388   }
389 
390 
391   /***
392    *  Sets the login attribute of the User object
393    *
394    * @param  v The new login value
395    */
396   public void setLogin(String v)
397   {
398     login = v;
399   }
400 
401 
402   /***
403    *  Sets the mobile attribute of the User object
404    *
405    * @param  mobile The new mobile value
406    */
407   public void setMobile(String mobile)
408   {
409     this.mobile = mobile;
410   }
411 
412 
413   /***
414    *  Sets the passwd attribute of the User object
415    *
416    * @param  v The new passwd value
417    */
418   public void setPasswd(String v)
419   {
420     passwd = v;
421   }
422 
423 
424   /***
425    *  Sets the phone attribute of the User object
426    *
427    * @param  phone The new phone value
428    */
429   public void setPhone(String phone)
430   {
431     this.phone = phone;
432   }
433 
434 
435 
436   /***
437    *  Sets the state attribute of the User object
438    *
439    * @param  state The new state value
440    */
441   public void setState(String state)
442   {
443     this.state = state;
444   }
445 
446 
447   /***
448    *  Sets the street attribute of the User object
449    *
450    * @param  street The new street value
451    */
452   public void setStreet(String street)
453   {
454     this.street = street;
455   }
456 
457 
458   /***
459    *  Sets the zipCode attribute of the User object
460    *
461    * @param  zipCode The new zipCode value
462    */
463   public void setZipCode(String zipCode)
464   {
465     this.zipCode = zipCode;
466   }
467 }