/**
 * GetTokenIdAction.java
 * Created on Jun 20, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.action;

import org.apache.log4j.Logger;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

/**
 * This class sets the 'tokenId' variable for the current process.
 * 
 * @author spuranik
 */
public class SetTokenIdAction implements ActionHandler {

	private static final long serialVersionUID = 1L;
	private static final String TOKEN_ID = "tokenId";
	private static final Logger logger = Logger.getLogger(SetTokenIdAction.class);

	/* (non-Javadoc)
	 * @see org.jbpm.graph.def.ActionHandler#execute(org.jbpm.graph.exe.ExecutionContext)
	 */
	public void execute(ExecutionContext context) throws Exception {
		int id = (int)context.getProcessInstance().getRootToken().getId();
		context.setVariable(TOKEN_ID, id);
		logger.debug("Set tokenId to: " + id);
	}

}
