//----------------------------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.impl.store.spi;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.huihoo.workflow.WorkflowException;
import org.huihoo.workflow.store.persistent.UserTransaction;
import org.huihoo.workflow.store.spi.AbstractSpiWorkflowDispatcher;
import org.huihoo.workflow.store.spi.SpiCaseDatabase;
import org.huihoo.workflow.usermodel.WorkflowParticipant;
import org.huihoo.workflow.runtime.WorkflowService;
import org.huihoo.workflow.runtime.WorkflowWork;
import org.huihoo.workflow.xpdl.WorkflowActivity;
import org.huihoo.workflow.xpdl.WorkflowPackage;
import org.huihoo.workflow.xpdl.WorkflowProcess;
import org.huihoo.workflow.impl.store.CaseDatabaseImpl;
import org.huihoo.workflow.impl.store.util.DispatchController;
/**
* @author zosatapo
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class SpiWorkflowDispatcherImpl extends AbstractSpiWorkflowDispatcher
{
private static Log log = LogFactory.getLog(SpiWorkflowDispatcherImpl.class);
public SpiWorkflowDispatcherImpl()
{
}
public SpiWorkflowDispatcherImpl(SpiCaseDatabase caseDatabase)
{
super(caseDatabase);
}
public boolean accept(WorkflowProcess workflowProcess,WorkflowParticipant operator, WorkflowWork workItem) throws WorkflowException
{
log.debug("[accept] workitem: " + workItem);
WorkflowActivity workflowActivity = workItem.getWorkflowActivity();
WorkflowPackage workflowPackage = workflowProcess.getWorkflowPackage();
WorkflowService workflowService=getCaseDatabase().getWorkflowService();
CaseDatabaseImpl caseDatabase =(CaseDatabaseImpl) workflowService.getCaseDatabase();
UserTransaction userTransaction = caseDatabase.getUserTransaction();
boolean resultDone = false;
try
{
resultDone = DispatchController.accept_core(workflowService,workflowProcess,operator, caseDatabase.getWrappedObject(), userTransaction, workItem);
userTransaction.commit();
}
catch (WorkflowException ex)
{
log.error(ex);
userTransaction.rollback();
throw ex;
}
finally
{
userTransaction.release();
}
return resultDone;
}
public boolean dispatch(WorkflowProcess workflowProcess,WorkflowParticipant operator, WorkflowWork workItem) throws WorkflowException
{
log.info("[dispatch] workitem: " + workItem );
WorkflowActivity workflowActivity = workItem.getWorkflowActivity();
WorkflowPackage workflowPackage = workflowProcess.getWorkflowPackage();
WorkflowService workflowService=getCaseDatabase().getWorkflowService();
CaseDatabaseImpl caseDatabase =(CaseDatabaseImpl) workflowService.getCaseDatabase();
UserTransaction userTransaction = caseDatabase.getUserTransaction();
boolean resultDone = false;
try
{
resultDone = DispatchController.dispatch_core(workflowService,workflowProcess,operator, caseDatabase.getWrappedObject(), userTransaction, workItem);
userTransaction.commit();
}
catch (Exception wfsex)
{
log.error(wfsex, wfsex);
userTransaction.rollback();
throw new WorkflowException(wfsex);
}
finally
{
userTransaction.release();
}
return resultDone;
}
public boolean revert(WorkflowProcess workflowProcess,WorkflowParticipant operator, WorkflowWork workItem) throws WorkflowException
{
log.debug("[revert] workitem: " + workItem );
WorkflowActivity workflowActivity = workItem.getWorkflowActivity();
WorkflowPackage workflowPackage = workflowProcess.getWorkflowPackage();
WorkflowService workflowService=getCaseDatabase().getWorkflowService();
CaseDatabaseImpl caseDatabase =(CaseDatabaseImpl) workflowService.getCaseDatabase();
UserTransaction userTransaction = caseDatabase.getUserTransaction();
boolean resultDone = false;
try
{
resultDone = DispatchController.revert_core(workflowService,workflowProcess,operator, caseDatabase.getWrappedObject(), userTransaction, workItem);
userTransaction.commit();
}
catch (WorkflowException ex)
{
log.error(ex, ex);
userTransaction.rollback();
throw ex;
}
finally
{
userTransaction.release();
}
return resultDone;
}
public boolean fetch(WorkflowProcess workflowProcess,WorkflowParticipant operator, WorkflowWork workItem) throws WorkflowException
{
log.debug("[fetch] workitem: " + workItem );
WorkflowActivity workflowActivity = workItem.getWorkflowActivity();
WorkflowPackage workflowPackage = workflowProcess.getWorkflowPackage();
WorkflowService workflowService=getCaseDatabase().getWorkflowService();
CaseDatabaseImpl caseDatabase =(CaseDatabaseImpl) workflowService.getCaseDatabase();
UserTransaction userTransaction = caseDatabase.getUserTransaction();
boolean resultDone = false;
try
{
resultDone = DispatchController.fetch_core(workflowService,workflowProcess,operator, caseDatabase.getWrappedObject(), userTransaction, workItem);
userTransaction.commit();
}
catch (WorkflowException ex)
{
log.error(ex, ex);
userTransaction.rollback();
throw ex;
}
finally
{
userTransaction.release();
}
return resultDone;
}
}