原创作者: chenjin   阅读:5372次   评论:2条   更新时间:2011-05-26    
好像源代码功能有点问题.

/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jbpm.jpdl.patterns;

import junit.framework.*;

import org.jbpm.graph.def.*;
import org.jbpm.graph.exe.*;

/**
 * http://is.tm.tue.nl/research/patterns/download/swf/pat_5.swf
 *
 * <p>in jbpm every node has an implicit merge in front of it.
 * so it's not necessary to use the merge node.  in fact, i can
 * not think of a situation where implicit merge nodeMap are not
 * sufficient.  for the sake of workflow patterns, we leave if in.
 * jbpm supports merging of both alternative paths of execution
 * and concurrent paths of execution.
 * </p>
 *
 * <p>first the merge node is demonstrated exactly as in the pattern.
 * then the implicit variant is demonstrated, then the merging of
 * concurrent paths is demonstrated.
 * </p>
 */
public class Wfp05SimpleMergeTest extends TestCase {

  private static ProcessDefinition simpleMergeProcessDefinition = createSimpleMergeProcessDefinition();
 
  public static ProcessDefinition createSimpleMergeProcessDefinition() {
    ProcessDefinition pd = new ProcessDefinition(
      new String[]{"start-state start",
                   "state a",
                   "state b",
                   "merge xor",
                   "state c"},
      new String[]{"start --to a--> a",
                   "start --to b--> b",
                   "a --> xor",
                   "b --> xor",
                   "xor --> c"});
    return pd;
  }

  public void testSimpleMergeScenario1() {
    ProcessDefinition pd = simpleMergeProcessDefinition;
    ProcessInstance pi = new ProcessInstance( pd );
    pi.signal("to a");
    Token root = pi.getRootToken();
    assertSame( pd.getNode("a"), root.getNode() );
    root.signal();
    assertSame( pd.getNode("c"), root.getNode() );
  }

  public void testSimpleMergeScenario2() {
    ProcessDefinition pd = simpleMergeProcessDefinition;
    ProcessInstance pi = new ProcessInstance( pd );
    pi.signal("to b");
    Token root = pi.getRootToken();
    assertSame( pd.getNode("b"), root.getNode() );
    root.signal();
    assertSame( pd.getNode("c"), root.getNode() );
  }
 
  private static ProcessDefinition implicitMergeProcessDefinition = createImplicitMergeProcessDefinition();
 
  public static ProcessDefinition createImplicitMergeProcessDefinition() {
    ProcessDefinition pd = new ProcessDefinition(
      new String[]{"start-state start",
                   "state a",
                   "state b",
                   "state c"},
      new String[]{"start --to a--> a",
                   "start --to b--> b",
                   "a --> c",
                   "b --> c"});
    return pd;
  }

  public void testImplicitMergeScenario1() {
    ProcessDefinition pd = implicitMergeProcessDefinition;
    ProcessInstance pi = new ProcessInstance( implicitMergeProcessDefinition );
    pi.signal("to a");
    Token root = pi.getRootToken();
    assertSame( pd.getNode("a"), root.getNode() );
    root.signal();
    assertSame( pd.getNode("c"), root.getNode() );
  }
 
  public void testImplicitMergeScenario2() {
    ProcessDefinition pd = implicitMergeProcessDefinition;
    ProcessInstance pi = new ProcessInstance( implicitMergeProcessDefinition );
    pi.signal("to b");
    Token root = pi.getRootToken();
    assertSame( pd.getNode("b"), root.getNode() );
    root.signal();
    assertSame( pd.getNode("c"), root.getNode() );
  }
 
}

createSimpleMergeProcessDefinition()

创建如下流程定义文件

xml 代码
 
  1. <process-definition name="process">  
  2.     <start-state name='start'>  
  3.         <transition name='to a' to='a' />  
  4.         <transition name='to b' to='b' />  
  5.     </start-state>  
  6.     <state name='a'>  
  7.         <transition to='xor' />  
  8.     </state>  
  9.     <state name='b'>  
  10.         <transition to='xor' />  
  11.     </state>  
  12.     <state name='xor'>  
  13.         <transition to='c' />  
  14.     </state>  
  15.     <state name='c' />  
  16. </process-definition>  


testSimpleMergeScenario1()

节点执行顺序
   
    start --> a --> xor --> c

testSimpleMergeScenario2()
 
    start --> b --> xor --> c

createImplicitMergeProcessDefinition()

创建如下流程定义文件

xml 代码
 
  1. <process-definition name="process">  
  2.     <start-state name='start'>  
  3.         <transition name='to a' to='a' />  
  4.         <transition name='to b' to='b' />  
  5.     </start-state>  
  6.     <state name='a'>  
  7.         <transition to='c' />  
  8.     </state>  
  9.     <state name='b'>  
  10.         <transition to='c' />  
  11.     </state>  
  12.     <state name='c' />  
  13. </process-definition>  


testImplicitMergeScenario1()
节点执行顺序

  start --> a --> c

testImplicitMergeScenario2()
节点执行顺序

  start --> b --> c



以上是对基本控制流程的一些说明, 本人水平有限, 难免有不当之处. 欢迎批评指正.
评论 共 2 条 请登录后发表评论
2 楼 DistantSaviour 2013-01-03 23:15
看不懂啊,能否介绍下
1 楼 xuebaoyang 2009-07-13 11:50

发表评论

您还没有登录,请您登录后再发表评论

文章信息

Global site tag (gtag.js) - Google Analytics