/**
 * WorkflowProcessEvent.java
 * Created May 25, 2006
 * Copyright (C) Tandberg Television 2006
 */
package com.tandbergtv.workflow.driver.event;

import org.jbpm.graph.exe.Token;

import com.tandbergtv.workflow.core.WorkflowProcess;
import com.tandbergtv.workflow.core.event.WorkflowEvent;

/**
 * Represents an event that is fired during the lifecycle of a workflow process.
 * 
 * @author Sahil Verma
 */
public class WorkflowProcessEvent extends WorkflowEvent {

	private WorkflowProcess process;
	
	private Token token;
	
	private WorkflowProcessEventType type;
	
	/**
	 * Creates a WorkflowProcessEvent
	 * 
	 * @param process the process
	 * @param type the event type
	 */
	public WorkflowProcessEvent(WorkflowProcess instance, WorkflowProcessEventType type) {
		this(null, instance, instance.getRootToken(), type);
	}

	/**
	 * Creates a WorkflowProcessEvent
	 * 
	 * @param source the sender
	 * @param instance the process
	 * @param type the event type
	 */
	public WorkflowProcessEvent(Object source, WorkflowProcess instance, WorkflowProcessEventType type) {
		this(source, instance, instance.getRootToken(), type);
	}
	
	/**
	 * Creates a WorkflowProcessEvent using the specified process and token
	 * 
	 * @param instance the process
	 * @param token the token
	 * @param type the event type
	 */
	public WorkflowProcessEvent(WorkflowProcess instance, Token token, WorkflowProcessEventType type) {
		this(null, instance, token, type);
	}
	
	/**
	 * Creates a WorkflowProcessEvent using the specified process and token
	 * 
	 * @param source the event sender
	 * @param instance the process
	 * @param token the token
	 * @param type the event type
	 */
	public WorkflowProcessEvent(Object source, WorkflowProcess instance, Token token, 
			WorkflowProcessEventType type) {
		super(source);
		this.process = instance;
		this.token = token;
		this.type = type;
	}
	
	/**
	 * @return Returns the instance.
	 */
	public WorkflowProcess getProcess() {
		return this.process;
	}

	/**
	 * @return Returns the token.
	 */
	public Token getToken() {
		return this.token;
	}

	/**
	 * @return Returns the type of the event
	 */
	public WorkflowProcessEventType getType() {
		return this.type;
	}
}
