[jbpm-commits] JBoss JBPM SVN: r6093 - in jbpm4/trunk/modules: bpmn/src/main/java/org/jbpm/bpmn/model and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Jan 19 04:57:50 EST 2010


Author: jbarrez
Date: 2010-01-19 04:57:49 -0500 (Tue, 19 Jan 2010)
New Revision: 6093

Added:
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/model/SequenceflowCondition.java
Modified:
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnActivity.java
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExpressionCondition.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/gateway/InclusiveGatewayTest.java
Log:
JBPM-2738: finished implementation/test cases for Inclusive Gateway

Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnActivity.java	2010-01-18 23:27:37 UTC (rev 6092)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnActivity.java	2010-01-19 09:57:49 UTC (rev 6093)
@@ -32,6 +32,7 @@
 import org.jbpm.pvm.internal.model.Activity;
 import org.jbpm.pvm.internal.model.Condition;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ExpressionCondition;
 import org.jbpm.pvm.internal.model.Transition;
 
 /**
@@ -126,7 +127,7 @@
       Condition condition = transition.getCondition();
       if ( ( (condition == null) 
              || (!checkConditions) 
-             || (condition.evaluate(execution))
+             || (condition.evaluate(execution)) 
            ) 
            && (activity.getDefaultOutgoingTransition() != transition)
          ) {

Added: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/model/SequenceflowCondition.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/model/SequenceflowCondition.java	                        (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/model/SequenceflowCondition.java	2010-01-19 09:57:49 UTC (rev 6093)
@@ -0,0 +1,75 @@
+/*
+ * 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.bpmn.model;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.model.OpenExecution;
+import org.jbpm.pvm.internal.model.Condition;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ExpressionCondition;
+
+/**
+ * Specialized {@link Condition} implementation for BPMN 2.0 sequence flow.
+ * 
+ * The difference with the JPDL {@link ExpressionCondition} is that expressions are always
+ * resolved against the given execution, instead of the executionContext in the environment.
+ * 
+ * In some BPMN 2.0 processes, the regular resolving of expressions failed because of 
+ * execution juggling inside activities (see eg. Inclusive Gateway test cases), hence this impl.
+ * 
+ * @author Joram Barrez
+ */
+public class SequenceflowCondition implements Condition {
+  
+  private static final long serialVersionUID = 1L;
+
+  protected String expression;
+  
+  protected String language;
+  
+  public boolean evaluate(OpenExecution execution) {
+    ExecutionImpl executionImpl = (ExecutionImpl) execution;
+    Object result = executionImpl.resolveExpression(expression, language);
+    if (result instanceof Boolean) {
+      return ((Boolean) result).booleanValue();
+    } else {
+      throw new JbpmException("Expression '" + expression + "' did not resolve to a boolean value");
+    }
+  }
+  
+  public String getExpression() {
+    return expression;
+  }
+  
+  public void setExpression(String expression) {
+    this.expression = expression;
+  }
+
+  public String getLanguage() {
+    return language;
+  }
+  
+  public void setLanguage(String language) {
+    this.language = language;
+  }
+
+}

Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java	2010-01-18 23:27:37 UTC (rev 6092)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java	2010-01-19 09:57:49 UTC (rev 6093)
@@ -36,6 +36,7 @@
 import org.jbpm.bpmn.flownodes.BpmnBinding;
 import org.jbpm.bpmn.flownodes.DatabasedGatewayActivity;
 import org.jbpm.bpmn.model.BpmnProcessDefinition;
+import org.jbpm.bpmn.model.SequenceflowCondition;
 import org.jbpm.internal.log.Log;
 import org.jbpm.pvm.internal.model.ActivityImpl;
 import org.jbpm.pvm.internal.model.CompositeElementImpl;
@@ -278,10 +279,10 @@
           String lang = XmlUtil.attribute(conditionElement, "language");
           // TODO: add looking up the default language in the document under definitions if lang  is null.
           
-          ExpressionCondition expressionCondition = new ExpressionCondition();
-          expressionCondition.setExpression(expr);
-          expressionCondition.setLanguage(lang);
-          transition.setCondition(expressionCondition);
+          SequenceflowCondition condition = new SequenceflowCondition();
+          condition.setExpression(expr);
+          condition.setLanguage(lang);
+          transition.setCondition(condition);
 
         } else {
           parse.addProblem("Type of the conditionExpression on sequenceFlow with id=" + 

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2010-01-18 23:27:37 UTC (rev 6092)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2010-01-19 09:57:49 UTC (rev 6093)
@@ -672,6 +672,43 @@
       atomicOperations.offer(operation);
     }
   }
+  
+  /** 
+   * Important: Only use this if resolving an expression on another execution then the current execution
+   * 
+   * TODO: remove this operation once the environment/executionContext is refactored
+   */
+  public Object resolveExpression(String expression, String language) {
+    ExecutionContext originalExecutionContext = null; 
+    ExecutionContext executionContext = null;
+    EnvironmentImpl environment = EnvironmentImpl.getCurrent();
+    if (environment!=null) {
+      originalExecutionContext = (ExecutionContext) environment.getContext(Context.CONTEXTNAME_EXECUTION);
+      if ( (originalExecutionContext!=null)
+           && (originalExecutionContext.getExecution()==this)
+         ) {
+        originalExecutionContext = null;
+      } else {
+        executionContext = new ExecutionContext(this);
+        environment.setContext(executionContext);
+      }
+    }
+    
+    try {
+      ScriptManager scriptManager = ScriptManager.getScriptManager();
+      return scriptManager.evaluateScript(expression, language);
+    } catch(RuntimeException e) {
+      log.error("Error while evaluation script " + expression, e);
+      throw e;
+    } finally {
+      if (executionContext != null) {
+        environment.removeContext(executionContext);
+      }
+      if (originalExecutionContext != null) {
+        environment.setContext(originalExecutionContext);
+      }
+    }
+  }
 
   public void handleException(ObservableElementImpl observableElement,
                               EventImpl event,

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExpressionCondition.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExpressionCondition.java	2010-01-18 23:27:37 UTC (rev 6092)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExpressionCondition.java	2010-01-19 09:57:49 UTC (rev 6093)
@@ -48,7 +48,9 @@
   public void setExpression(String expression) {
     this.expression = expression;
   }
+  
   public void setLanguage(String language) {
     this.language = language;
   }
+  
 }

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/gateway/InclusiveGatewayTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/gateway/InclusiveGatewayTest.java	2010-01-18 23:27:37 UTC (rev 6092)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/gateway/InclusiveGatewayTest.java	2010-01-19 09:57:49 UTC (rev 6093)
@@ -219,22 +219,22 @@
     
     // If var == 6, then the nested inclusive split will not be reached
     // The inclusive merge will then have to merge two incoming sequence flow
-    /*ProcessInstance pi = startAndVerifySimpleSplitProcess("nestedInclusiveSplit", 6, "wait1", "wait2");
+    ProcessInstance pi = startAndVerifySimpleSplitProcess("nestedInclusiveSplit", 6, "wait1", "wait2");
     pi = executionService.signalExecutionById(pi.findActiveExecutionIn("wait1").getId());
     assertActivitiesActive(pi.getId(), "wait2", "wait4");
     pi = executionService.signalExecutionById(pi.findActiveExecutionIn("wait2").getId());
     pi = executionService.signalExecutionById(pi.findActiveExecutionIn("wait4").getId());
-    assertProcessInstanceEnded(pi);*/
+    assertProcessInstanceEnded(pi);
     
     // If var == 9, the inclusive split will be reached and it will produce 2 outgoing sequence flow.
     // The inclusive merge will have to merge three incoming sequence flow
-    /*ProcessInstance pi = startAndVerifySimpleSplitProcess("nestedInclusiveSplit", 9, "wait1", "wait2");
+    pi = startAndVerifySimpleSplitProcess("nestedInclusiveSplit", 9, "wait1", "wait2");
     pi = executionService.signalExecutionById(pi.findActiveExecutionIn("wait1").getId());
     assertActivitiesActive(pi.getId(), "wait2", "wait5", "wait6");
     pi = executionService.signalExecutionById(pi.findActiveExecutionIn("wait5").getId());
     pi = executionService.signalExecutionById(pi.findActiveExecutionIn("wait6").getId());
     pi = executionService.signalExecutionById(pi.findActiveExecutionIn("wait2").getId());
-    assertProcessInstanceEnded(pi);*/
+    assertProcessInstanceEnded(pi);
   }
   
   private ProcessInstance startAndVerifySimpleSplitProcess(String processKey, Integer varValue, String ... expectedActivities) {



More information about the jbpm-commits mailing list