//----------------------------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.event;

import org.huihoo.workflow.WorkflowComponent;
import org.huihoo.workflow.WorkflowSimpleComponent;

public class WorkflowEvent extends EventObject
{
	/**
	 * The event's id.
	 */
	protected int id;

	/**
	 * The input event's Time stamp in UTC format.  The time stamp 
	 * indicates when the input event was created.
	 *
	 * @see #getWhen()
	 */
	protected long when;

	/**
	 * Constructs a prototypical Event.
	 *
	 * @param    source    The object on which the Event initially occurred.
	 * @param    type      The event type
	 * @param    when      the time the event occurred
	 */
	public WorkflowEvent(WorkflowComponent source, int id)
	{
		this(source, id, System.currentTimeMillis());
	}

	public WorkflowEvent(WorkflowComponent source, int id, long when)
	{
		super(source);
		this.id = id;
		this.when = when;
	}

	/**
	 * The event type on which the Event initially occurred.
	 *
	 * @return   The event type by which the Event initially occurred.
	 */
	public int getID()
	{
		return id;
	}

	/**
	 * Returns the timestamp of when this event occurred.
	 */
	public long getWhen()
	{
		return when;
	}

	/**
	 * Returns a String representation of this EventObject.
	 *
	 * @return  A a String representation of this EventObject.
	 */
	public String toString()
	{
		String srcName = null;
		if (source instanceof WorkflowSimpleComponent)
		{
			srcName = ((WorkflowSimpleComponent) source).getName();
		}
		
		StringBuffer sb = new StringBuffer();
		sb.append(getClass().getName());
		sb.append("<" + paramString() + ">  on ");
		sb.append(srcName != null ? (Object)srcName : (Object)source);
		return sb.toString();
	}

	/**
	 * Returns a string representing the state of this <code>Event</code>.
	 * This method is intended to be used only for debugging purposes, and the 
	 * content and format of the returned string may vary between 
	 * implementations. The returned string may be empty but may not be 
	 * <code>null</code>.
	 * 
	 * @return  a string representation of this event
	 */
	protected String paramString()
	{
		return "";
	}
}
