[jbpm-commits] JBoss JBPM SVN: r4821 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/activity and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri May 15 06:45:04 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-05-15 06:45:02 -0400 (Fri, 15 May 2009)
New Revision: 4821

Added:
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateActivity.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateBinding.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java
Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Activity.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/StartBinding.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
   jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml
Log:
JBPM-2026 initial addition of basic super-state test

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Activity.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Activity.java	2009-05-15 09:59:31 UTC (rev 4820)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/model/Activity.java	2009-05-15 10:45:02 UTC (rev 4821)
@@ -129,4 +129,7 @@
    * and {@link Execution#getPreviousTransition()} will be available to the 
    * activity behaviour when it is executed or signalled. */
   boolean isPreviousNeeded();
+  
+  /** the type of this activity which corresponds to the xml tag */
+  String getType();
 }
\ No newline at end of file

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/StartBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/StartBinding.java	2009-05-15 09:59:31 UTC (rev 4820)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/StartBinding.java	2009-05-15 10:45:02 UTC (rev 4821)
@@ -44,7 +44,7 @@
     if (processDefinition.getInitial()==null) {
       processDefinition.setInitial(startActivity);
       
-    } else {
+    } else if (startActivity.getParentActivity()==null) {
       parse.addProblem("multiple start events not yet supported");
     }
     

Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateActivity.java	                        (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateActivity.java	2009-05-15 10:45:02 UTC (rev 4821)
@@ -0,0 +1,74 @@
+/*
+ * 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.jpdl.internal.activity;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.activity.ActivityExecution;
+import org.jbpm.api.model.Activity;
+import org.jbpm.api.model.Transition;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class SuperStateActivity extends JpdlExternalActivity {
+
+  private static final long serialVersionUID = 1L;
+
+  public void execute(ActivityExecution execution) throws Exception {
+    // find the start activity
+    Activity activity = execution.getActivity();
+    Activity startActivity = findStartActivity(activity);
+    execution.execute(startActivity);
+  }
+
+  private Activity findStartActivity(Activity activity) {
+    List nestedActivities = activity.getActivities();
+    for (ActivityImpl nestedActivity : (List<ActivityImpl>) nestedActivities) {
+      if (nestedActivity.getBehaviour() instanceof StartActivity) {
+        return nestedActivity;
+      }
+    }
+    throw new JbpmException("no start activity in "+activity);
+  }
+
+  public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
+    Transition transition = null;
+    Activity activity = execution.getActivity();
+    List<Transition> outgoingTransitions = activity.getOutgoingTransitions();
+    
+    int nbrOfOutgoingTransitions  = (outgoingTransitions!=null ? outgoingTransitions.size() : 0);
+    if ( (signalName==null)
+         && (nbrOfOutgoingTransitions==1)
+       ) {
+      transition = outgoingTransitions.get(0);
+    } else {
+      transition = activity.getOutgoingTransition(signalName);
+    }
+    
+    execution.take(transition);
+  }
+}


Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateActivity.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateBinding.java	                        (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateBinding.java	2009-05-15 10:45:02 UTC (rev 4821)
@@ -0,0 +1,50 @@
+/*
+ * 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.jpdl.internal.activity;
+
+import org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class SuperStateBinding extends JpdlBinding {
+
+  public SuperStateBinding() {
+    super("super-state");
+  }
+
+  public Object parse(Element element, Parse parse, Parser parser) {
+    SuperStateActivity superStateActivity = new SuperStateActivity();
+    
+    ActivityImpl activity = parse.findObject(ActivityImpl.class);
+
+    JpdlParser jpdlParser = (JpdlParser) parser;
+    jpdlParser.parseActivities(element, parse, activity);
+
+    return superStateActivity;
+  }
+}


Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SuperStateBinding.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java	2009-05-15 09:59:31 UTC (rev 4820)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java	2009-05-15 10:45:02 UTC (rev 4821)
@@ -31,9 +31,6 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
-import javax.print.attribute.standard.Severity;
-
-import org.jbpm.api.Problem;
 import org.jbpm.api.activity.ActivityBehaviour;
 import org.jbpm.api.env.Environment;
 import org.jbpm.api.listener.EventListener;
@@ -42,6 +39,7 @@
 import org.jbpm.jpdl.internal.model.JpdlProcessDefinition;
 import org.jbpm.pvm.internal.model.ActivityCoordinatesImpl;
 import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.CompositeElementImpl;
 import org.jbpm.pvm.internal.model.EventImpl;
 import org.jbpm.pvm.internal.model.ObservableElementImpl;
 import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
@@ -221,33 +219,33 @@
     }
   }
 
-  public void parseActivities(Element documentElement, Parse parse, JpdlProcessDefinition processDefinition) {
+  public void parseActivities(Element documentElement, Parse parse, CompositeElementImpl compositeElement) {
     List<Element> elements = XmlUtil.elements(documentElement);
-    for (Element element : elements) {
-      String tagName = XmlUtil.getTagLocalName(element);
+    for (Element nestedElement : elements) {
+      String tagName = XmlUtil.getTagLocalName(nestedElement);
       if ( !"on".equals(tagName) 
            && !"timer".equals(tagName)
            && !"swimlane".equals(tagName)
          ) {
-        JpdlBinding activityBinding = (JpdlBinding) getBinding(element, "activity");
+        JpdlBinding activityBinding = (JpdlBinding) getBinding(nestedElement, "activity");
         if (activityBinding != null) {
-          ActivityImpl activity = processDefinition.createActivity();
+          ActivityImpl activity = compositeElement.createActivity();
           parse.pushObject(activity);
           try {
             activity.setType(activityBinding.getTagName());
-            activityBinding.parseName(element, activity, parse);
-            activityBinding.parseTransitions(element, activity, parse, this);
+            activityBinding.parseName(nestedElement, activity, parse);
+            activityBinding.parseTransitions(nestedElement, activity, parse, this);
 
-            if (XmlUtil.attributeBoolean(element, "async", false, parse, Boolean.FALSE)) {
+            if (XmlUtil.attributeBoolean(nestedElement, "async", false, parse, Boolean.FALSE)) {
               activity.setExecutionAsync(true);
             }
 
-            ActivityBehaviour activityBehaviour = (ActivityBehaviour) activityBinding.parse(element, parse, this);
+            ActivityBehaviour activityBehaviour = (ActivityBehaviour) activityBinding.parse(nestedElement, parse, this);
             activity.setBehaviour(activityBehaviour);
 
-            parseOnEvents(element, parse, activity);
+            parseOnEvents(nestedElement, parse, activity);
 
-            String g = XmlUtil.attribute(element, "g");
+            String g = XmlUtil.attribute(nestedElement, "g");
             if (g != null) {
               StringTokenizer stringTokenizer = new StringTokenizer(g, ",");
               ActivityCoordinatesImpl coordinates = null;

Modified: jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml	2009-05-15 09:59:31 UTC (rev 4820)
+++ jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml	2009-05-15 10:45:02 UTC (rev 4821)
@@ -15,4 +15,5 @@
   <activity binding="org.jbpm.jpdl.internal.activity.TaskBinding" />
   <activity binding="org.jbpm.jpdl.internal.activity.SubProcessBinding" />
   <activity binding="org.jbpm.jpdl.internal.activity.MailBinding" />
+  <activity binding="org.jbpm.jpdl.internal.activity.SuperStateBinding" />
 </activities>

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java	2009-05-15 10:45:02 UTC (rev 4821)
@@ -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.test.activities;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class SuperStateBasicsTest extends JbpmTestCase {
+
+  public void testSimplestSuperState() {
+    deployJpdlXmlString(
+      "<process name='Super'>" +
+      "  <start>" +
+      "    <transition to='super' />" +
+      "  </start>" +
+      "  <super-state name='super'>" +
+      "    <start>" +
+      "      <transition to='a' />" +
+      "    </start>" +
+      "    <state name='a'>" +
+      "      <transition to='done' />" +
+      "    </state>" +
+      "    <end name='done' />" +
+      "    <transition to='end' />" +
+      "  </super-state>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("Super");
+    assertEquals("a", processInstance.getActivityName());
+    
+    processInstance = executionService.signalExecutionById(processInstance.getId());
+    assertTrue(processInstance.isEnded());
+  }
+
+  public void testSuperStateDirectEntry() {
+    deployJpdlXmlString(
+      "<process name='Super'>" +
+      "  <start>" +
+      "    <transition to='direct' />" +
+      "  </start>" +
+      "  <super-state name='super'>" +
+      "    <start name='direct'>" +
+      "      <transition to='a' />" +
+      "    </start>" +
+      "    <state name='a'>" +
+      "      <transition to='done' />" +
+      "    </state>" +
+      "    <end name='done' />" +
+      "    <transition to='end' />" +
+      "  </super-state>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("Super");
+    assertEquals("a", processInstance.getActivityName());
+    
+    processInstance = executionService.signalExecutionById(processInstance.getId());
+    assertTrue(processInstance.isEnded());
+  }
+
+  public void testSuperStateMultipleEntries() {
+    deployJpdlXmlString(
+      "<process name='Super'>" +
+      "  <start>" +
+      "    <transition to='choose' />" +
+      "  </start>" +
+      "  <decision name='choose' expr='#{theWayToGo}'>" +
+      "    <transition name='left' to='left' />" +
+      "    <transition name='right' to='right' />" +
+      "  </decision>" +
+      "  <super-state name='super'>" +
+      "    <start name='left'>" +
+      "      <transition to='a' />" +
+      "    </start>" +
+      "    <start name='right'>" +
+      "      <transition to='b' />" +
+      "    </start>" +
+      "    <state name='a'>" +
+      "      <transition to='done' />" +
+      "    </state>" +
+      "    <state name='b'>" +
+      "      <transition to='done' />" +
+      "    </state>" +
+      "    <end name='done' />" +
+      "    <transition to='end' />" +
+      "  </super-state>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("theWayToGo", "left");
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("Super", variables);
+    assertEquals("a", processInstance.getActivityName());
+    
+    processInstance = executionService.signalExecutionById(processInstance.getId());
+    assertTrue(processInstance.isEnded());
+
+    variables.put("theWayToGo", "right");
+    processInstance = executionService.startProcessInstanceByKey("Super", variables);
+    assertEquals("b", processInstance.getActivityName());
+    
+    processInstance = executionService.signalExecutionById(processInstance.getId());
+    assertTrue(processInstance.isEnded());
+  }
+}


Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the jbpm-commits mailing list