[jbpm-commits] JBoss JBPM SVN: r5984 - in jbpm4/trunk/modules: bpmn/src/main/java/org/jbpm/bpmn/flownodes and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Dec 17 18:23:31 EST 2009
Author: jbarrez
Date: 2009-12-17 18:23:31 -0500 (Thu, 17 Dec 2009)
New Revision: 5984
Added:
jbpm4/trunk/modules/devguide/src/main/docbook/en/images/bpmn2.script.task.png
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/task/script/
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/task/script/ScriptTaskTest.java
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/task/script/
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/task/script/script_task.bpmn.xml
Removed:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/ScriptTaskTest.java
jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/scriptTask.bpmn.xml
Modified:
jbpm4/trunk/modules/bpmn/pom.xml
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskActivity.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskBinding.java
jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch03-Bpmn2.xml
Log:
JBPM-2666: revisited, documented and enhanced BPMN 2.0 Script Task
Modified: jbpm4/trunk/modules/bpmn/pom.xml
===================================================================
--- jbpm4/trunk/modules/bpmn/pom.xml 2009-12-17 21:30:45 UTC (rev 5983)
+++ jbpm4/trunk/modules/bpmn/pom.xml 2009-12-17 23:23:31 UTC (rev 5984)
@@ -81,9 +81,6 @@
<configuration>
<excludes>
<exclude>org/jbpm/test/xml/DbGenTest.java</exclude>
- <exclude>org/jbpm/bpmn/flownodes/ExclusiveGatewayTest.java</exclude>
- <exclude>org/jbpm/bpmn/flownodes/ScriptTaskTest.java</exclude>
- <exclude>org/jbpm/bpmn/flownodes/UserTaskTest.java</exclude>
</excludes>
</configuration>
</plugin>
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskActivity.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskActivity.java 2009-12-17 21:30:45 UTC (rev 5983)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskActivity.java 2009-12-17 23:23:31 UTC (rev 5984)
@@ -21,36 +21,44 @@
*/
package org.jbpm.bpmn.flownodes;
+import org.jbpm.api.JbpmException;
import org.jbpm.api.model.OpenExecution;
-import org.jbpm.bpmn.parser.ExpressionEvaluator;
-import org.jbpm.bpmn.parser.ExpressionEvaluatorDescriptor;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.internal.wire.WireContext;
-import org.jbpm.pvm.internal.wire.WireException;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.script.ScriptManager;
public class ScriptTaskActivity extends BpmnAutomaticActivity {
- private static final long serialVersionUID = 1L;
-
- private ExpressionEvaluatorDescriptor script;
+ private static final long serialVersionUID = 1L;
- public void perform(OpenExecution execution) throws Exception {
- try {
-
- //TODO: return values etc...
- ((ExpressionEvaluator) WireContext.create(script)).evaluateExpression(execution);
+ private String language;
- } catch (Exception e) {
- throw new WireException("couldn't run script: " + e.getMessage(), e);
- }
- }
+ private String script;
- public void setScript(ExpressionEvaluatorDescriptor expressionDescriptor) {
- this.script = expressionDescriptor;
- }
+ public void perform(OpenExecution execution) throws Exception {
+ try {
- public ExpressionEvaluatorDescriptor getScript() {
- return this.script;
- }
-
+ ScriptManager scriptManager = EnvironmentImpl.getFromCurrent(ScriptManager.class);
+ scriptManager.evaluateScript(script, language);
+
+ } catch (Exception e) {
+ throw new JbpmException("couldn't run script: " + e.getMessage(), e);
+ }
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public String getScript() {
+ return script;
+ }
+
+ public void setScript(String script) {
+ this.script = script;
+ }
+
}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskBinding.java 2009-12-17 21:30:45 UTC (rev 5983)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ScriptTaskBinding.java 2009-12-17 23:23:31 UTC (rev 5984)
@@ -21,7 +21,6 @@
*/
package org.jbpm.bpmn.flownodes;
-import org.jbpm.bpmn.parser.ExpressionEvaluatorDescriptor;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.xml.Parse;
import org.jbpm.pvm.internal.xml.Parser;
@@ -36,15 +35,14 @@
}
public Object parse(Element element, Parse parse, Parser parser) {
- ScriptTaskActivity scriptTaskActivity = new ScriptTaskActivity();
- String scriptLanguage = XmlUtil.attribute(element, "scriptLanguage");
+ String scriptLanguage = XmlUtil.attribute(element, "scriptLanguage");
String script = XmlUtil.element(element, "script").getTextContent();
- if (script != null) {
- ExpressionEvaluatorDescriptor expressionDescriptor = new ExpressionEvaluatorDescriptor(script, scriptLanguage);
- scriptTaskActivity.setScript(expressionDescriptor);
- }
+ ScriptTaskActivity scriptTaskActivity = new ScriptTaskActivity();
+ scriptTaskActivity.setLanguage(scriptLanguage);
+ scriptTaskActivity.setScript(script);
+
return scriptTaskActivity;
}
}
Added: jbpm4/trunk/modules/devguide/src/main/docbook/en/images/bpmn2.script.task.png
===================================================================
(Binary files differ)
Property changes on: jbpm4/trunk/modules/devguide/src/main/docbook/en/images/bpmn2.script.task.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch03-Bpmn2.xml
===================================================================
--- jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch03-Bpmn2.xml 2009-12-17 21:30:45 UTC (rev 5983)
+++ jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch03-Bpmn2.xml 2009-12-17 23:23:31 UTC (rev 5984)
@@ -577,12 +577,62 @@
<para>
<emphasis role="bold">Important note: Interfaces, ItemDefinitions and messages are
- defined outside the <process>.</emphasis>. See the example <emphasis role="bold">
+ defined outside the <process>.</emphasis> See the example <emphasis role="bold">
ServiceTaskTest</emphasis> for a concrete process and unit test.
</para>
</section>
+ <section id="scriptTask">
+
+ <title>Task: Script Task</title>
+
+ <para>
+ A script task is a an automatic activity upon which the process engine will execute
+ a script when the task is reached. The script task is used as follows:
+ <programlisting>
+<scriptTask id="scriptTask" name="Script Task" scriptLanguage="bsh">
+ <script><![CDATA[
+ for(int i=0; i < input.length; i++){
+ System.out.println(input[i] + " x 2 = " + (input[i]*2));
+ }]]>
+ </script>
+</scriptTask>
+ </programlisting>
+ The script task, besides the required <emphasis role="bold">id</emphasis> and the optional
+ <emphasis role="bold">name</emphasis>, allows for specifying a <emphasis role="bold">
+ scriptLanguage</emphasis> and a <emphasis role="bold">script</emphasis>.
+ Since we're using JSR-223 ('Scripting for the Java platform'), changing the script language involves
+ <itemizedlist>
+ <listitem>changing the scriptLanguage attribute to the JSR-223 compliant name</listitem>
+ <listitem>adding the ScriptEngine implementation of the specification to the classpath</listitem>
+ </itemizedlist>
+ The XML above is visualized as follows (adding a none start and end event).
+ </para>
+
+ <mediaobject><imageobject><imagedata align="center" fileref="images/bpmn2.script.task.png"/></imageobject></mediaobject>
+
+ <para>
+ As shown in the example, process variables are usable inside the scripts. We can now start
+ a process instance, while also supplying some random input variables:
+ <programlisting>
+Map<String, Object> variables = new HashMap<String, Object>();
+Integer[] values = { 11, 23, 56, 980, 67543, 8762524 };
+variables.put("input", values);
+ </programlisting>
+ In the output console, we can now see the script being executed:
+ <programlisting>
+11 x 2 = 22
+23 x 2 = 46
+56 x 2 = 112
+980 x 2 = 1960
+67543 x 2 = 135086
+8762524 x 2 = 17525048
+ </programlisting>
+ </para>
+
+ </section>
+
<section id="manualTask">
<title>Task: Manual task</title>
Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/task/script/ScriptTaskTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/task/script/ScriptTaskTest.java (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/task/script/ScriptTaskTest.java 2009-12-17 23:23:31 UTC (rev 5984)
@@ -0,0 +1,57 @@
+/*
+ * 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.task.script;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.api.NewDeployment;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ * @author Ronald van Kuijk (kukeltje)
+ * @author Joram Barrez
+ */
+public class ScriptTaskTest extends JbpmTestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ NewDeployment deployment = repositoryService.createDeployment();
+ deployment
+ .addResourceFromClasspath("org/jbpm/examples/bpmn/task/script/script_task.bpmn.xml");
+ registerDeployment(deployment.deploy());
+ }
+
+ public void testProcessExecution() {
+
+ Map<String, Object> variables = new HashMap<String, Object>();
+ Integer[] values = { 11, 23, 56, 980, 67543, 8762524 };
+ variables.put("input", values);
+
+ ProcessInstance pi = executionService.startProcessInstanceByKey("ScriptTask", variables);
+
+ assertProcessInstanceEnded(pi);
+ }
+}
Copied: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/task/script/script_task.bpmn.xml (from rev 5970, jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/scriptTask.bpmn.xml)
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/task/script/script_task.bpmn.xml (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/bpmn/task/script/script_task.bpmn.xml 2009-12-17 23:23:31 UTC (rev 5984)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<definitions id="ExclusiveGatewayNormal"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://schema.omg.org/spec/BPMN/2.0 ../../../../../../../../../../bpmn/src/main/resources/BPMN20.xsd"
+ xmlns="http://schema.omg.org/spec/BPMN/2.0" typeLanguage="http://www.w3.org/2001/XMLSchema"
+ expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://jbpm.org/example/bpmn2/scriptTask">
+
+ <process id="ScriptTask" name="ScriptTask">
+
+ <startEvent id="Start" />
+
+ <sequenceFlow id="flow1" sourceRef="Start"
+ targetRef="scriptTask" name="Start->ScriptTask" />
+
+ <scriptTask id="scriptTask" name="Script Task" scriptLanguage="bsh">
+ <script><![CDATA[
+for(int i=0; i < input.length; i++){
+ System.out.println(input[i] + " x 2 = " + (input[i]*2));
+}]]>
+ </script>
+ </scriptTask>
+
+ <sequenceFlow id="flow2" sourceRef="scriptTask"
+ targetRef="End" />
+
+ <endEvent id="End" name="End" />
+
+ </process>
+</definitions>
Deleted: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/ScriptTaskTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/ScriptTaskTest.java 2009-12-17 21:30:45 UTC (rev 5983)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/ScriptTaskTest.java 2009-12-17 23:23:31 UTC (rev 5984)
@@ -1,78 +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;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jbpm.api.ProcessInstance;
-import org.jbpm.bpmn.parser.BpmnParser;
-import org.jbpm.pvm.internal.xml.Problem;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- * @author Tom Baeyens
- * @author Ronald van Kuijk (kukeltje)
- */
-public class ScriptTaskTest 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/scriptTask.bpmn.xml");
-
- if (!problems.isEmpty()) {
- fail("No problems should have occured. Problems: " + problems);
- }
- }
-
- public void testNormalExecute() {
-
- String deploymentId = repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/bpmn/scriptTask.bpmn.xml").deploy();
-
- try {
- Map variables = new HashMap();
- String[] values = {"st", "nd", "rd", "th", "th"};
- variables.put("test", values);
-
- ProcessInstance pi = executionService.startProcessInstanceByKey("ScriptTask", variables );
- String pid = pi.getId();
-
- // process instance should be ended
- pi = executionService.findProcessInstanceById(pid);
- assertNull(pi);
-
- }
- finally {
- repositoryService.deleteDeploymentCascade(deploymentId);
- }
- }
-}
Deleted: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/scriptTask.bpmn.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/scriptTask.bpmn.xml 2009-12-17 21:30:45 UTC (rev 5983)
+++ jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/bpmn/scriptTask.bpmn.xml 2009-12-17 23:23:31 UTC (rev 5984)
@@ -1,31 +0,0 @@
-<?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 ../../../../../../../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="ScriptTask" name="ScriptTask">
- <!-- Start-Event -->
- <bpmn:startEvent id="Start" />
-
- <bpmn:sequenceFlow id="flow1" sourceRef="Start"
- targetRef="scriptTask" name="Start->ScriptTask" />
-
- <bpmn:scriptTask id="scriptTask" name="Script Task"
- scriptLanguage="bsh" >
- <bpmn:script><![CDATA[
-for(int i=0;i<5;i++){
- System.out.println((i+1) + test[i] + " universe");
-}]]>
-</bpmn:script>
- </bpmn:scriptTask>
- <bpmn:sequenceFlow id="flow2" sourceRef="scriptTask"
- targetRef="End" />
-
- <!-- End Events -->
- <bpmn:endEvent id="End" name="End" />
- </bpmn:process>
-</bpmn:definitions>
More information about the jbpm-commits
mailing list