//----------------------------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.coreImpl.server;

import org.huihoo.workflow.WorkflowException;
import org.huihoo.workflow.server.WorkflowCase;
import org.huihoo.workflow.server.WorkflowWork;
import org.huihoo.workflow.usermodel.WorkflowParticipant;
import org.huihoo.workflow.xpdl.WorkflowActivity;
import org.huihoo.workflow.xpdl.activity.Implementation;

public class WorkflowWorkImpl extends  WorkflowWork
{
	protected WorkflowCase workflowCase;
	protected WorkflowActivity activity;
	protected WorkflowParticipant performer;

	protected java.util.Date arriveTime;
	protected java.util.Date acceptTime;
	protected java.util.Date submitTime;

	protected int priority;
	protected int eventType;

	protected String userObject;

	protected WorkflowWork parentWork;
	
	public WorkflowWorkImpl()
	{
	}

	public WorkflowWorkImpl(
		String uuid,
		String name,
		String description,
		WorkflowCase workflowCase_,
		WorkflowActivity activity_,
		WorkflowParticipant performer_)
	{
		super(uuid, name, description);

		this.workflowCase = workflowCase_;
		this.activity = activity_;
		this.performer = performer_;
	}

	public void execute() throws WorkflowException
	{
		Implementation impl = activity.getImplementation();
		impl.execute(this,Thread.currentThread().getContextClassLoader());
	}

	public WorkflowCase getCase()
	{
		return workflowCase;
	}
	public void setCase(WorkflowCase workflowCase_)
	{
		this.workflowCase = workflowCase_;
	}
	public WorkflowActivity getActivity()
	{
		return activity;
	}
	public void setActivity(WorkflowActivity activity_)
	{
		this.activity = activity_;
	}
	public WorkflowParticipant getPerformer()
	{
		return performer;
	}

	public void setPerformer(WorkflowParticipant performer_)
	{
		this.performer = performer_;
	}

	public java.util.Date getArriveTime()
	{
		return this.arriveTime;
	}
	public void setArriveTime(java.util.Date arriveTime_)
	{
		this.arriveTime = arriveTime_;
	}

	public java.util.Date getAcceptTime()
	{
		return this.acceptTime;
	}

	public void setAcceptTime(java.util.Date acceptTime_)
	{
		this.acceptTime = acceptTime_;
	}

	public java.util.Date getDispatchTime()
	{
		return this.submitTime;
	}

	public void setDispatchTime(java.util.Date submitTime_)
	{
		this.submitTime = submitTime_;
	}

	public String getUserObject()
	{
		return userObject;
	}

	public void setUserObject(String userObject)
	{
		this.userObject = userObject;
	}

	public int getPriority()
	{
		return this.priority;
	}
	public void setPriority(int priority)
	{
		this.priority = priority;
	}

	public int getEventType()
	{
		return eventType;
	}

	public void setEventType(int eventType_)
	{
		this.eventType = eventType_;
	}

	public WorkflowWork getParentWork()
	{
		return parentWork;
	}
  
	public void setParentWork(WorkflowWork parentWork_)
	{
		this.parentWork=parentWork_;
	}

	public String getTagName()
	{
		return "WorkflowWork";
	}
	
	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		
		sb.append("[");
		sb.append(getTagName()+":");
		sb.append("[uuid=");
		sb.append(uuid==null ? "?" : uuid);
		sb.append("]");
		sb.append("]");
		
		return sb.toString();
	}
}
