基础管理 > 支持协作 > 工作流管理 > 工作流工具 > 工作流模板管理 > 工作流代码示例 > 同步自动机示例 > 根据同属子进程进行同步
  
根据同属子进程进行同步
本主题提供了这样一个示例,即“同步”自动机节点监听父进程中子进程的活动状态更改。
参考工作流
SynchronizingOnSiblingSubProcess.xml
SiblingSubProcess.xml
说明
下列表达式供监听由已分配活动激发的 ACTIVITY_STATE_CHANGED 事件的自动机使用。该表达式用于审查激发了事件的活动节点是否属于“同步”自动机节点所属父工作流模板的一个子进程。如果是,则根据该活动节点的状态来激发相应的路由事件。
指示
本例中的自动机监听 ACTIVITY_STATE_CHANGED 事件,它监听的 Wndchill 类是 wt.workflow.work.WfAssignedActivity。
本示例假定该活动属于第一层级进程,即不存在于嵌套子进程中。可以跟踪此类活动,但这要求自动机了解嵌套子进程的结构。
复制下列代码:
//Get the Activity that generated the event
wt.workflow.engine.WfActivity activity = (( wt.workflow.engine.WfActivity ) (((wt.events.KeyedEvent)event).getEventTarget()));
//Get the sub process that the Activity belongs to
wt.workflow.engine.WfProcess subProcess = activity.getParentProcess();
//Get the Parent of that sub process
wt.workflow.engine.WfProcess activityParentProcess = (( wt.workflow.engine.WfActivity ) subProcess.getRequester( )). getParentProcess( );
//Get the parent process of the Synch robot that has this expression
wt.workflow.engine.WfProcess myParentProcess = ( wt.workflow.engine.WfProcess ) self.getObject( );
//If the object IDs of the parent of the activity and the parent of the Synch Robot are the same,check for the state of the activity.
if ( wt.fc.PersistenceHelper.isEquivalent(activityParentProcess , myParentProcess )){
//If the Activity has been executed, set result to "completed" and if it has been terminated, setresult to "terminated". Else wait //for a state change.
if ( wt.workflow.engine.WfState.CLOSED_COMPLETED_EXECUTED.equals(activity.getState( ))){
result= "completed";
}
else if ( wt.workflow.engine.WfState.CLOSED_TERMINATED.equals(activity.getState( ))){
result= "terminated";
}
}