View Javadoc
1   /******************************************************************************
2    * BSAccountUser.java - Be a User
3    * 
4    * BSAccount - BuckoSoft Web Account Manager 
5    * Copyright(c) 2007 - Dick Balaska and BuckoSoft, Corp.
6    * 
7    */
8   package com.buckosoft.BSAccount.domain;
9   
10  import java.io.Serializable;
11  import java.util.Date;
12  
13  /** Be a User, base class for an app's User.  Encapsulates an Account, which can be anonymous or logged in.
14   * @author dick
15   *
16   */
17  public class BSAccountUser implements Serializable {
18  	private static final long serialVersionUID = 1L;
19  
20  	private	BSAccount	account = null;
21  	private	Date		lastAccess;
22  
23  	public BSAccountUser(BSAccount account) {
24  		this.account = account;
25  	}
26  	
27  	/** Get the account;  This is not a standard bean getter method because i want you to think twice
28  	 * about whether you really want to access the account directly.
29  	 * @return the BSAccount for this user
30  	 */
31  	public BSAccount accessAccount() {
32  		return account;
33  	}
34  	/** Set this user's BSAccount.
35  	 * @param account the account to set
36  	 */
37  	public void setAccount(BSAccount account) {
38  		this.account = account;
39  	}
40  	
41  	/** Convenience accessor to the userid
42  	 * @return the userId from the account or -1 if there is no account.
43  	 */
44  	public int	getUserId() {
45  		if (account == null)
46  			return(-1);
47  		return(this.account.getUserId());
48  	}
49  	/** Convenience accessor to get the username.
50  	 * This will never return null
51  	 * @return The username in the account or the Empty String if account is null
52  	 */
53  	public	String	getUsername() {
54  		if (this.account == null)
55  			return("");
56  		return(account.getUsername());
57  	}
58  	/**
59  	 * @return the lastAccess
60  	 */
61  	public Date getLastAccess() {
62  		return lastAccess;
63  	}
64  	/**
65  	 * @param lastAccess the lastAccess to set
66  	 */
67  	public void setLastAccess(Date lastAccess) {
68  		this.lastAccess = lastAccess;
69  	}
70  	
71  	/** Is this user registered in our database and logged in
72  	 * @return true if logged in, false if anonymous
73  	 */
74  	public	boolean	isRegisteredUser() {
75  		if (account == null)
76  			return(false);
77  		return(this.account.isRegisteredUser());
78  	}
79  }