//----------------------------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 class JoinType implements WorkflowSerializable
{
	public final static JoinType JOIN_AND    = new JoinType("AND");
	public final static JoinType JOIN_XOR    = new JoinType("XOR");
	public final static JoinType JOIN_OR     = new JoinType("OR");
	public final static JoinType JOIN_WEIGHT = new JoinType("WEIGHT");

	//for shared route (just used to predigest process)
	public final static JoinType JOIN_ROUTE = new JoinType("ROUTE");

	//used for activity multi-instance (i.e meeting signature)
	public final static JoinType JOIN_INSTANCE_AND = new JoinType("INSTANCE_AND");
	public final static JoinType JOIN_INSTANCE_XOR = new JoinType("INSTANCE_XOR");
	public final static JoinType JOIN_INSTANCE_WEIGHT = new JoinType("INSTANCE_WEIGHT");

	public final static JoinType JOIN_UNKNOWN = new JoinType("UNKNOWN");

	private String type;

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

	public String getType()
	{
		return type;
	}

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

		if (obj instanceof JoinType)
		{
			JoinType anotherJT = (JoinType) obj;

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

		return false;
	}

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

	public static JoinType parse(String type)
	{
		if ("AND".equals(type))
		{
			return JOIN_AND;
		}
		else if ("XOR".equals(type))
		{
			return JOIN_XOR;
		}
		else if ("WEIGHT".equals(type))
		{
			return JOIN_WEIGHT;
		}
		else if ("OR".equals(type))
		{
			return JOIN_OR;
		}
		else if ("ROUTE".equals(type))
		{
			return JOIN_ROUTE;
		}
		else if ("INSTANCE_AND".equals(type))
		{
			return JOIN_INSTANCE_AND;
		}
		else if ("INSTANCE_XOR".equals(type))
		{
			return JOIN_INSTANCE_XOR;
		}
		else if ("INSTANCE_WEIGHT".equals(type))
		{
			return JOIN_INSTANCE_WEIGHT;
		}

		return JOIN_UNKNOWN;
	}
}
