[jbpm-commits] JBoss JBPM SVN: r6836 - in jbpm4/trunk/modules: examples/src/test/java/org/jbpm/examples/bpmn and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Nov 21 07:55:21 EST 2010


Author: rebody
Date: 2010-11-21 07:55:19 -0500 (Sun, 21 Nov 2010)
New Revision: 6836

Added:
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/SignalStartEventActivity.java
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/subprocess/
   jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/subprocess/SignalStartEventTest.java
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/subprocess/
   jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/subprocess/signal_start_sub_process.bpmn.xml
Modified:
   jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/StartEventBinding.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
Log:
JBPM-2723 signal start event

Added: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/SignalStartEventActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/SignalStartEventActivity.java	                        (rev 0)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/SignalStartEventActivity.java	2010-11-21 12:55:19 UTC (rev 6836)
@@ -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.bpmn.flownodes;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.op.AtomicOperation;
+
+/**
+ * @author Huisheng Xu
+ */
+public class SignalStartEventActivity extends NoneStartEventActivity implements BpmnEvent, EventListener {
+
+  private static final long serialVersionUID = 1L;
+
+  private String activityName;
+
+  public void notify(EventListenerExecution execution) {
+    ExecutionImpl parentExecution = (ExecutionImpl) execution;
+    ExecutionImpl childExecution = parentExecution.createExecution(activityName);
+    childExecution.setActivity(parentExecution.getProcessDefinition().findActivity(activityName));
+    childExecution.setState(Execution.STATE_ACTIVE_ROOT);
+
+    childExecution.performAtomicOperation(AtomicOperation.EXECUTE_ACTIVITY);
+  }
+
+  public void setActivityName(String activityName) {
+    this.activityName = activityName;
+  }
+
+}

Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/StartEventBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/StartEventBinding.java	2010-11-21 03:47:28 UTC (rev 6835)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/StartEventBinding.java	2010-11-21 12:55:19 UTC (rev 6836)
@@ -29,6 +29,8 @@
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
 import org.jbpm.pvm.internal.job.StartProcessTimer;
 import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.EventImpl;
+import org.jbpm.pvm.internal.model.EventListenerReference;
 import org.jbpm.pvm.internal.model.TimerDefinitionImpl;
 import org.jbpm.pvm.internal.session.DbSession;
 import org.jbpm.pvm.internal.util.XmlUtil;
@@ -38,51 +40,56 @@
 
 
 public class StartEventBinding extends BpmnBinding {
-  
+
   private static final Log LOG = Log.getLog(StartEventBinding.class.getName());
 
   public StartEventBinding() {
-	  super("startEvent");
+      super("startEvent");
   }
-  
+
   public Object parse(Element element, Parse parse, BpmnParser bpmnParser) {
     ActivityImpl startActivity = parse.contextStackFind(ActivityImpl.class);
     BpmnProcessDefinition processDefinition = parse.contextStackFind(BpmnProcessDefinition.class);
-    
+
     if (processDefinition.getInitial()==null) {
       processDefinition.setInitial(startActivity);
-      
+
     } else if (startActivity.getParentActivity()==null) {
       parse.addProblem("multiple start events not yet supported", element);
     }
-    
+
     String id = XmlUtil.attribute(element, "id", parse);
     Element eventDefinition = XmlUtil.element(element);
-    if (eventDefinition != null && "timerEventDefinition".equals(eventDefinition.getNodeName())) {
-      return createTimerStartEvent(processDefinition, eventDefinition, id, bpmnParser, parse);
-    } else if (eventDefinition != null){
-      parse.addProblem("Invalid eventDefinition type : " + eventDefinition.getNodeName());
+
+    if (eventDefinition != null) {
+      if ("timerEventDefinition".equals(eventDefinition.getNodeName())) {
+        return createTimerStartEvent(processDefinition, eventDefinition, id, bpmnParser, parse);
+      } else if ("signalEventDefinition".equals(eventDefinition.getNodeName())) {
+        return createSignalStartEvent(processDefinition, eventDefinition, id, bpmnParser, parse);
+      } else {
+        parse.addProblem("Invalid eventDefinition type : " + eventDefinition.getNodeName());
+      }
     }
-    
+
     return new NoneStartEventActivity(); // default
   }
-  
+
   /**
    * Timer start event
    */
-  protected TimerStartEventActivity createTimerStartEvent(BpmnProcessDefinition processDefinition, 
+  protected TimerStartEventActivity createTimerStartEvent(BpmnProcessDefinition processDefinition,
           Element timerEventDefinition, String eventId, BpmnParser parser, Parse parse) {
-    
+
     TimerStartEventActivity timerStartEvent = new TimerStartEventActivity();
     TimerDefinitionImpl timerDefinition = parser.parseTimerEventDefinition(timerEventDefinition, parse, eventId);
-    
+
     if (timerDefinition == null) { // problem explanation will already be added to parse, no need to do it here
       return null;
     }
-    
+
     StartProcessTimer startProcessTimer = new StartProcessTimer();
     startProcessTimer.setProcessDefinitionName(processDefinition.getName());
-    
+
     if (timerDefinition.getDueDate() != null) {
       startProcessTimer.setDuedate(timerDefinition.getDueDate());
     } else if (timerDefinition.getDueDateDescription() != null) {
@@ -90,20 +97,41 @@
     } else if (timerDefinition.getCronExpression() != null) {
       startProcessTimer.setIntervalExpression(timerDefinition.getCronExpression());
     }
-    
+
     if (LOG.isDebugEnabled()) {
-      LOG.debug("Scheduling a new start process timer for process definition " 
-              + processDefinition.getName());
+      LOG.debug("Scheduling a new start process timer for process definition "
+        + processDefinition.getName());
     }
-    
+
     deleteStartProcessTimers(processDefinition.getName()); // Only the latest procDef should have a timer start
     startProcessTimer.schedule();
     return timerStartEvent;
   }
-  
+
+  protected SignalStartEventActivity createSignalStartEvent(BpmnProcessDefinition processDefinition,
+          Element signalEventDefinition, String eventId, BpmnParser parser, Parse parse) {
+    SignalStartEventActivity signalStartEvent = new SignalStartEventActivity();
+
+    signalStartEvent.setActivityName(eventId);
+
+    String eventName = XmlUtil.attribute(signalEventDefinition, "signalRef");
+    EventImpl event = processDefinition.getEvent(eventName);
+    if (event == null) {
+      event = processDefinition.createEvent(eventName);
+    }
+    EventListenerReference eventListenerReference = event.createEventListenerReference(signalStartEvent);
+    eventListenerReference.setPropagationEnabled(true);
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("activityId : " + eventId + ", event : " + event);
+    }
+
+    return signalStartEvent;
+  }
+
   /**
    * Deletes all existing timer start events for a given process definition.
-   * 
+   *
    * This is required when a new version of a process definition with a timer start is deployed:
    * only the latest may version may be started by the timer start event.
    */
@@ -117,5 +145,5 @@
       dbSession.delete(spt);
     }
   }
-  
+
 }

Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/subprocess/SignalStartEventTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/subprocess/SignalStartEventTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/subprocess/SignalStartEventTest.java	2010-11-21 12:55:19 UTC (rev 6836)
@@ -0,0 +1,45 @@
+/*
+ * 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.subprocess;
+
+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 SignalStartEventTest extends JbpmTestCase {
+
+    public void testSignalStart() {
+        NewDeployment deployment = repositoryService.createDeployment();
+        deployment.addResourceFromClasspath("org/jbpm/examples/bpmn/subprocess/signal_start_sub_process.bpmn.xml");
+        registerDeployment(deployment.deploy());
+
+        ProcessInstance processInstance = executionService.startProcessInstanceByKey("signal_start_sub_process");
+
+        assertEquals(2, taskService.createTaskQuery().list().size());
+    }
+
+}

Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/subprocess/signal_start_sub_process.bpmn.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/subprocess/signal_start_sub_process.bpmn.xml	                        (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/subprocess/signal_start_sub_process.bpmn.xml	2010-11-21 12:55:19 UTC (rev 6836)
@@ -0,0 +1,48 @@
+<?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/signal_start_sub_process"
+  xmlns:jbpm="http://jbpm.org/bpmn2">
+
+  <signal id="MySignal" name="MySignal" />
+
+  <process id="signal_start_sub_process" name="Signal Start Sub Process">
+
+    <startEvent id="startEvent" name="StartProcess"/>
+
+    <sequenceFlow id="flow1" sourceRef="startEvent" targetRef="signalEvent"/>
+
+    <intermediateThrowEvent id="signalEvent" name="Signal Event">
+      <signalEventDefinition signalRef="MySignal"/>
+    </intermediateThrowEvent>
+
+    <sequenceFlow id="flow2" sourceRef="signalEvent" targetRef="subTask1"/>
+
+    <userTask id="subTask1" name="User Task" />
+
+    <sequenceFlow id="flow3" sourceRef="subTask1" targetRef="end"/>
+
+    <endEvent id="end" name="EndEvent">
+      <terminateEventDefinition/>
+    </endEvent>
+
+    <subProcess id="subProcess" name="HelloSignal" triggeredByEvent="true">
+      <startEvent id="subStart" name="StartSubProcess">
+        <signalEventDefinition signalRef="MySignal"/>
+      </startEvent>
+
+      <sequenceFlow id="flow4" sourceRef="subStart" targetRef="subTask2"/>
+
+      <userTask id="subTask2" name="User Task2" />
+
+      <sequenceFlow id="flow5" sourceRef="subTask2" targetRef="subEnd"/>
+
+      <endEvent id="subEnd" name="EndEvent"/>
+    </subProcess>
+
+  </process>
+</definitions>

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-11-21 03:47:28 UTC (rev 6835)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2010-11-21 12:55:19 UTC (rev 6836)
@@ -212,13 +212,13 @@
 
   public void start() {
     if (!STATE_CREATED.equals(state)) {
-      throw new JbpmException(toString()+" is already begun: "+state);
+      throw new JbpmException(toString() + " is already begun: " + state);
     }
     this.state = STATE_ACTIVE_ROOT;
     ExecutionImpl scopedExecution = initializeScopes();
 
     fire(Event.START, getProcessDefinition());
-    if (getActivity()!=null) {
+    if (getActivity() != null) {
       scopedExecution.performAtomicOperation(AtomicOperation.EXECUTE_ACTIVITY);
     }
   }
@@ -229,7 +229,7 @@
     ActivityImpl initial = getProcessDefinition().getInitial();
     ExecutionImpl scopedExecution = null;
 
-    if (initial!=null) {
+    if (initial != null) {
       enteredActivities.add(initial);
       ActivityImpl parentActivity = initial.getParentActivity();
       while (parentActivity!=null) {



More information about the jbpm-commits mailing list