[jbpm-commits] JBoss JBPM SVN: r5351 - jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jul 27 15:39:15 EDT 2009


Author: kukeltje
Date: 2009-07-27 15:39:15 -0400 (Mon, 27 Jul 2009)
New Revision: 5351

Modified:
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionBinding.java
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionConditionActivity.java
Log:
Finished parsing of exclusiveGateway

Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionBinding.java	2009-07-27 19:34:52 UTC (rev 5350)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionBinding.java	2009-07-27 19:39:15 UTC (rev 5351)
@@ -21,6 +21,7 @@
  */
 package org.jbpm.bpmn.flownodes;
 
+import java.util.Iterator;
 import java.util.List;
 
 import org.jbpm.pvm.internal.model.ActivityImpl;
@@ -35,7 +36,6 @@
 import org.jbpm.pvm.internal.xml.Parser;
 import org.w3c.dom.Element;
 
-
 /**
  * @author Tom Baeyens
  */
@@ -48,45 +48,83 @@
     super("exclusiveGateway");
   }
 
-  public Object parse(Element element, Parse parse, Parser parser) {  
-    
-    boolean hasConditions = false;
-    List<Element> transitionElements = XmlUtil.elements(element, "transition");
-    ActivityImpl activity = parse.findObject(ActivityImpl.class);
-    List<TransitionImpl> transitions = (List) activity.getOutgoingTransitions();
-    
-    for (int i=0; i<transitionElements.size(); i++) {
-      TransitionImpl transition = transitions.get(i);
-      Element transitionElement = transitionElements.get(i);
+  public Object parse(Element element, Parse parse, Parser parser) {
 
-      Element conditionElement = XmlUtil.element(transitionElement, "condition");
-      if (conditionElement!=null) {
-        hasConditions = true;
-        
-        if (conditionElement.hasAttribute("expr")) {
-          String expr = conditionElement.getAttribute("expr");
-          String lang = XmlUtil.attribute(conditionElement, "expr-lang");
-          ExpressionEvaluatorDescriptor expressionDescriptor = new ExpressionEvaluatorDescriptor(expr, lang);
-          transition.setConditionDescriptor(expressionDescriptor);
-          
-        } else if (conditionElement.hasAttribute("ref")) {
-          String expr = conditionElement.getAttribute("ref");
-          ReferenceDescriptor refDescriptor = new ReferenceDescriptor(expr);
-          transition.setConditionDescriptor(refDescriptor);
-          
-        } else if (ObjectBinding.isObjectDescriptor(conditionElement)) {
-          ObjectDescriptor conditionDescriptor = (ObjectDescriptor) objectBinding.parse(conditionElement, parse, parser);
-          transition.setConditionDescriptor(conditionDescriptor);
+    String gatewayDirection = "unspeficied";
+    String default_ = null;
+
+    if (element.hasAttribute("gatewayDirection")) {
+      gatewayDirection = element.getAttribute("gatewayDirection");
+      // Default behaviour according to the spec is mixed. This is the
+      // default in the activity
+    } else {
+      gatewayDirection = "unspecified";
+    }
+
+    if (element.hasAttribute("default")) {
+      default_ = element.getAttribute("default");
+    }
+
+    List<Element> transitionElements = XmlUtil.elements((Element) element.getParentNode(), "sequenceFlow");
+    String elementId = element.getAttribute("id");
+    // System.out.println("Element name: " + elementId);
+
+    int incomming = 0;
+    int outgoing = 0;
+    boolean defaultExists = false;
+    boolean valid = true;
+
+    for (Iterator iterator = transitionElements.iterator(); iterator.hasNext();) {
+      Element transitionElement = (Element) iterator.next();
+      String sourceRef = transitionElement.getAttribute("sourceRef");
+      if (elementId.equals(sourceRef)) {
+        outgoing++;
+        List<Element> ces = XmlUtil.elements(transitionElement, "conditionExpression");
+        if (transitionElement.getAttribute("id").equals(default_)) {
+          defaultExists = true;
+          if (ces.size() != 0) {
+            System.out.println("Default sequenceFlow has conditionExpressio(s). Ignoring them by removing them from the Document model");
+            for (Iterator iterator2 = ces.iterator(); iterator2.hasNext();) {
+              Element ce = (Element) iterator2.next();
+              transitionElement.removeChild(ce);
+            }
+          }
+        } else {
+          if (default_ != null && ces.size() == 0) {
+            parse.addProblem("exclusiveGateway '" + element.getAttribute("name") + "' has default sequenceFlow '" + default_ + "' but "
+                    + transitionElement.getAttribute("id") + " does not have a required conditionExpression", element);
+            valid = false; // do not break. Parsing may find other issues;
+          }
         }
+      } else if (transitionElement.getAttribute("targetRef").equals(elementId)) {
+        incomming++;
       }
     }
-    
-    if (hasConditions) {
-      return new DecisionConditionActivity();
-    } else {
-      parse.addProblem("decision '"+element.getAttribute("name")+"' must have one of: expr attribute, handler attribute, handler element or condition expressions", element);
+
+    if (("converging".equals(gatewayDirection) && !(incomming > 1) && outgoing != 1)
+            || ("diverging".equals(gatewayDirection) && incomming != 1 && !(outgoing > 1))
+            || ("mixed".equals(gatewayDirection) && (incomming <= 1 || outgoing <= 1))) {
+      parse.addProblem("exclusiveGateway '" + element.getAttribute("name") + "' has the wrong number of incomming (" + incomming + ") and outgoing ("
+              + outgoing + ") transitions for gatewayDirection='" + gatewayDirection + "'", element);
+
+      valid = false;
     }
-    
-    return null;
+
+    if (default_ != null && !defaultExists) {
+      parse.addProblem("exclusiveGateway '" + element.getAttribute("name") + "' default sequenceFlow '" + default_
+              + "' does not exist or is not related to this node", element);
+
+      valid = false;
+    }
+
+    if (!valid) {
+      return null;
+    }
+    DecisionConditionActivity decisionConditionActivity = new DecisionConditionActivity();
+    if (default_ != null) {
+      decisionConditionActivity.setDefault(default_);
+    }
+    decisionConditionActivity.setGatewayDirection(gatewayDirection);
+    return decisionConditionActivity;
   }
 }

Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionConditionActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionConditionActivity.java	2009-07-27 19:34:52 UTC (rev 5350)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionConditionActivity.java	2009-07-27 19:39:15 UTC (rev 5351)
@@ -30,23 +30,26 @@
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.model.Transition;
 
-
 /**
  * @author Tom Baeyens
  */
 public class DecisionConditionActivity extends BpmnActivity {
 
+  String gatewayDirection = "unspecified"; // is the default behaviour
+  String default_ = null;
+
   private static final long serialVersionUID = 1L;
 
   public void execute(ActivityExecution execution) {
-    execute((ExecutionImpl)execution);
+    execute((ExecutionImpl) execution);
   }
+
   public void execute(ExecutionImpl execution) {
     Transition transition = findTransition(execution);
-    if (transition==null) {
-      throw new JbpmException("no outgoing transition condition evaluated to true for decision "+execution.getActivity());
+    if (transition == null) {
+      throw new JbpmException("no outgoing transition condition evaluated to true for decision " + execution.getActivity());
     }
-    if (transition.getName()!=null) {
+    if (transition.getName() != null) {
       execution.historyDecision(transition.getName());
     }
     execution.take(transition);
@@ -57,12 +60,27 @@
     List<Transition> outgoingTransitions = activity.getOutgoingTransitions();
     for (Transition transition : outgoingTransitions) {
       Condition condition = transition.getCondition();
-      if  ( (condition==null)
-            || (condition.evaluate(execution))
-          ) {
+      if ((condition == null) || (condition.evaluate(execution))) {
         return transition;
       }
     }
     return null;
   }
+
+  public String getGatewayDirection() {
+    return gatewayDirection;
+  }
+
+  public void setGatewayDirection(String gatewayDirection) {
+    this.gatewayDirection = gatewayDirection;
+  }
+
+  public String getDefault() {
+    return default_;
+  }
+
+  public void setDefault(String default_) {
+    this.default_ = default_;
+  }
+
 }



More information about the jbpm-commits mailing list