/* ===================================================================
 * BasicBizContext.java
 * 
 * Created Oct 4, 2004 12:13:14 PM
 * 
 * Copyright (c) 2004 Matt Magoffin (spamsqr@msqr.us)
 * 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation; either version 2 of 
 * the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
 * 02111-1307 USA
 * ===================================================================
 * $Id: BasicBizContext.java 74 2009-05-15 04:44:37Z msqr $
 * ===================================================================
 */

package magoffin.matt.ieat.util;

import java.util.HashMap;
import java.util.Map;

import magoffin.matt.ieat.biz.BizContext;
import magoffin.matt.ieat.domain.User;
import magoffin.matt.xweb.util.AppContextSupport;

/**
 * Basic implementation of BizContext interface.
 * 
 * <p>Note this implementation is not thread safe.</p>
 * 
 * @author Matt Magoffin (spamsqr@msqr.us)
 * @version $Revision: 74 $ $Date: 2009-05-15 16:44:37 +1200 (Fri, 15 May 2009) $
 */
public class BasicBizContext implements BizContext {
	
	private User actingUser;
	private AppContextSupport appContextSupport;
	private Map<String, Object> attributes;
	
	/**
	 * Constructor.
	 * @param appContextSupport the application context
	 */
	public BasicBizContext(AppContextSupport appContextSupport) {
		this.appContextSupport = appContextSupport;
	}
	
	/**
	 * Set the ActingUser.
	 * 
	 * @param user the user to set
	 */
	public void setActingUser(User user) {
		actingUser = user;
	}

	/* (non-Javadoc)
	 * @see magoffin.matt.ieat.biz.BizContext#getActingUser()
	 */
	public User getActingUser() {
		return actingUser;
	}

	/* (non-Javadoc)
	 * @see magoffin.matt.ieat.biz.BizContext#getAppContextSupport()
	 */
	public AppContextSupport getAppContextSupport() {
		return appContextSupport;
	}
	
	/* (non-Javadoc)
	 * @see magoffin.matt.ieat.biz.BizContext#getAttribute(java.lang.String)
	 */
	public Object getAttribute(String key) {
		if ( attributes == null ) return null;
		return attributes.get(key);
	}

	/* (non-Javadoc)
	 * @see magoffin.matt.ieat.biz.BizContext#setAttribute(java.lang.String, java.lang.Object)
	 */
	public void setAttribute(String key, Object value) {
		if ( attributes == null ) {
			attributes = new HashMap<String, Object>();
		}
		attributes.put(key,value);
	}

}
