[jbpm-commits] JBoss JBPM SVN: r6808 - in jbpm4/trunk/modules: bpmn/src/main/java/org/jbpm/bpmn/parser and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 9 11:42:37 EST 2010


Author: rebody
Date: 2010-11-09 11:42:36 -0500 (Tue, 09 Nov 2010)
New Revision: 6808

Added:
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BoundaryErrorEvent.java
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/error/
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/error/BoundaryErrorEventTest.java
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/error/
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/error/boundary_error_event.bpmn.xml
Modified:
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/EndActivity.java
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
Log:
JBPM-2926 boundary error event

Added: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BoundaryErrorEvent.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BoundaryErrorEvent.java	                        (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BoundaryErrorEvent.java	2010-11-09 16:42:36 UTC (rev 6808)
@@ -0,0 +1,66 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.api.model.Transition;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.internal.model.op.AtomicOperation;
+
+/**
+ * boundary error event.
+ *
+ * @author Huisheng Xu
+ */
+public class BoundaryErrorEvent extends BpmnActivity implements EventListener, BpmnEvent {
+
+  protected String boundaryErrorEventActivityName;
+
+  @SuppressWarnings("unchecked")
+  public void execute(ExecutionImpl execution) {
+    ExecutionImpl parent = execution.destroyScope(execution.getActivity());
+    this.executeBoundaryEventBranch(parent);
+  }
+
+  protected void executeBoundaryEventBranch(ExecutionImpl execution) {
+    ProcessDefinitionImpl processDefinitionImpl = execution.getProcessDefinition();
+    ActivityImpl activityImpl = processDefinitionImpl.getActivity(boundaryErrorEventActivityName);
+    execution.moveTo(activityImpl);
+    execution.take(activityImpl.getOutgoingTransitions().get(0));
+  }
+
+  public void notify(EventListenerExecution execution) {
+    this.execute((ExecutionImpl) execution);
+  }
+
+  public void setBoundaryErrorEventActivityName(String boundaryErrorEventActivityName) {
+    this.boundaryErrorEventActivityName = boundaryErrorEventActivityName;
+  }
+
+}

Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/EndActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/EndActivity.java	2010-11-09 16:41:18 UTC (rev 6807)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/EndActivity.java	2010-11-09 16:42:36 UTC (rev 6808)
@@ -68,7 +68,13 @@
 
       } else {
         execution.setActivity(parentActivity);
-        execution.signal();
+
+        ExecutionImpl parent = (ExecutionImpl) execution.getParent(); // save parent before it is nullified
+        if (parent != null && errorCode != null) {
+          parent.fire(errorCode, (ActivityImpl) activity.getParentActivity());
+        } else {
+          execution.signal();
+        }
       }
 
     } else {

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-11-09 16:41:18 UTC (rev 6807)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java	2010-11-09 16:42:36 UTC (rev 6808)
@@ -39,6 +39,7 @@
 import org.jbpm.bpmn.common.Resource;
 import org.jbpm.bpmn.common.ResourceParameter;
 import org.jbpm.bpmn.flownodes.BpmnActivity;
+import org.jbpm.bpmn.flownodes.BoundaryErrorEvent;
 import org.jbpm.bpmn.flownodes.BoundaryTimerEvent;
 import org.jbpm.bpmn.model.BpmnProcessDefinition;
 import org.jbpm.bpmn.model.SequenceflowCondition;
@@ -277,9 +278,9 @@
       Element timerEventDefinition = XmlUtil.element(boundaryEventElement, "timerEventDefinition");
       Element errorEventDefinition = XmlUtil.element(boundaryEventElement, "errorEventDefinition");
       if (timerEventDefinition != null) {
-        parseBoundaryTimerEventDefinition(timerEventDefinition, interrupting, nestedActivity, refActivity, parse);
+        this.parseBoundaryTimerEventDefinition(timerEventDefinition, interrupting, nestedActivity, refActivity, parse);
       } else if (errorEventDefinition != null) {
-          // TODO: error event boundary
+        this.parseBoundaryErrorEventDefinition(errorEventDefinition, nestedActivity, refActivity, parse);
       } else {
         parse.addProblem("Unsupported boundary event type : " + boundaryEventElement);
       }
@@ -315,6 +316,25 @@
     timerActivity.setActivityBehaviour(boundaryTimerEvent);
   }
 
+  public void parseBoundaryErrorEventDefinition(Element errorEventDefinition,
+                                                ActivityImpl errorActivity,
+                                                ActivityImpl refActivity,
+                                                Parse parse) {
+
+    BoundaryErrorEvent boundaryErrorEvent = new BoundaryErrorEvent();
+    boundaryErrorEvent.setBoundaryErrorEventActivityName(errorActivity.getName());
+
+    String eventName = XmlUtil.attribute(errorEventDefinition, "errorRef");
+
+    EventImpl event = refActivity.getEvent(eventName);
+    if (event == null) {
+      event = refActivity.createEvent(eventName);
+    }
+    EventListenerReference eventListenerReference = event.createEventListenerReference(boundaryErrorEvent);
+
+    errorActivity.setActivityBehaviour(boundaryErrorEvent);
+  }
+
   public void parseSequenceFlow(Element element, Parse parse, BpmnProcessDefinition processDefinition) {
     List<Element> transitionElements = XmlUtil.elements(element, "sequenceFlow");
     for (Element transitionElement : transitionElements) {

Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/error/BoundaryErrorEventTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/error/BoundaryErrorEventTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/event/error/BoundaryErrorEventTest.java	2010-11-09 16:42:36 UTC (rev 6808)
@@ -0,0 +1,52 @@
+/*
+ * 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.bpmn.event.error;
+
+import org.jbpm.api.NewDeployment;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ *
+ * @author Huisheng Xu
+ */
+public class BoundaryErrorEventTest extends JbpmTestCase {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        NewDeployment deployment = repositoryService.createDeployment();
+        deployment.addResourceFromClasspath("org/jbpm/examples/bpmn/event/error/boundary_error_event.bpmn.xml");
+        registerDeployment(deployment.deploy());
+    }
+
+    public void testProcessStartToEnd() {
+
+        ProcessInstance processInstance = executionService.startProcessInstanceByKey("boundary_error_event");
+        assertProcessInstanceEnded(processInstance);
+
+        HistoryProcessInstance hip = historyService.createHistoryProcessInstanceQuery().uniqueResult();
+        assertNotNull(hip);
+    }
+
+}

Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/error/boundary_error_event.bpmn.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/error/boundary_error_event.bpmn.xml	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/event/error/boundary_error_event.bpmn.xml	2010-11-09 16:42:36 UTC (rev 6808)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"
+  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
+  typeLanguage="http://www.w3.org/2001/XMLSchema"
+  expressionLanguage="http://www.w3.org/1999/XPath"
+  targetNamespace="http://jbpm.org/example/bpmn2/boundary_error_event"
+  xmlns:jbpm="http://jbpm.org/bpmn2">
+
+  <error id="MyError" errorCode="MyError" />
+
+  <process id="boundary_error_event" name="Error Boundary Event Process">
+    <startEvent id="startEvent" name="StartProcess"/>
+    <sequenceFlow id="flow1" sourceRef="startEvent" targetRef="subProcess"/>
+    <subProcess id="subProcess" name="Hello" >
+      <startEvent id="sub-start" name="StartSubProcess"/>
+      <sequenceFlow id="flow2" sourceRef="sub-start" targetRef="sub-parallel"/>
+      <parallelGateway id="sub-parallel" gatewayDirection="Diverging"/>
+      <sequenceFlow id="flow3" sourceRef="sub-parallel" targetRef="sub-error"/>
+      <endEvent id="sub-error" name="ErrorEvent">
+        <errorEventDefinition errorRef="MyError"/>
+      </endEvent>
+      <sequenceFlow id="flow4" sourceRef="sub-parallel" targetRef="sub-task"/>
+      <userTask id="sub-task" name="Task" />
+      <sequenceFlow id="flow5" sourceRef="sub-task" targetRef="sub-end"/>
+      <endEvent id="sub-end" name="EndEvent"/>
+    </subProcess>
+    <sequenceFlow id="flow6" sourceRef="subProcess" targetRef="terminateEnd"/>
+    <endEvent id="terminateEnd" name="EndProcess">
+      <terminateEventDefinition/>
+    </endEvent>
+    <boundaryEvent id="errorEvent" name="ErrorEvent" attachedToRef="subProcess" >
+      <errorEventDefinition errorRef="MyError" />
+    </boundaryEvent>
+    <sequenceFlow id="flow7" sourceRef="errorEvent" targetRef="task"/>
+    <scriptTask id="task" name="Goodbye">
+      <script>System.out.println("Error handled");</script>
+    </scriptTask>
+    <sequenceFlow id="flow8" sourceRef="task" targetRef="endEvent"/>
+    <endEvent id="endEvent" name="EndProcess"/>
+  </process>
+</definitions>



More information about the jbpm-commits mailing list