/*
 * Created on 2004-10-6
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.huihoo.willow.core;

import java.util.Hashtable;

import workflow.script.interpretor.ScriptInterpretor;
import workflow.services.WorkflowService;
import workflow.store.CaseDatabase;
import workflow.store.UserDatabase;
import workflow.store.WorkflowDispatcher;
import workflow.wfmc.xpdl.WorkflowPackage;

import com.zosatapo.workflow.threads.EventMonitorThread;

/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public abstract class ContextBase extends ContainerBase implements WorkflowService
{
	protected Hashtable hash_packages = new Hashtable();
	public WorkflowPackage findWorkflowPackage(String packageID)
	{
		return (WorkflowPackage) hash_packages.get(packageID);
	}
	public WorkflowPackage reomveWorkflowPackage(String packageID)
	{
		return (WorkflowPackage) hash_packages.remove(packageID);
	}

	public void addWorkflowPackage(WorkflowPackage workflowPackage)
	{
		hash_packages.put(workflowPackage.getUUID(), workflowPackage);
	}

	protected UserDatabase userDatabase;
	public UserDatabase getUserDatabase()
	{
		return userDatabase;
	}
	public void setUserDatabase(UserDatabase userDatabase)
	{
		this.userDatabase = userDatabase;
	}

	protected CaseDatabase caseDatabase;
	public CaseDatabase getCaseDatabase()
	{
		return caseDatabase;
	}
	public void setCaseDatabase(CaseDatabase caseDatabase)
	{
		this.caseDatabase = caseDatabase;
	}

	protected WorkflowDispatcher workDispatcher;
	public WorkflowDispatcher getWorkflowDispatcher()
	{
		return workDispatcher;
	}
	public void setWorkDispatcher(WorkflowDispatcher workDispatcher)
	{
		this.workDispatcher = workDispatcher;
	}

	protected ScriptInterpretor scriptInterpretor;
	public ScriptInterpretor getScriptInterpretor()
	{
		return this.scriptInterpretor;
	}

	public void setScriptInterpretor(ScriptInterpretor scriptInterpretor)
	{
		this.scriptInterpretor = scriptInterpretor;
	}

	protected EventMonitorThread eventMonitorThread;
	public EventMonitorThread getEventMonitorThread()
	{
		return eventMonitorThread;
	}
	public void setEventMonitorThread(EventMonitorThread eventMonitorThread)
	{
		this.eventMonitorThread = eventMonitorThread;
	}

	/**
		 * Start the background thread that will periodically check for
		 * session timeouts.
		 */
	protected void threadStart()
	{
		super.threadStart();

		if (eventMonitorThread != null)
		{
			return;
		}
		eventMonitorThread = new EventMonitorThread();
		eventMonitorThread.start();

	}

	/**
	 * Stop the background thread that is periodically checking for
	 * session timeouts.
	 */
	protected void threadStop()
	{
		super.threadStop();

		if (eventMonitorThread == null)
		{
			return;
		}

		eventMonitorThread.interrupt();
		eventMonitorThread = null;
	}

}
