[jbpm-commits] JBoss JBPM SVN: r5353 - in jbpm4/trunk/modules/bpmn/src: main/java/org/jbpm/bpmn/flownodes and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Jul 27 20:26:08 EDT 2009
Author: kukeltje
Date: 2009-07-27 20:26:08 -0400 (Mon, 27 Jul 2009)
New Revision: 5353
Added:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayActivity.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayBinding.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ParallelGatewayActivity.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ParallelGatewayBinding.java
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ParallelGatewayTest.java
jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/parallelGateway.bpmn.xml
jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/parallelGatewayInvalid.bpmn.xml
Removed:
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
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/jbpm.bpmn.flownodes.xml
Log:
Initial commit of parallelgateway and renaming decision to exclusivegateway
Modified: jbpm4/trunk/modules/bpmn/src/main/java/jbpm.bpmn.flownodes.xml
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/jbpm.bpmn.flownodes.xml 2009-07-27 21:31:26 UTC (rev 5352)
+++ jbpm4/trunk/modules/bpmn/src/main/java/jbpm.bpmn.flownodes.xml 2009-07-28 00:26:08 UTC (rev 5353)
@@ -4,5 +4,6 @@
<activity binding="org.jbpm.bpmn.flownodes.ServiceActivityBinding" />
<activity binding="org.jbpm.bpmn.flownodes.ReceiveBinding" />
<activity binding="org.jbpm.bpmn.flownodes.EndBinding" />
- <activity binding="org.jbpm.bpmn.flownodes.DecisionBinding" />
+ <activity binding="org.jbpm.bpmn.flownodes.ParallelGatewayBinding" />
+ <activity binding="org.jbpm.bpmn.flownodes.ExclusiveGatewayBinding" />
</activities>
Deleted: 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 21:31:26 UTC (rev 5352)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionBinding.java 2009-07-28 00:26:08 UTC (rev 5353)
@@ -1,137 +0,0 @@
-/*
- * 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.flownodes;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.jbpm.bpmn.parser.BpmnParser;
-import org.jbpm.internal.log.Log;
-import org.jbpm.pvm.internal.model.ActivityImpl;
-import org.jbpm.pvm.internal.model.TransitionImpl;
-import org.jbpm.pvm.internal.util.XmlUtil;
-import org.jbpm.pvm.internal.wire.binding.ObjectBinding;
-import org.jbpm.pvm.internal.wire.descriptor.ExpressionEvaluatorDescriptor;
-import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.pvm.internal.wire.descriptor.ReferenceDescriptor;
-import org.jbpm.pvm.internal.wire.xml.WireParser;
-import org.jbpm.pvm.internal.xml.Parse;
-import org.jbpm.pvm.internal.xml.Parser;
-import org.w3c.dom.Element;
-
-/**
- * @author Tom Baeyens
- */
-public class DecisionBinding extends BpmnBinding {
-
- private static final Log log = Log.getLog(DecisionBinding.class.getName());
-
- static ObjectBinding objectBinding = new ObjectBinding();
- static WireParser wireParser = WireParser.getInstance();
-
- public DecisionBinding() {
- super("exclusiveGateway");
- }
-
- public Object parse(Element element, Parse parse, Parser parser) {
-
- 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");
- String elementName = element.getAttribute("name");
- // 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) {
- log.debug("Default sequenceFlow for " + elementName + " 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 '" + elementName + "' 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++;
- }
- }
-
- log.debug(gatewayDirection +": incomming: " + incomming + ", outgoing: " + outgoing);
-
- 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;
- }
-
- 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;
- }
-}
Deleted: 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 21:31:26 UTC (rev 5352)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionConditionActivity.java 2009-07-28 00:26:08 UTC (rev 5353)
@@ -1,86 +0,0 @@
-/*
- * 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.flownodes;
-
-import java.util.List;
-
-import org.jbpm.api.JbpmException;
-import org.jbpm.api.activity.ActivityExecution;
-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.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);
- }
-
- 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.getName() != null) {
- execution.historyDecision(transition.getName());
- }
- execution.take(transition);
- }
-
- private Transition findTransition(ExecutionImpl execution) {
- Activity activity = execution.getActivity();
- List<Transition> outgoingTransitions = activity.getOutgoingTransitions();
- for (Transition transition : outgoingTransitions) {
- Condition condition = transition.getCondition();
- 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_;
- }
-
-}
Copied: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayActivity.java (from rev 5351, jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionConditionActivity.java)
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayActivity.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayActivity.java 2009-07-28 00:26:08 UTC (rev 5353)
@@ -0,0 +1,87 @@
+/*
+ * 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.flownodes;
+
+import java.util.List;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.activity.ActivityExecution;
+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.Transition;
+
+/**
+ * @author Tom Baeyens
+ * @author Ronald van Kuijk (kukeltje)
+ */
+public class ExclusiveGatewayActivity 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);
+ }
+
+ 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.getName() != null) {
+ execution.historyDecision(transition.getName());
+ }
+ execution.take(transition);
+ }
+
+ private Transition findTransition(ExecutionImpl execution) {
+ Activity activity = execution.getActivity();
+ List<Transition> outgoingTransitions = activity.getOutgoingTransitions();
+ for (Transition transition : outgoingTransitions) {
+ Condition condition = transition.getCondition();
+ 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_;
+ }
+
+}
Copied: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayBinding.java (from rev 5352, jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/DecisionBinding.java)
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayBinding.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayBinding.java 2009-07-28 00:26:08 UTC (rev 5353)
@@ -0,0 +1,135 @@
+/*
+ * 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.flownodes;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.binding.ObjectBinding;
+import org.jbpm.pvm.internal.wire.xml.WireParser;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+/**
+ * @author Tom Baeyens
+ * @author Ronald van Kuijk (kukeltje)
+ *
+ */
+public class ExclusiveGatewayBinding extends BpmnBinding {
+
+ private static final Log log = Log.getLog(ExclusiveGatewayBinding.class.getName());
+
+ static ObjectBinding objectBinding = new ObjectBinding();
+ static WireParser wireParser = WireParser.getInstance();
+
+ public ExclusiveGatewayBinding() {
+ super("exclusiveGateway");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+
+ String gatewayDirection = "unspeficied";
+ String default_ = null;
+
+ int incomming = 0;
+ int outgoing = 0;
+
+ boolean defaultExists = false;
+ boolean valid = true;
+
+ if (element.hasAttribute("gatewayDirection")) {
+ gatewayDirection = element.getAttribute("gatewayDirection");
+ } else {
+ // unspecified should be the 'xsd' default, so maybe this is not even
+ // needed.
+ gatewayDirection = "unspecified";
+ }
+
+ if (element.hasAttribute("default")) {
+ default_ = element.getAttribute("default");
+ }
+
+ List<Element> transitionElements = XmlUtil.elements((Element) element.getParentNode(), "sequenceFlow");
+ String elementId = element.getAttribute("id");
+ String elementName = element.getAttribute("name");
+
+ Element ce;
+
+ for (Iterator<Element> iterator = transitionElements.iterator(); iterator.hasNext();) {
+ Element transitionElement = iterator.next();
+ String sourceRef = transitionElement.getAttribute("sourceRef");
+ if (elementId.equals(sourceRef)) {
+ outgoing++;
+ ce = XmlUtil.element(transitionElement, "conditionExpression");
+ if (transitionElement.getAttribute("id").equals(default_)) {
+ defaultExists = true;
+ if (ce != null) {
+ // conditionExpression on the default sequenceflow SHALL be ignored according to the spec
+ log.debug("Default sequenceFlow for " + elementName + " has conditionExpressio(s). Ignoring them by removing them from the Document model");
+ transitionElement.removeChild(ce);
+ }
+ } else if (default_ != null && ce == null) {
+ parse.addProblem("exclusiveGateway '" + elementName + "' 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 (invalidGatewayDirection(gatewayDirection, incomming, outgoing)) {
+ parse.addProblem("exclusiveGateway '" + element.getAttribute("name") + "' has the wrong number of incomming (" + incomming + ") and outgoing ("
+ + outgoing + ") transitions for gatewayDirection='" + gatewayDirection + "'", element);
+
+ valid = false;
+ }
+
+ 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;
+ }
+
+ ExclusiveGatewayActivity decisionConditionActivity = new ExclusiveGatewayActivity();
+ decisionConditionActivity.setDefault(default_);
+ decisionConditionActivity.setGatewayDirection(gatewayDirection);
+
+ return decisionConditionActivity;
+ }
+
+ private boolean invalidGatewayDirection(String gatewayDirection, int incomming, int outgoing) {
+
+ log.debug(gatewayDirection + ": incomming: " + incomming + ", outgoing: " + outgoing);
+ return ("converging".equals(gatewayDirection) && (!(incomming > 1) || outgoing != 1))
+ || ("diverging".equals(gatewayDirection) && (incomming != 1 || !(outgoing > 1)))
+ || ("mixed".equals(gatewayDirection) && (incomming <= 1 || outgoing <= 1));
+
+ }
+}
Added: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ParallelGatewayActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ParallelGatewayActivity.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ParallelGatewayActivity.java 2009-07-28 00:26:08 UTC (rev 5353)
@@ -0,0 +1,55 @@
+/*
+ * 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.flownodes;
+
+import org.jbpm.api.activity.ActivityExecution;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+
+/**
+ * @author Ronald van Kuijk (kukeltje)
+ */
+public class ParallelGatewayActivity extends BpmnActivity {
+
+ private static final long serialVersionUID = 1L;
+
+ //GatewayDirection indicates fork (divergence) or join (convergence). Maybe two different activities is better
+ private String gatewayDirection;
+
+ public void execute(ActivityExecution execution) {
+ execute((ExecutionImpl) execution);
+ }
+
+ public void execute(ExecutionImpl execution) {
+
+ //TODO Implement ;-)
+
+ }
+
+ public String getGatewayDirection() {
+ return gatewayDirection;
+ }
+
+ public void setGatewayDirection(String gatewayDirection) {
+ this.gatewayDirection = gatewayDirection;
+ }
+
+}
Added: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ParallelGatewayBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ParallelGatewayBinding.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ParallelGatewayBinding.java 2009-07-28 00:26:08 UTC (rev 5353)
@@ -0,0 +1,115 @@
+/*
+ * 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.flownodes;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.binding.ObjectBinding;
+import org.jbpm.pvm.internal.wire.xml.WireParser;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+/**
+ * @author Tom Baeyens
+ * @author Ronald van Kuijk (kukeltje)
+ *
+ */
+public class ParallelGatewayBinding extends BpmnBinding {
+
+ private static final Log log = Log.getLog(ParallelGatewayBinding.class.getName());
+
+ static ObjectBinding objectBinding = new ObjectBinding();
+ static WireParser wireParser = WireParser.getInstance();
+
+ public ParallelGatewayBinding() {
+ super("parallelGateway");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+
+ String gatewayDirection = "unspeficied";
+
+ if (element.hasAttribute("gatewayDirection")) {
+ gatewayDirection = element.getAttribute("gatewayDirection");
+ } else {
+ // unspecified should be the 'xsd' default, so maybe this is not even
+ // needed.
+ gatewayDirection = "unspecified";
+ }
+
+
+ int incomming = 0;
+ int outgoing = 0;
+
+ boolean valid = true;
+
+ List<Element> transitionElements = XmlUtil.elements((Element) element.getParentNode(), "sequenceFlow");
+ String elementId = element.getAttribute("id");
+ String elementName = element.getAttribute("name");
+
+ if (gatewayDirection.equals("unspecified") || gatewayDirection.equals("mixed")) {
+ parse.addProblem("gatewayDirection='"+gatewayDirection+ "' currently not supported on parallelGateway '" + elementName + "'", element);
+ return null;
+ }
+
+
+ for (Iterator<Element> iterator = transitionElements.iterator(); iterator.hasNext();) {
+ Element transitionElement = iterator.next();
+ String sourceRef = transitionElement.getAttribute("sourceRef");
+ if (elementId.equals(sourceRef)) {
+ outgoing++;
+ if (XmlUtil.element(transitionElement, "conditionExpression") != null) {
+ parse.addProblem("parallelGateway '" + elementName + "' has invalid conditionExpression outgoing transition", element);
+ valid = false;
+ }
+ } else if (transitionElement.getAttribute("targetRef").equals(elementId)) {
+ incomming++;
+ }
+ }
+
+ if (invalidGatewayDirection(gatewayDirection, incomming, outgoing)) {
+ parse.addProblem("parallelGateway '" + elementName + "' has the wrong number of incomming (" + incomming + ") and outgoing (" + outgoing
+ + ") transitions for gatewayDirection='" + gatewayDirection + "'", element);
+
+ valid = false;
+ }
+
+ if (!valid) {
+ return null;
+ }
+
+ return new ParallelGatewayActivity();
+ }
+
+ private boolean invalidGatewayDirection(String gatewayDirection, int incomming, int outgoing) {
+
+ log.debug(gatewayDirection + ": incomming: " + incomming + ", outgoing: " + outgoing);
+ return ("converging".equals(gatewayDirection) && (!(incomming > 1) || outgoing != 1))
+ || ("diverging".equals(gatewayDirection) && (incomming != 1 || !(outgoing > 1)))
+ || ("mixed".equals(gatewayDirection) && (incomming <= 1 || outgoing <= 1));
+
+ }
+}
Added: jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ParallelGatewayTest.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ParallelGatewayTest.java (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ParallelGatewayTest.java 2009-07-28 00:26:08 UTC (rev 5353)
@@ -0,0 +1,120 @@
+/*
+ * 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.flownodes;
+
+import java.util.List;
+
+import org.jbpm.bpmn.parser.BpmnParser;
+import org.jbpm.pvm.internal.xml.Problem;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Ronald van Kuijk (kukeltje)
+ */
+public class ParallelGatewayTest extends JbpmTestCase {
+
+ static BpmnParser bpmnParser = new BpmnParser();
+
+ public List<Problem> parse(String resource) {
+
+ List<Problem> problems = bpmnParser.createParse().setResource(resource).execute().getProblems();
+
+ return problems;
+ }
+
+ public void testNormal() {
+
+ List<Problem> problems = parse("org/jbpm/bpmn/flownodes/parallelGateway.bpmn.xml");
+
+ if (!problems.isEmpty()) {
+ fail("No problems should have occured. Problems: " + problems);
+ }
+ }
+
+ public void testInvalid() {
+
+ List<Problem> problems = parse("org/jbpm/bpmn/flownodes/parallelGatewayInvalid.bpmn.xml");
+
+ if ((problems == null) || (problems.isEmpty())) {
+ fail("expected problems during parse");
+ } else {
+ assertTextPresent("parallelGateway 'The Fork' has the wrong number of incomming (1) and outgoing (2) transitions for gatewayDirection='converging'", problems.get(0).getMsg());
+ }
+ }
+//
+// public void testNonExistingDefault() {
+//
+// List<Problem> problems = parse("org/jbpm/bpmn/flownodes/exclusiveGatewayNonExistingDefault.bpmn.xml");
+//
+// if ((problems == null) || (problems.isEmpty())) {
+// fail("expected problems during parse");
+// } else {
+// assertTextPresent("cvc-id.1: There is no ID/IDREF binding for IDREF 'flow666'", problems.get(0).getMsg());
+// }
+// }
+//
+// public void testMixedValid() {
+//
+// List<Problem> problems = parse("org/jbpm/bpmn/flownodes/exclusiveGatewayMixedValid.bpmn.xml");
+//
+// if (!problems.isEmpty()) {
+// fail("No problems should have occured. Problems: " + problems);
+// }
+// }
+//
+//
+// public void testMixedInvalid() {
+//
+// List<Problem> problems = parse("org/jbpm/bpmn/flownodes/exclusiveGatewayMixedInvalid.bpmn.xml");
+//
+// if ((problems == null) || (problems.isEmpty())) {
+// fail("expected problems during parse");
+// } else {
+// assertTextPresent("exclusiveGateway 'Just a gateway' has the wrong number of incomming (1) and outgoing (2) transitions for gatewayDirection='mixed'", problems.get(0).getMsg());
+// }
+// }
+//
+//
+//
+// public void testConvergingInvalid() {
+//
+// List<Problem> problems = parse("org/jbpm/bpmn/flownodes/exclusiveGatewayConvergingInvalid.bpmn.xml");
+//
+// if ((problems == null) || (problems.isEmpty())) {
+// fail("expected problems during parse");
+// } else {
+// assertTextPresent("exclusiveGateway 'Just a gateway' has the wrong number of incomming (1) and outgoing (2) transitions for gatewayDirection='converging'", problems.get(0).getMsg());
+// }
+// }
+//
+// public void testDivergingInvalid() {
+//
+// List<Problem> problems = parse("org/jbpm/bpmn/flownodes/exclusiveGatewayDivergingInvalid.bpmn.xml");
+//
+// if ((problems == null) || (problems.isEmpty())) {
+// fail("expected problems during parse");
+// } else {
+// assertTextPresent("exclusiveGateway 'Just a gateway' has the wrong number of incomming (2) and outgoing (2) transitions for gatewayDirection='diverging'", problems.get(0).getMsg());
+// }
+// }
+
+}
Added: jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/parallelGateway.bpmn.xml
===================================================================
--- jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/parallelGateway.bpmn.xml (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/parallelGateway.bpmn.xml 2009-07-28 00:26:08 UTC (rev 5353)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bpmn:definitions id="ExclusiveGatewayNormal"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 /home/kukel/workspace-jbpm4/jbpm/modules/bpmn/src/main/resources/BPMN20.xsd"
+ xmlns:bpmn="http://schema.omg.org/spec/BPMN/2.0" typeLanguage="http://www.w3.org/2001/XMLSchema"
+ expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://sample.bpmn.camunda.com/">
+
+ <bpmn:process id="Shipment" name="Shipment">
+ <!-- Start-Event -->
+ <bpmn:startEvent id="Start" />
+
+ <bpmn:sequenceFlow id="flow1" sourceRef="Start"
+ targetRef="parallelGatewayFork" name="fromStartToFork" />
+
+ <bpmn:parallelGateway id="parallelGatewayFork"
+ name="The Fork" gatewayDirection="diverging"/>
+
+ <bpmn:sequenceFlow id="flow2" sourceRef="parallelGatewayFork"
+ targetRef="parallelGatewayJoin" name="Leg 1" />
+
+ <bpmn:sequenceFlow id="flow3" sourceRef="parallelGatewayFork"
+ targetRef="parallelGatewayJoin" name="Leg 2" />
+
+ <bpmn:parallelGateway id="parallelGatewayJoin"
+ name="The Join" gatewayDirection="converging"/>
+
+ <bpmn:sequenceFlow id="flow4" sourceRef="parallelGatewayJoin"
+ targetRef="End">
+ </bpmn:sequenceFlow>
+
+ <!-- End Events -->
+ <bpmn:endEvent id="End" name="End" />
+ </bpmn:process>
+</bpmn:definitions>
Added: jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/parallelGatewayInvalid.bpmn.xml
===================================================================
--- jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/parallelGatewayInvalid.bpmn.xml (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/parallelGatewayInvalid.bpmn.xml 2009-07-28 00:26:08 UTC (rev 5353)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<bpmn:definitions id="ExclusiveGatewayNormal"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 /home/kukel/workspace-jbpm4/jbpm/modules/bpmn/src/main/resources/BPMN20.xsd"
+ xmlns:bpmn="http://schema.omg.org/spec/BPMN/2.0" typeLanguage="http://www.w3.org/2001/XMLSchema"
+ expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://sample.bpmn.camunda.com/">
+
+ <bpmn:process id="Shipment" name="Shipment">
+ <!-- Start-Event -->
+ <bpmn:startEvent id="Start" />
+
+ <bpmn:sequenceFlow id="flow1" sourceRef="Start"
+ targetRef="parallelGatewayFork" name="fromStartToFork" />
+
+ <bpmn:parallelGateway id="parallelGatewayFork"
+ name="The Fork" gatewayDirection="converging"/>
+
+ <bpmn:sequenceFlow id="flow2" sourceRef="parallelGatewayFork"
+ targetRef="parallelGatewayJoin" name="Leg 1" />
+
+ <bpmn:sequenceFlow id="flow3" sourceRef="parallelGatewayFork"
+ targetRef="parallelGatewayJoin" name="Leg 2" />
+
+ <bpmn:parallelGateway id="parallelGatewayJoin"
+ name="The Join" gatewayDirection="diverging"/>
+
+ <bpmn:sequenceFlow id="flow4" sourceRef="parallelGatewayJoin"
+ targetRef="End">
+ </bpmn:sequenceFlow>
+
+ <!-- End Events -->
+ <bpmn:endEvent id="End" name="End" />
+ </bpmn:process>
+</bpmn:definitions>
More information about the jbpm-commits
mailing list