View Javadoc
1   /******************************************************************************
2    * UserFactory.java - Implement the BSAccount UserFactory interface for PicMan
3    * 
4    * PicMan - The BuckoSoft Picture Manager in Java
5    * Copyright(c) 2007 - Dick Balaska
6    * 
7    */
8   
9   package com.buckosoft.PicMan.business.common;
10  
11  import org.apache.commons.logging.Log;
12  import org.apache.commons.logging.LogFactory;
13  
14  import com.buckosoft.BSAccount.BSAccountMan;
15  import com.buckosoft.BSAccount.domain.BSAccount;
16  import com.buckosoft.BSAccount.domain.BSAccountUser;
17  import com.buckosoft.BSAccount.web.BSAccountUserWebSession;
18  import com.buckosoft.PicMan.db.DatabaseFacade;
19  import com.buckosoft.PicMan.domain.User;
20  
21  /** Implement the <a target="_top" href="http://www.buckosoft.com/java/javadoc/BSAccount/">BSAccount</a>
22   * UserFactory interface for PicMan.
23   * @author Dick Balaska
24   * @since 2007/09/26
25   */
26  public class UserFactory implements com.buckosoft.BSAccount.domain.UserFactory {
27  	protected final static boolean DEBUG = false;
28  	protected final Log logger = LogFactory.getLog(getClass());
29  
30  	@SuppressWarnings("unused")
31  	private	BSAccountMan	bsAccountMan = null;
32  	
33  	private DatabaseFacade	dbf;
34  
35  	/**
36  	 * @param dbf the db to set
37  	 */
38  	public void setDatabase(DatabaseFacade dbf) { this.dbf = dbf; }
39  
40  
41  	/** Set the reference to BSAccountMan
42  	 * @param bsAccountMan the BSAccountMan to set
43  	 */
44  	public void setBsAccountMan(BSAccountMan bsAccountMan) {
45  		this.bsAccountMan = bsAccountMan;
46  	}
47  
48  	/* (non-Javadoc)
49  	 * @see com.buckosoft.BSAccount.domain.UserFactory#getNewUser()
50  	 */
51  	public BSAccountUser getNewUser() {
52  		if (DEBUG)
53  			logger.info("getNewUser()");
54  		return(new User(null));
55  	}
56  
57  	/* (non-Javadoc)
58  	 * @see com.buckosoft.BSAccount.domain.UserFactory#getNewUserWebSession(com.buckosoft.BSAccount.domain.BSAccountUser)
59  	 */
60  	public BSAccountUserWebSession getNewUserWebSession(BSAccountUser user) {
61  		return(new BSAccountUserWebSession(user));
62  	}
63  
64  	/* (non-Javadoc)
65  	 * @see com.buckosoft.BSAccount.domain.UserFactory#getUser(com.buckosoft.BSAccount.domain.BSAccount)
66  	 */
67  	public BSAccountUser getUser(BSAccount account) {
68  		if (DEBUG)
69  			logger.info("getUser: " + account == null ? "account = null" : "account userid=" + account.getUserId());
70  		if (account == null)
71  			return(null);
72  		User user = null;
73  		user = dbf.getUser(account.getUserId());
74  		if (user == null)
75  			return(new User(account));
76  		user.setAccount(account);
77  		return(user);
78  	}
79  
80  }