//----------------------------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.xpdl.activity;

import org.huihoo.workflow.WorkflowSerializable;

public final class PerformerType implements WorkflowSerializable
{
	/**
	 * no human performer . computer performs work automatically
	 */
	public final static PerformerType PERFORMER_AUTOMATION        = new PerformerType("AUTOMATION");
	
	public final static PerformerType PERFORMER_PARTICIPANT = new PerformerType("PARTICIPANT");
	public final static PerformerType PERFORMER_DEPARTMENT  = new PerformerType("DEPARTMENT");
	public final static PerformerType PERFORMER_RANK        = new PerformerType("RANK");
	public final static PerformerType PERFORMER_CATEGORY    = new PerformerType("CATEGORY");
	public final static PerformerType PERFORMER_GROUP       = new PerformerType("GROUP");
	public final static PerformerType PERFORMER_ROLE        = new PerformerType("ROLE");
	public final static PerformerType PERFORMER_SELECTOR    = new PerformerType("SELECTOR");
	
	private String type;

	private PerformerType(String type)
	{
		this.type = type;
	}

	public String getType()
	{
		return type;
	}

	public static PerformerType parse(String type)
	{	
		if ("AUTOMATION".equals(type))
		{
			return PERFORMER_AUTOMATION;
		}
		else if ("PARTICIPANT".equals(type))
		{
			return PERFORMER_PARTICIPANT;
		}
		else if ("DEPARTMENT".equals(type))
		{
			return PERFORMER_DEPARTMENT;
		}
		else if ("RANK".equals(type))
		{
			return PERFORMER_RANK;
		}
		else if ("CATEGORY".equals(type))
		{
			return PERFORMER_CATEGORY;
		}
		else if ("GROUP".equals(type))
		{
			return PERFORMER_GROUP;
		}
		else if ("ROLE".equals(type))
		{
			return PERFORMER_ROLE;
		}
		else if ("SELECTOR".equals(type))
		{
			return PERFORMER_SELECTOR;
		}		
		//default value is PERFORMER_AUTOMATION

		return PERFORMER_AUTOMATION;
	}

	public boolean equals(Object obj)
	{
		if (this == obj)
		{
			return true;
		}

		if (obj instanceof PerformerType)
		{
			PerformerType anotherPT = (PerformerType) obj;

			if (anotherPT.getType().equals(type))
			{
				return true;
			}
		}

		return false;
	}

	public String toString()
	{
		return "PerformerType@" + type;
	}
}
