[jbpm-commits] JBoss JBPM SVN: r3376 - in jbpm4/trunk/modules: api/src/main/resources and 13 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Dec 13 06:40:50 EST 2008


Author: tom.baeyens at jboss.com
Date: 2008-12-13 06:40:49 -0500 (Sat, 13 Dec 2008)
New Revision: 3376

Added:
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/graphbased/
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/graphbased/ConcurrencyGraphBasedTest.java
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/graphbased/
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/graphbased/process.jpdl.xml
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ForkActivity.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/JoinActivity.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/ForkBinding.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/JoinBinding.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionsCmd.java
Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
   jbpm4/trunk/modules/api/src/main/resources/jpdl.xsd
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/exclusive/conditions/process.jpdl.xml
   jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml
   jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
Log:
added fork and join

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2008-12-12 16:28:54 UTC (rev 3375)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -21,6 +21,7 @@
  */
 package org.jbpm;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -85,6 +86,8 @@
   /** the execution that is uniquely defined by the process definition and the business key. */
   Execution findExecution(String executionId);
 
+  /** this method returns this execution and all its child executions recursively. */
+  List<Execution> findExecutions(String executionId);
   
   /** provides an external trigger to an execution. */
   Execution signalExecutionById(String executionId);
@@ -131,4 +134,5 @@
 
   /** delete a process instance */
   void deleteProcessInstance(String processInstanceId);
+
 }

Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl.xsd	2008-12-12 16:28:54 UTC (rev 3375)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl.xsd	2008-12-13 11:40:49 UTC (rev 3376)
@@ -35,19 +35,13 @@
   </annotation>
 
   <!-- ### PROCESS DEFINITION ############################################# -->
-  
+
   <element name="process">
     <annotation><documentation>A jPDL process definition description; This 
     is the top level element in a jPDL process file.</documentation></annotation>
     <complexType>
       <sequence minOccurs="0" maxOccurs="unbounded">
         <group ref="tns:activityGroup" minOccurs="0" maxOccurs="unbounded" />
-        <!-- 
-          <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-          <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-          </element>
-          <element ref="tns:timer" minOccurs="0" maxOccurs="unbounded"/>
-        -->
       </sequence>
       <attribute name="name" use="required" type="string">
         <annotation>
@@ -91,9 +85,6 @@
         <complexType>
           <sequence>
             <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
-            <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-              <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-            </element>
           </sequence>
           <attributeGroup ref="tns:nodeAttributes" />
         </complexType>
@@ -105,9 +96,6 @@
         </documentation></annotation>
         <complexType>
           <sequence>
-            <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-              <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-            </element>
           </sequence>
           <attributeGroup ref="tns:nodeAttributes" />
           <attribute name="ends" default="process-instance">
@@ -133,12 +121,6 @@
         <complexType>
           <sequence>
             <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
-            <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-              <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-            </element>
-            <!-- 
-            <element ref="tns:timer" minOccurs="0" maxOccurs="unbounded"/>
-            -->
           </sequence>
           <attributeGroup ref="tns:nodeAttributes" />
         </complexType>
@@ -146,23 +128,40 @@
 
       <!-- ~~~ EXCLUSIVE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
       <element name="exclusive">
-        <annotation><documentation>Exclusive gayteway: selects one path out of many alternatives.  
+        <annotation><documentation>Exclusive gateway: selects one path out of many alternatives.  
         When an execution comes in, exactly one outgoing flow is taken.
         </documentation></annotation>
         <complexType>
           <sequence>
-            <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded">
+            <element name="flow" minOccurs="0" maxOccurs="unbounded">
+              <complexType>
+                <complexContent>
+                  <extension base="tns:flowType">
+                    <sequence>
+                      <element name="condition" minOccurs="0" maxOccurs="unbounded">
+                        <complexType>
+                          <attribute name="expr" type="string">
+                            <annotation><documentation>The script text that will be evaluated.  This 
+                            is mutually exclusive with the expression element.
+                            </documentation></annotation>
+                          </attribute>
+                          <attribute name="lang" type="string">
+                            <annotation><documentation>Identification of the scripting language 
+                            to use.</documentation></annotation>
+                          </attribute>
+                        </complexType>
+                      </element>
+                    </sequence>
+                  </extension>
+                </complexContent>
+              </complexType>
               <!-- TODO add conditions -->
             </element>
-            <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-              <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-            </element>
           </sequence>
           <attributeGroup ref="tns:nodeAttributes" />
         </complexType>
       </element>
-    
-      <!-- 
+
       <element name="fork">
         <annotation><documentation>Spawns multiple concurrent paths of 
         execution.
@@ -170,9 +169,6 @@
         <complexType>
           <sequence>
             <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
-            <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-              <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-            </element>
           </sequence>
           <attributeGroup ref="tns:nodeAttributes" />
         </complexType>
@@ -185,14 +181,59 @@
         <complexType>
           <sequence>
             <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
-            <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-              <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-            </element>
           </sequence>
           <attributeGroup ref="tns:nodeAttributes" />
         </complexType>
       </element>
-    
+
+      <element name="script">
+        <annotation><documentation>Evaluates a piece of text as a script
+        </documentation></annotation>
+        <complexType>
+          <complexContent>
+            <extension base="tns:scriptType">
+              <sequence>
+                <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
+              </sequence>
+              <attributeGroup ref="tns:nodeAttributes" />
+            </extension>
+          </complexContent>
+        </complexType>
+      </element>
+
+      <element name="java">
+        <annotation><documentation>Instantiates java class with reflection, inject 
+        values from the environment in the fields and execute a method.
+        </documentation></annotation>
+        <complexType>
+          <complexContent>
+            <extension base="tns:javaType">
+              <sequence>
+                <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
+              </sequence>
+              <attributeGroup ref="tns:nodeAttributes" />
+            </extension>
+          </complexContent>
+        </complexType>
+      </element>
+      
+      <element name="java-ref">
+        <annotation><documentation>Invokes a method on a java object in the 
+        environment.
+        </documentation></annotation>
+        <complexType>
+          <complexContent>
+            <extension base="tns:javaRefType">
+              <sequence>
+                <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
+              </sequence>
+              <attributeGroup ref="tns:nodeAttributes" />
+            </extension>
+          </complexContent>
+        </complexType>
+      </element>
+
+      <!-- 
       <element name="process-state">
         <annotation><documentation>Waits while a sub process instance is 
         being executed and continues when the sub process instance ends.
@@ -246,42 +287,6 @@
         </complexType>
       </element>
       
-      <element name="invoke">
-        <annotation><documentation>Invokes a method on a java object
-        </documentation></annotation>
-        <complexType>
-          <complexContent>
-            <extension base="tns:invokeType">
-              <sequence>
-                <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
-                <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-                  <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-                </element>
-              </sequence>
-              <attributeGroup ref="tns:nodeAttributes" />
-            </extension>
-          </complexContent>
-        </complexType>
-      </element>
-      
-      <element name="script">
-        <annotation><documentation>Evaluates a piece of text as a script
-        </documentation></annotation>
-        <complexType>
-          <complexContent>
-            <extension base="tns:scriptType">
-              <sequence>
-                <element ref="tns:flow" minOccurs="0" maxOccurs="unbounded" />
-                <element ref="tns:on" minOccurs="0" maxOccurs="unbounded">
-                  <annotation><documentation>Events on which listeners can be registered.</documentation></annotation>
-                </element>
-              </sequence>
-              <attributeGroup ref="tns:nodeAttributes" />
-            </extension>
-          </complexContent>
-        </complexType>
-      </element>
-      
       <element name="email">
         <annotation><documentation>Sends an email
         </documentation></annotation>
@@ -322,6 +327,59 @@
     </choice>
   </group>
 
+  <complexType name="scriptType">
+    <sequence>
+      <element name="expr" type="string">
+        <annotation><documentation>The content of this expression element 
+        is the script text that will be evaluated.  This is mutually 
+        exclusive with the expression attribute.</documentation></annotation>
+      </element>
+    </sequence>
+    <attribute name="expr" type="string">
+      <annotation><documentation>The script text that will be evaluated.  This 
+      is mutually exclusive with the expression element.
+      </documentation></annotation>
+    </attribute>
+    <attribute name="lang" type="string">
+      <annotation><documentation>Identification of the scripting language 
+      to use.</documentation></annotation>
+    </attribute>
+  </complexType>
+  
+  <complexType name="javaType">
+    <sequence>
+      <element name="field" minOccurs="0" maxOccurs="unbounded">
+        <annotation><documentation>Field injections from the environment 
+        invocation.</documentation></annotation>
+      </element>
+    </sequence>
+    <attribute name="method" type="string" use="required">
+      <annotation><documentation>The name of the method to invoke.
+      </documentation></annotation>
+    </attribute>
+    <attribute name="class" type="string">
+      <annotation><documentation>The class to use.
+      </documentation></annotation>
+    </attribute>
+  </complexType>
+
+  <complexType name="javaRefType">
+    <sequence>
+      <element name="arg" minOccurs="0" maxOccurs="unbounded">
+        <annotation><documentation>Arguments passed into the method 
+        invocation.</documentation></annotation>
+      </element>
+    </sequence>
+    <attribute name="method" type="string" use="required">
+      <annotation><documentation>The name of the method to invoke.
+      </documentation></annotation>
+    </attribute>
+    <attribute name="object" type="string">
+      <annotation><documentation>The name of the object in the environment to use.
+      </documentation></annotation>
+    </attribute>
+  </complexType>
+
   <attributeGroup name="nodeAttributes">
     <attribute name="name" type="string">
       <annotation><documentation>The id of this activity.  The name should be unique
@@ -419,46 +477,6 @@
     </choice>
   </group>
 
-  <group name="delegationGroup">
-    <choice>
-      <element name="object">
-        <annotation><documentation>A java object that will be obtained by using 
-        the constructor through reflection or through a factory method.</documentation></annotation>
-        <complexType>
-          <attribute name="class" type="string" />
-        </complexType>
-      </element>
-      <element name="jndi">
-        <complexType>
-          <attribute name="name" type="string" />
-        </complexType>
-      </element>
-      <element name="expr">
-        <complexType>
-          <attribute name="text" type="string" use="required"/>
-          <attribute name="language" type="string" />
-        </complexType>
-      </element>
-    </choice>
-  </group>
-  
-  <complexType name="invokeType">
-    <sequence>
-      <group ref="tns:delegationGroup">
-        <annotation><documentation>The object on which the method 
-        will be invoked</documentation></annotation>
-      </group>
-      <element name="arg" minOccurs="0" maxOccurs="unbounded">
-        <annotation><documentation>Arguments passed into the method 
-        invocation.</documentation></annotation>
-      </element>
-    </sequence>
-    <attribute name="method" type="string" use="required">
-      <annotation><documentation>The name of the method to invoke.
-      </documentation></annotation>
-    </attribute>
-  </complexType>
-
   <complexType name="scriptType">
     <sequence>
       <element name="expr" type="string">

Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/graphbased/ConcurrencyGraphBasedTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/graphbased/ConcurrencyGraphBasedTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/graphbased/ConcurrencyGraphBasedTest.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -0,0 +1,77 @@
+/*
+ * 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.examples.concurrency.graphbased;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.Execution;
+import org.jbpm.test.DbTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ConcurrencyGraphBasedTest extends DbTestCase {
+
+  public void testConcurrencyGraphBased() {
+    deployJpdlResource("org/jbpm/examples/concurrency/graphbased/process.jpdl.xml");
+    
+    Execution processInstance = executionService.startExecutionByKey("ConcurrencyGraphBased");
+
+    List<Execution> executions = executionService.findExecutions(processInstance.getId());
+    Map<String, Execution> executionNodesMap = getExecutionsNodesMap(executions);
+    
+    Set<String> nodeNames = new HashSet<String>(executionNodesMap.keySet());
+    Set<String> expectedNodeNames = new HashSet<String>();
+    expectedNodeNames.add("fork");
+    expectedNodeNames.add("send invoice");
+    expectedNodeNames.add("load truck");
+    expectedNodeNames.add("print shipping documents");
+    
+    assertEquals(expectedNodeNames, nodeNames);
+    assertFalse(executionNodesMap.get("fork").isActive());
+    assertTrue(executionNodesMap.get("load truck").isActive());
+    assertTrue(executionNodesMap.get("print shipping documents").isActive());
+    
+    Execution sendInvoiceExecution = executionNodesMap.get("send invoice");
+    assertTrue(sendInvoiceExecution.isActive());
+    
+    /*
+
+    executionService.signalExecutionById(sendInvoiceExecution.getId());
+
+    executions = executionService.findExecutions(processInstance.getId());
+    executionNodesMap = getExecutionsNodesMap(executions);
+
+    expectedNodeNames.remove("send invoice");
+
+    assertEquals(expectedNodeNames, nodeNames);
+    assertFalse(executionNodesMap.get("fork").isActive());
+    assertTrue(executionNodesMap.get("load truck").isActive());
+    assertTrue(executionNodesMap.get("print shipping documents").isActive());
+    */
+  }
+
+}


Property changes on: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/graphbased/ConcurrencyGraphBasedTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/graphbased/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/graphbased/process.jpdl.xml	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/graphbased/process.jpdl.xml	2008-12-13 11:40:49 UTC (rev 3376)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process name="ConcurrencyGraphBased" xmlns="http://jbpm.org/4/jpdl">
+
+  <start>
+    <flow to="fork" />
+  </start>
+
+  <fork name="fork">
+    <flow to="send invoice" />
+    <flow to="load truck" />
+    <flow to="print shipping documents" />
+  </fork>
+
+  <state name="send invoice">
+    <flow to="final join" />
+  </state>
+
+  <state name="load truck">
+    <flow to="intermediate join" />
+  </state>
+
+  <state name="print shipping documents">
+    <flow to="intermediate join" />
+  </state>
+  
+  <join name="intermediate join">
+    <flow to="drive truck to destination" />
+  </join>
+
+  <state name="drive truck to destination">
+    <flow to="final join" />
+  </state>
+
+  <join name="final join">
+    <flow to="end" />
+  </join>
+
+  <end name="end" />
+
+</process>


Property changes on: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/graphbased/process.jpdl.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/exclusive/conditions/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/exclusive/conditions/process.jpdl.xml	2008-12-12 16:28:54 UTC (rev 3375)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/exclusive/conditions/process.jpdl.xml	2008-12-13 11:40:49 UTC (rev 3376)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8" xmlns="http://jbpm.org/4/jpdl"?>
 
 <process name="ExclusiveConditions" >
 

Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ForkActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ForkActivity.java	                        (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ForkActivity.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -0,0 +1,53 @@
+/*
+ * 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.activity;
+
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.model.Node;
+import org.jbpm.model.Transition;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ForkActivity extends JpdlActivity {
+
+  private static final long serialVersionUID = 1L;
+  
+  public void execute(ActivityExecution execution) throws Exception {
+    Execution processInstance = execution.getProcessInstance();
+    Node node = execution.getNode();
+    List<Transition> outgoingTransitions = node.getOutgoingTransitions();
+
+    // for each outgoing transition
+    for (Transition outgoingTransition: outgoingTransitions) {
+      // launch a concurrent path of execution
+      String childExecutionName = outgoingTransition.getName();
+      // creating the execution will cause the execution to become inactive
+      Execution childExecution = execution.createExecution(childExecutionName, processInstance);
+      execution.take(outgoingTransition, childExecution);
+    }
+  }
+}


Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ForkActivity.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/JoinActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/JoinActivity.java	                        (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/JoinActivity.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -0,0 +1,100 @@
+/*
+ * 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.activity;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.model.Node;
+import org.jbpm.model.OpenExecution;
+import org.jbpm.model.Transition;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JoinActivity extends JpdlActivity {
+
+  private static final long serialVersionUID = 1L;
+
+  public void execute(ActivityExecution execution) throws Exception {
+    // end the child execution execution
+    // this will also remove the execution from it's parent
+    execution.end();
+    
+    Node join = execution.getNode();
+    List<OpenExecution> joinedExecutions = findJoinedExecutions(execution, join);
+    
+    if (isComplete(joinedExecutions, join)) {
+      removeJoinedExecutions(joinedExecutions, execution);
+
+      OpenExecution processInstance = execution.getProcessInstance();
+      
+      Execution outgoingExecution = null;
+      if ( processInstance.getExecutions()==null
+           || processInstance.getExecutions().isEmpty() 
+         ) {
+        outgoingExecution = processInstance;
+      } else {
+        outgoingExecution = execution.createExecution(processInstance);
+      }
+      
+      execution.move(join, outgoingExecution);
+      Transition transition = join.getDefaultTransition();
+      execution.take(transition, outgoingExecution);
+    }
+  }
+  
+  List<OpenExecution> findJoinedExecutions(OpenExecution execution, Node join) {
+    List<OpenExecution> joinedExecutions = new ArrayList<OpenExecution>();
+    scanRecursive(execution.getProcessInstance(), join, joinedExecutions);
+    return joinedExecutions;
+  }
+
+  void scanRecursive(OpenExecution execution, Node join, List<OpenExecution> joinedExecutions) {
+    // if the execution is positioned in the join
+    if (join.equals(execution.getNode())) {
+      joinedExecutions.add(execution);
+    }
+    Collection<OpenExecution> childExecutions = execution.getExecutions();
+    if (childExecutions!=null) {
+      for (OpenExecution childExecution: childExecutions) {
+        scanRecursive(childExecution, join, joinedExecutions);
+      }
+    }
+  }
+
+  boolean isComplete(List<OpenExecution> joinedExecutions, Node join) {
+    int executionsToJoin = join.getIncomingTransitions().size();
+    return (executionsToJoin==joinedExecutions.size());
+  }
+
+  void removeJoinedExecutions(List<OpenExecution> joinedExecutions, ActivityExecution execution) {
+    for (OpenExecution joinedExecution: joinedExecutions) {
+      execution.removeExecution(joinedExecution, joinedExecution.getParent());
+    }
+  }
+
+}


Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/JoinActivity.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/ForkBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/ForkBinding.java	                        (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/ForkBinding.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -0,0 +1,43 @@
+/*
+ * 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.xml;
+
+import org.jbpm.jpdl.activity.ForkActivity;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ForkBinding extends JpdlActivityBinding {
+
+  public ForkBinding() {
+    super("fork");
+  }
+
+  public Object parse(Element element, Parse parse, Parser parser) {
+    return new ForkActivity();
+  }
+
+}


Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/ForkBinding.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/JoinBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/JoinBinding.java	                        (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/JoinBinding.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -0,0 +1,43 @@
+/*
+ * 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.xml;
+
+import org.jbpm.jpdl.activity.JoinActivity;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class JoinBinding extends JpdlActivityBinding {
+
+  public JoinBinding() {
+    super("join");
+  }
+
+  public Object parse(Element element, Parse parse, Parser parser) {
+    return new JoinActivity();
+  }
+
+}


Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/xml/JoinBinding.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml	2008-12-12 16:28:54 UTC (rev 3375)
+++ jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml	2008-12-13 11:40:49 UTC (rev 3376)
@@ -4,4 +4,6 @@
   <activity binding="org.jbpm.jpdl.xml.StateBinding" />
   <activity binding="org.jbpm.jpdl.xml.ExclusiveBinding" />
   <activity binding="org.jbpm.jpdl.xml.EndBinding" />
+  <activity binding="org.jbpm.jpdl.xml.ForkBinding" />
+  <activity binding="org.jbpm.jpdl.xml.JoinBinding" />
 </activities>

Modified: jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml	2008-12-12 16:28:54 UTC (rev 3375)
+++ jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml	2008-12-13 11:40:49 UTC (rev 3376)
@@ -36,6 +36,8 @@
       <property name="endProcessInstance" column="ENDPI_" />
       <property name="state" column="TEXT_" />
     </subclass>
+    <subclass name="org.jbpm.jpdl.activity.ForkActivity" discriminator-value="fork" />
+    <subclass name="org.jbpm.jpdl.activity.JoinActivity" discriminator-value="join" />
   </class>
 
 </hibernate-mapping>
\ No newline at end of file

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionCmd.java	2008-12-12 16:28:54 UTC (rev 3375)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionCmd.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -25,7 +25,6 @@
 import org.jbpm.JbpmException;
 import org.jbpm.cmd.Command;
 import org.jbpm.env.Environment;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.session.PvmDbSession;
 
 

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionsCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionsCmd.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionsCmd.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -0,0 +1,79 @@
+/*
+ * 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.pvm.internal.cmd;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.JbpmException;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.model.OpenExecution;
+import org.jbpm.session.PvmDbSession;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class FindExecutionsCmd implements Command<List<Execution>> {
+
+  private static final long serialVersionUID = 1L;
+  
+  protected String executionId;
+
+  public FindExecutionsCmd(String executionId) {
+    if (executionId==null) {
+      throw new JbpmException("executionId is null");
+    }
+    this.executionId = executionId;
+  }
+
+
+  public List<Execution> execute(Environment environment) throws Exception {
+    List<Execution> executions = new ArrayList<Execution>();
+    
+    PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
+    ClientExecution execution = pvmDbSession.findExecutionById(executionId);
+    scanExecutions(execution, executions);
+    
+    return executions;
+  }
+
+  public void scanExecutions(OpenExecution execution, List<Execution> executions) {
+
+    executions.add(execution);
+    
+    // initialize node relation.  this is necessary for the method  
+    // Execution.getNodeName()
+    execution.getNode().getName();
+    
+    Collection<OpenExecution> childExecutions = execution.getExecutions();
+    if (childExecutions!=null) {
+      for (OpenExecution childExecution: childExecutions) {
+        scanExecutions(childExecution, executions);
+      }
+    }
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindExecutionsCmd.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2008-12-12 16:28:54 UTC (rev 3375)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -22,6 +22,7 @@
 package org.jbpm.pvm.internal.svc;
 
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -30,6 +31,7 @@
 import org.jbpm.ExecutionService;
 import org.jbpm.cmd.CommandService;
 import org.jbpm.pvm.internal.cmd.DeleteProcessInstance;
+import org.jbpm.pvm.internal.cmd.FindExecutionsCmd;
 import org.jbpm.pvm.internal.cmd.FindExecutionCmd;
 import org.jbpm.pvm.internal.cmd.GetVariableNamesCmd;
 import org.jbpm.pvm.internal.cmd.GetVariablesCmd;
@@ -125,6 +127,10 @@
     return commandService.execute(new FindExecutionCmd(executionId));
   }
   
+  public List<Execution> findExecutions(String executionId) {
+    return commandService.execute(new FindExecutionsCmd(executionId));
+  }
+
   public ExecutionQuery createExecutionQuery() {
     return new ExecutionQueryImpl(commandService);
   }

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java	2008-12-12 16:28:54 UTC (rev 3375)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/DbTestCase.java	2008-12-13 11:40:49 UTC (rev 3376)
@@ -22,9 +22,12 @@
 package org.jbpm.test;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.jbpm.Configuration;
+import org.jbpm.Execution;
 import org.jbpm.ExecutionService;
 import org.jbpm.ManagementService;
 import org.jbpm.ProcessDefinition;
@@ -134,4 +137,14 @@
 
     taskService.saveTask(task);
   }
+
+  public Map<String, Execution> getExecutionsNodesMap(List<Execution> executions) {
+    Map<String,Execution> executionsMap = new HashMap<String, Execution>();
+    
+    for (Execution execution: executions) {
+      executionsMap.put(execution.getNodeName(), execution);
+    }
+    
+    return executionsMap;
+  }
 }




More information about the jbpm-commits mailing list