/*
 * Created on Sep 8, 2006
 * 
 * (C) Copyright TANDBERG Television Ltd.
 */

package com.tandbergtv.workflow.driver.event.message;

import org.jbpm.graph.exe.Token;

import com.tandbergtv.workflow.comm.ISource;
import com.tandbergtv.workflow.core.event.WorkflowEvent;
import com.tandbergtv.workflow.message.WorkflowMessage;
import com.tandbergtv.workflow.message.WorkflowMessage.MessageType;

/**
 * Abstract event that is the parent for any task status event
 * 
 * @author Vijay Silva
 * @author Sahil Verma
 */
public abstract class TaskStatusEvent extends WorkflowEvent
{
	private Token token;
	
	private WorkflowMessage message;

	/**
	 * Creates a TaskStatusEvent
	 * 
	 * @param source the source of the event
	 * @param token the token
	 * @param message the message that contains the status information
	 */
	public TaskStatusEvent(Object source, Token token, WorkflowMessage message)
	{
		super(source);
		this.token = token;
		this.message = message;
	}

	/**
	 * @return Returns the token.
	 */
	public Token getToken()
	{
		return token;
	}

	/**
	 * @return the external source of the event. This source is the device from which the
	 *         message was sent that caused this event to be triggered.
	 */
	public ISource getExternalSource()
	{
		return this.message.getSource();
	}

	/**
	 * @return Returns the message.
	 */
	public WorkflowMessage getMessage()
	{
		return this.message;
	}

	/**
	 * Indicates whether the task has failed or not
	 * 
	 * @return Returns the value of the failed flag
	 */
	public boolean hasFailed()
	{
		return (this.message.getType() == MessageType.nack);
	}
}
