//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010 huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE----------------------------

package org.huihoo.workflow.server;

import java.util.HashMap;
import java.util.Iterator;


public class WorkflowXPDLRepository
{
	private static WorkflowXPDLRepository repositoryInstance;

	public static WorkflowXPDLRepository getInstance()
	{
		if (repositoryInstance == null)
		{
			synchronized (WorkflowXPDLRepository.class)
			{
				if (repositoryInstance == null)
				{
					repositoryInstance = new WorkflowXPDLRepository();
				}
			}
		}

		return repositoryInstance;
	}

	//---------------------------------------------------------------
	//
	//---------------------------------------------------------------
	private HashMap map;

	private WorkflowXPDLRepository()
	{
		map = new HashMap();
	}

	public WorkflowXPDL findWorkflowXPDL(String workflowXPDL)
	{
		return (WorkflowXPDL) map.get(workflowXPDL);
	}

	public Iterator findWorkflowXPDLs()
	{
		return map.keySet().iterator();
	}

	public synchronized void addWorkflowXPDL(WorkflowXPDL workflowXPDL)
	{
		map.put(workflowXPDL.getWorkflowPackage().getUUID(), workflowXPDL);
	}

	public synchronized void removeWorkflowXPDL(WorkflowXPDL workflowXPDL)
	{
		map.remove(workflowXPDL.getWorkflowPackage().getUUID());
	}

	public synchronized void cleanup()
	{
		map.clear();
	}
}
