JBoss JBPM SVN: r6405 - jbpm4/trunk/modules/userguide/src/main/docbook/en/modules.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-06-11 14:05:08 -0400 (Fri, 11 Jun 2010)
New Revision: 6405
Modified:
jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch07-Variables.xml
Log:
JBPM-2776: documentation for variable declaration and history support
Modified: jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch07-Variables.xml
===================================================================
--- jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch07-Variables.xml 2010-06-11 13:11:04 UTC (rev 6404)
+++ jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch07-Variables.xml 2010-06-11 18:05:08 UTC (rev 6405)
@@ -114,4 +114,143 @@
</para>
</section>
+ <section>
+ <title>Declared variables</title>
+ <para>(Since jBPM 4.4)</para>
+ <para>
+ Variables can be declared directly in process definition (JPDL). These variables
+ will be created at process instance startup. There can be more than one variable definition.
+ </para>
+ <para>There are several possible ways for declaring variable:</para>
+ <itemizedlist>
+ <listitem>declare <literal>String</literal> variable initialized with static text
+ <programlisting>
+<variable name="declaredVar" type="string" init-expr="testing declared variable"/>
+ </programlisting>
+ </listitem>
+ <listitem>declare <literal>custom</literal> variable initialized with EL
+ <programlisting>
+<variable name="declaredVar" type="long" init-expr="#{anotherVar}"/>
+ </programlisting>
+ </listitem>
+ <listitem>declare <literal>custom</literal> variable initialized with serializable class
+ <programlisting>
+<variable name="declaredVar" type="serializable" >
+ <object class="org.jbpm.examples.variable.declared.HistoryVariable" />
+</variable>
+ </programlisting>
+ </listitem>
+ </itemizedlist>
+ <para>As shown above variable values can be assigned in two ways: using attribute <literal>init-expr</literal> or
+ by nesting init descriptor (element <literal>object</literal>) within variable tags.
+ </para>
+ <para>
+ Note: Only one of value assignment can be used for a variable declaration.
+ </para>
+ <table><title>Attribute for <literal>variable</literal> element:</title>
+ <tgroup cols="5" rowsep="1" colsep="1">
+ <thead>
+ <row>
+ <entry>Attribute</entry>
+ <entry>Type</entry>
+ <entry>Default</entry>
+ <entry>Required?</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>name</literal></entry>
+ <entry>text</entry>
+ <entry></entry>
+ <entry><emphasis role="bold">required</emphasis></entry>
+ <entry>name of the variable</entry>
+ </row>
+ <row>
+ <entry><literal>type</literal></entry>
+ <entry>text</entry>
+ <entry></entry>
+ <entry><emphasis role="bold">required</emphasis></entry>
+ <entry>type of the variable, must refer to types defined in jbpm.variable.types.xml</entry>
+ </row>
+ <row>
+ <entry><literal>init-expr</literal></entry>
+ <entry>text (EL expression)</entry>
+ <entry></entry>
+ <entry><emphasis role="bold">optional</emphasis></entry>
+ <entry>value for the variable, this attribute or nested element must be given</entry>
+ </row>
+ <row>
+ <entry><literal>init-expr-type</literal></entry>
+ <entry>text</entry>
+ <entry>UEL</entry>
+ <entry><emphasis role="bold">optional</emphasis></entry>
+ <entry>defines language for expression evaluation</entry>
+ </row>
+ <row>
+ <entry><literal>history</literal></entry>
+ <entry>boolean</entry>
+ <entry>false</entry>
+ <entry><emphasis role="bold">optional</emphasis></entry>
+ <entry>indicates wheater variable should be stored in history or not - default false,
+ for more information about history see <xref linkend="variablehistory" /></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table><title>Nested element for <literal>variable</literal>:</title>
+ <tgroup cols="5" rowsep="1" colsep="1">
+ <thead>
+ <row>
+ <entry>Element</entry>
+ <entry>Multiplicity</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>object</literal></entry>
+ <entry>1</entry>
+ <entry>Value for the variable as custom object, either this element or <literal>init-expr</literal> attribute must be specified</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ </section>
+
+ <section id="variablehistory">
+ <title>Variables history</title>
+ <para>(Since jBPM 4.4)</para>
+
+ <para>Variables can be marked to be persisted as history records. This means that once process instance is ended and
+ its runtime information is removed, history details are preserved.
+ </para>
+ <para>History can be enabled for variable in two ways:</para>
+ <itemizedlist>
+ <listitem>via public API <literal>ExecutionService</literal>:
+ <itemizedlist>
+ <listitem><literal>void createVariable(String executionId, String name, Object value, boolean historyEnabled);</literal></listitem>
+ <listitem><literal>void createVariables(String executionId, Map<String, ?> variables, boolean historyEnabled);</literal></listitem>
+ </itemizedlist>
+ </listitem>
+ <listitem>on variable declaration
+ <programlisting>
+<variable name="declaredVar" type="string" init-expr="testing declared variable" history="true"/>
+ </programlisting>
+ </listitem>
+ </itemizedlist>
+ <para>Currently all variables are persisted in history as <literal>String</literal> values.
+ Variable (regardless of its type) will be converted to a string value using <literal>toString()</literal>
+ method. In case of custom objects they should override <literal>toString()</literal> method to provide string representation
+ of the variable that will be available as history record. This will provide an easy way for enabling convienient search
+ capabilities based on variable values. </para>
+ <para>Access to history variables is given via <literal>HistoryService</literal> methods:</para>
+ <itemizedlist>
+ <listitem><literal>Object getVariable(String processInstnceId, String name);</literal></listitem>
+ <listitem><literal>Map<String, Object> getVariables(String processInstnceId, Set<String> variableNames);</literal></listitem>
+ <listitem><literal>Set<String> getVariableNames(String processInstnceId);</literal></listitem>
+ </itemizedlist>
+ </section>
+
</chapter>
13 years, 11 months
JBoss JBPM SVN: r6404 - in jbpm4/trunk: modules/test-db/src/test/java/org/jbpm/test/process and 3 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-06-11 09:11:04 -0400 (Fri, 11 Jun 2010)
New Revision: 6404
Added:
jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.xml
Removed:
jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml
Modified:
jbpm4/trunk/modules/distro/src/main/files/install/src/cfg/jbpm/standalone.testsuite.jbpm.cfg.xml
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/RepositoryServiceTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskDueDateTest.java
jbpm4/trunk/modules/test-db/src/test/resources/jbpm.cfg.xml
jbpm4/trunk/qa/jdbc/mysql.properties
Log:
JBPM-2872: fix hudson db job - mysql chapter
Modified: jbpm4/trunk/modules/distro/src/main/files/install/src/cfg/jbpm/standalone.testsuite.jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/distro/src/main/files/install/src/cfg/jbpm/standalone.testsuite.jbpm.cfg.xml 2010-06-10 19:17:23 UTC (rev 6403)
+++ jbpm4/trunk/modules/distro/src/main/files/install/src/cfg/jbpm/standalone.testsuite.jbpm.cfg.xml 2010-06-11 13:11:04 UTC (rev 6404)
@@ -9,4 +9,6 @@
<import resource="jbpm.identity.cfg.xml" />
<import resource="jbpm.businesscalendar.cfg.xml" />
+ <import resource="jbpm.mail.templates.xml" />
+
</jbpm-configuration>
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/RepositoryServiceTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/RepositoryServiceTest.java 2010-06-10 19:17:23 UTC (rev 6403)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/RepositoryServiceTest.java 2010-06-11 13:11:04 UTC (rev 6404)
@@ -21,13 +21,19 @@
*/
package org.jbpm.test.process;
+import java.sql.ResultSet;
import java.util.List;
+import org.hibernate.Session;
+
import org.jbpm.api.Execution;
import org.jbpm.api.JbpmException;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessDefinitionQuery;
import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.cmd.CommandService;
import org.jbpm.test.JbpmTestCase;
/**
@@ -379,6 +385,24 @@
* @see <a href="https://jira.jboss.org/browse/JBPM-2746">JBPM-2746</a>
*/
public void testNonLatinProcessName() {
+ processEngine.execute(new Command<Void>() {
+
+ public Void execute(Environment environment) throws Exception {
+ ResultSet resultSet = environment.get(Session.class)
+ .connection()
+ .createStatement()
+ .executeQuery("select @@character_set_client, @@character_set_connection, @@character_set_results, @@collation_connection");
+ if (resultSet.next()) {
+ log.info("character set client: " + resultSet.getString(1));
+ log.info("character set connection: " + resultSet.getString(2));
+ log.info("character set results: " + resultSet.getString(3));
+ log.info("collation connection: " + resultSet.getString(4));
+ }
+ resultSet.close();
+ return null;
+ }
+ });
+
// "Lev Trotskij"
deployJpdlXmlString("<process name='\u041B\u0435\u0412 \u0422\u0440\u043E\u0446\u043A\u0438\u0439'>" +
" <start/>" +
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskDueDateTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskDueDateTest.java 2010-06-10 19:17:23 UTC (rev 6403)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskDueDateTest.java 2010-06-11 13:11:04 UTC (rev 6404)
@@ -47,6 +47,7 @@
Calendar tomorrow = Calendar.getInstance();
tomorrow.add(Calendar.DATE, 1);
+ tomorrow.set(Calendar.MILLISECOND, 0); // mysql does not capture subsecond times
Map<String, ? > variables = Collections.singletonMap("tomorrow", tomorrow);
String processInstanceId = executionService.startProcessInstanceByKey("BaseDate", variables)
.getId();
@@ -69,6 +70,7 @@
Calendar tomorrow = Calendar.getInstance();
tomorrow.add(Calendar.DATE, 1);
+ tomorrow.set(Calendar.MILLISECOND, 0); // mysql does not capture subsecond times
Map<String, ? > variables = Collections.singletonMap("tomorrow", tomorrow);
String processInstanceId = executionService.startProcessInstanceByKey(
"BaseDatePlusDuration", variables).getId();
@@ -92,6 +94,7 @@
Calendar tomorrow = Calendar.getInstance();
tomorrow.add(Calendar.DATE, 1);
+ tomorrow.set(Calendar.MILLISECOND, 0); // mysql does not capture subsecond times
Map<String, ? > variables = Collections.singletonMap("tomorrow", tomorrow);
String processInstanceId = executionService.startProcessInstanceByKey(
"BaseDateMinusDuration", variables).getId();
Modified: jbpm4/trunk/modules/test-db/src/test/resources/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/jbpm.cfg.xml 2010-06-10 19:17:23 UTC (rev 6403)
+++ jbpm4/trunk/modules/test-db/src/test/resources/jbpm.cfg.xml 2010-06-11 13:11:04 UTC (rev 6404)
@@ -9,6 +9,6 @@
<import resource="jbpm.bpmn.cfg.xml" />
<import resource="jbpm.identity.cfg.xml" />
- <import resource="jbpm.mail.templates.examples.xml" />
+ <import resource="jbpm.mail.templates.xml" />
</jbpm-configuration>
Deleted: jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml 2010-06-10 19:17:23 UTC (rev 6403)
+++ jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml 2010-06-11 13:11:04 UTC (rev 6404)
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<jbpm-configuration>
-
- <process-engine-context>
-
- <mail-template name="rectify-template">
- <to addresses="${addressee}" />
- <cc users="bb" groups="innerparty" />
- <subject>rectify ${newspaper}</subject>
- <text>${newspaper} ${date} ${details}</text>
- </mail-template>
-
- </process-engine-context>
-
-</jbpm-configuration>
Copied: jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.xml (from rev 6386, jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.examples.xml)
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.xml (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/resources/jbpm.mail.templates.xml 2010-06-11 13:11:04 UTC (rev 6404)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<jbpm-configuration>
+
+ <process-engine-context>
+
+ <mail-template name="rectify-template">
+ <to addresses="${addressee}" />
+ <cc users="bb" groups="innerparty" />
+ <subject>rectify ${newspaper}</subject>
+ <text>${newspaper} ${date} ${details}</text>
+ </mail-template>
+
+ </process-engine-context>
+
+</jbpm-configuration>
Modified: jbpm4/trunk/qa/jdbc/mysql.properties
===================================================================
--- jbpm4/trunk/qa/jdbc/mysql.properties 2010-06-10 19:17:23 UTC (rev 6403)
+++ jbpm4/trunk/qa/jdbc/mysql.properties 2010-06-11 13:11:04 UTC (rev 6404)
@@ -1,4 +1,4 @@
jdbc.driver=com.mysql.jdbc.Driver
-jdbc.url=jdbc:mysql://vmg02.mw.lab.eng.bos.redhat.com:3306/pvm1
+jdbc.url=jdbc:mysql://vmg02.mw.lab.eng.bos.redhat.com:3306/pvm1?characterEncoding=utf8
jdbc.username=pvm1
jdbc.password=pvm1
13 years, 11 months
JBoss JBPM SVN: r6403 - in jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal: hibernate and 1 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-06-10 15:17:23 -0400 (Thu, 10 Jun 2010)
New Revision: 6403
Removed:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindLatestProcessDefinitionByKeyCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionByIdCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionKeysCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionsByKeyCmd.java
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
Log:
JBPM-2584: remove obsolete, database-related, process definition commands
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java 2010-06-10 18:43:18 UTC (rev 6402)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessDefinitionCmd.java 2010-06-10 19:17:23 UTC (rev 6403)
@@ -1,59 +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.pvm.internal.cmd;
-
-import org.jbpm.api.JbpmException;
-import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.session.DbSession;
-import org.jbpm.pvm.internal.wire.binding.DbSessionBinding;
-
-
-/**
- * @author Tom Baeyens
- */
-public class DeleteProcessDefinitionCmd extends AbstractCommand<Void> {
-
- private static final long serialVersionUID = 1L;
-
- String processDefinitionId;
- boolean deleteProcessInstances;
- boolean deleteHistory;
-
- public DeleteProcessDefinitionCmd(String processDefinitionId) {
- this(processDefinitionId, false, false);
- }
-
- public DeleteProcessDefinitionCmd(String processDefinitionId, boolean deleteProcessInstances, boolean deleteHistory) {
- this.processDefinitionId = processDefinitionId;
- this.deleteProcessInstances = deleteProcessInstances;
- this.deleteHistory = deleteHistory;
- }
-
- public Void execute(Environment environment) {
- DbSession dbSession = environment.get(DbSession.class);
- if (dbSession==null) {
- throw new JbpmException("no "+DbSessionBinding.TAG+" configured");
- }
- dbSession.deleteProcessDefinition(processDefinitionId, deleteProcessInstances, deleteHistory);
- return null;
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindLatestProcessDefinitionByKeyCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindLatestProcessDefinitionByKeyCmd.java 2010-06-10 18:43:18 UTC (rev 6402)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindLatestProcessDefinitionByKeyCmd.java 2010-06-10 19:17:23 UTC (rev 6403)
@@ -1,48 +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.pvm.internal.cmd;
-
-import org.jbpm.api.ProcessDefinition;
-import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.model.OpenProcessDefinition;
-import org.jbpm.pvm.internal.session.DbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class FindLatestProcessDefinitionByKeyCmd extends AbstractCommand<ProcessDefinition> {
-
- private static final long serialVersionUID = 1L;
-
- protected String processDefinitionKey;
-
- public FindLatestProcessDefinitionByKeyCmd(String processDefinitionKey) {
- this.processDefinitionKey = processDefinitionKey;
- }
-
- public OpenProcessDefinition execute(Environment environment) throws Exception {
- return environment
- .get(DbSession.class)
- .findLatestProcessDefinitionByKey(processDefinitionKey);
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionByIdCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionByIdCmd.java 2010-06-10 18:43:18 UTC (rev 6402)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionByIdCmd.java 2010-06-10 19:17:23 UTC (rev 6403)
@@ -1,47 +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.pvm.internal.cmd;
-
-import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.model.OpenProcessDefinition;
-import org.jbpm.pvm.internal.session.DbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class FindProcessDefinitionByIdCmd extends AbstractCommand<OpenProcessDefinition> {
-
- private static final long serialVersionUID = 1L;
-
- protected String processDefinitionId;
-
- public FindProcessDefinitionByIdCmd(String processDefinitionId) {
- this.processDefinitionId = processDefinitionId;
- }
-
- public OpenProcessDefinition execute(Environment environment) throws Exception {
- return environment
- .get(DbSession.class)
- .findProcessDefinitionById(processDefinitionId);
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionKeysCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionKeysCmd.java 2010-06-10 18:43:18 UTC (rev 6402)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionKeysCmd.java 2010-06-10 19:17:23 UTC (rev 6403)
@@ -1,43 +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.pvm.internal.cmd;
-
-import java.util.List;
-
-import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.session.DbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class FindProcessDefinitionKeysCmd extends AbstractCommand<List<String>> {
-
- private static final long serialVersionUID = 1L;
-
- public List<String> execute(Environment environment) throws Exception {
- return environment
- .get(DbSession.class)
- .findProcessDefinitionKeys();
- }
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionsByKeyCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionsByKeyCmd.java 2010-06-10 18:43:18 UTC (rev 6402)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/FindProcessDefinitionsByKeyCmd.java 2010-06-10 19:17:23 UTC (rev 6403)
@@ -1,49 +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.pvm.internal.cmd;
-
-import java.util.List;
-
-import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.client.ClientProcessDefinition;
-import org.jbpm.pvm.internal.session.DbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class FindProcessDefinitionsByKeyCmd extends AbstractCommand<List<ClientProcessDefinition>> {
-
- private static final long serialVersionUID = 1L;
-
- protected String processDefinitionKey;
-
- public FindProcessDefinitionsByKeyCmd(String processDefinitionKey) {
- this.processDefinitionKey = processDefinitionKey;
- }
-
- public List<ClientProcessDefinition> execute(Environment environment) throws Exception {
- return environment
- .get(DbSession.class)
- .findProcessDefinitionsByKey(processDefinitionKey);
- }
-}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java 2010-06-10 18:43:18 UTC (rev 6402)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java 2010-06-10 19:17:23 UTC (rev 6403)
@@ -29,15 +29,14 @@
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.metadata.ClassMetadata;
+
import org.jbpm.api.Execution;
import org.jbpm.api.JbpmException;
-import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.history.HistoryComment;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.task.Task;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.client.ClientExecution;
-import org.jbpm.pvm.internal.client.ClientProcessDefinition;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.history.model.HistoryCommentImpl;
import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
@@ -109,62 +108,6 @@
this.session = session;
}
- public List<String> findProcessDefinitionKeys() {
- return session.getNamedQuery("findProcessDefinitionKeys").list();
- }
-
- public ClientProcessDefinition findLatestProcessDefinitionByKey(String processDefinitionKey) {
- Query query = session.getNamedQuery("findProcessDefinitionsByKey");
- query.setString("key", processDefinitionKey);
- query.setMaxResults(1);
- ClientProcessDefinition processDefinition = (ClientProcessDefinition) query.uniqueResult();
- return processDefinition;
- }
-
- public List<ClientProcessDefinition> findProcessDefinitionsByKey(String processDefinitionKey) {
- Query query = session.getNamedQuery("findProcessDefinitionsByKey");
- query.setString("key", processDefinitionKey);
- return query.list();
- }
-
- public ClientProcessDefinition findProcessDefinitionById(String processDefinitionId) {
- Query query = session.getNamedQuery("findProcessDefinitionById");
- query.setString("id", processDefinitionId);
- query.setMaxResults(1);
- ClientProcessDefinition processDefinition = (ClientProcessDefinition) query.uniqueResult();
- return processDefinition;
- }
-
- public void deleteProcessDefinition(String processDefinitionId, boolean deleteProcessInstances, boolean deleteHistory) {
- List<String> processInstanceIds = findProcessInstanceIds(processDefinitionId);
-
- if ( deleteHistory
- // and if hibernate knows about the history class
- && (isHistoryEnabled())
- ) {
- List<HistoryProcessInstance> historyProcessInstances = createHistoryProcessInstanceQuery()
- .processDefinitionId(processDefinitionId)
- .list();
-
- for (HistoryProcessInstance historyProcessInstance : historyProcessInstances) {
- session.delete(historyProcessInstance);
- }
- }
-
- if (deleteProcessInstances) {
- for (String processInstanceId : processInstanceIds) {
- deleteProcessInstance(processInstanceId, deleteHistory);
- }
- } else {
- if (processInstanceIds.size()>0) {
- throw new JbpmException("still "+processInstanceIds.size()+" process instances for process definition "+processDefinitionId);
- }
- }
-
- ProcessDefinition processDefinition = findProcessDefinitionById(processDefinitionId);
- session.delete(processDefinition);
- }
-
public void deleteProcessDefinitionHistory(String processDefinitionId) {
List<HistoryProcessInstanceImpl> historyProcessInstances =
session.createQuery(
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java 2010-06-10 18:43:18 UTC (rev 6402)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java 2010-06-10 19:17:23 UTC (rev 6403)
@@ -26,11 +26,9 @@
import org.jbpm.api.Execution;
import org.jbpm.api.history.HistoryComment;
import org.jbpm.pvm.internal.client.ClientExecution;
-import org.jbpm.pvm.internal.client.ClientProcessDefinition;
import org.jbpm.pvm.internal.job.JobImpl;
import org.jbpm.pvm.internal.job.StartProcessTimer;
import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
import org.jbpm.pvm.internal.query.DeploymentQueryImpl;
import org.jbpm.pvm.internal.query.HistoryActivityInstanceQueryImpl;
import org.jbpm.pvm.internal.query.HistoryDetailQueryImpl;
@@ -39,11 +37,7 @@
import org.jbpm.pvm.internal.query.ProcessInstanceQueryImpl;
import org.jbpm.pvm.internal.query.TaskQueryImpl;
import org.jbpm.pvm.internal.task.TaskImpl;
-import org.jbpm.pvm.internal.tx.JtaTransaction;
-import org.jbpm.pvm.internal.tx.StandardTransaction;
-import org.jbpm.pvm.internal.type.Variable;
-
/**
* @author Tom Baeyens
*/
@@ -56,22 +50,6 @@
void delete(Object entity);
void flush();
- /** all deployed process names. */
- List<String> findProcessDefinitionKeys();
-
- /** latest version of the processDefinition for the given key. */
- ClientProcessDefinition findLatestProcessDefinitionByKey(String processDefinitionKey);
-
- /** all versions of the processDefinition for the given key. */
- List<ClientProcessDefinition> findProcessDefinitionsByKey(String processDefinitionKey);
-
- /** the process definition uniquely identified by the given
- * processDefinition id. */
- ClientProcessDefinition findProcessDefinitionById(String processDefinitionId);
-
- /** delete process definition */
- void deleteProcessDefinition(String processDefinitionId, boolean deleteProcessInstances, boolean deleteHistory);
-
// process execution queries ////////////////////////////////////////////////
/** create a process instance query */
13 years, 11 months
JBoss JBPM SVN: r6402 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/cmd and 5 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-06-10 14:43:18 -0400 (Thu, 10 Jun 2010)
New Revision: 6402
Removed:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
Log:
JBPM-2506: reapply variable history patch
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -104,17 +104,17 @@
* queries that include finished process instances. */
ProcessInstanceQuery createProcessInstanceQuery();
- /** creates or overwrites a variable value on the referenced execution */
+ /** creates or overwrites a variable value in the referenced execution */
void setVariable(String executionId, String name, Object value);
- /** creates or overwrites the variable values on the referenced execution */
+ /** creates or overwrites variable values in the referenced execution */
void setVariables(String executionId, Map<String, ?> variables);
- /** creates or overwrites a variable value on the referenced execution and marks the variable to be stored in history*/
- void setVariable(String executionId, String name, Object value, boolean historyEnabled);
+ /** creates a variable value in the referenced execution. optionally enables variable history tracking. */
+ void createVariable(String executionId, String name, Object value, boolean historyEnabled);
- /** creates or overwrites the variable values on the referenced execution and marks the variables to be stored in history*/
- void setVariables(String executionId, Map<String, ?> variables, boolean historyEnabled);
+ /** creates variable values in the referenced execution. optionally enables variable history tracking. */
+ void createVariables(String executionId, Map<String, ?> variables, boolean historyEnabled);
/** retrieves a variable */
Object getVariable(String executionId, String variableName);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -24,12 +24,9 @@
import org.jbpm.api.JbpmException;
import org.jbpm.api.cmd.Environment;
import org.jbpm.pvm.internal.client.ClientExecution;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-
/**
* @author Tom Baeyens
- * @author Maciej Swiderski
*/
public class SetExecutionVariablesCmd extends VariablesCmd<Void> {
@@ -46,12 +43,7 @@
public Void execute(Environment environment) throws Exception {
ClientExecution execution = getExecution(environment, executionId);
- if (isHistoryEnabled()) {
- ((ExecutionImpl) execution).setVariables(variables, historyEnabled);
- } else {
- execution.setVariables(variables);
- }
-
+ execution.setVariables(variables);
return null;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -38,9 +38,7 @@
protected Map<String, ?> variables;
private Map<String, Object> internalMap;
- protected boolean historyEnabled;
-
public void addVariable(String key, Object variable) {
if (internalMap == null) {
if (variables != null) {
@@ -59,14 +57,6 @@
this.variables = variables;
}
- public boolean isHistoryEnabled() {
- return historyEnabled;
- }
-
- public void setHistoryEnabled(boolean historyEnabled) {
- this.historyEnabled = historyEnabled;
- }
-
protected ClientExecution getExecution(Environment environment, String executionId) {
DbSession dbSession = environment.get(DbSession.class);
ClientExecution execution = dbSession.findExecutionById(executionId);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -99,7 +99,7 @@
}
protected Variable createVariableObject(String key, Object value, String typeName, boolean isHistoryEnabled) {
- log.debug("create variable '"+key+"' in '"+this+"' with value '"+value+"' history enabled " + isHistoryEnabled);
+ log.debug("create variable '"+key+"' in '"+this+"' with value '"+value+"'");
Type type = null;
@@ -144,7 +144,6 @@
variable.setHistoryEnabled(isHistoryEnabled);
variable.setValue(value, this);
-
long dbid = DbidGenerator.getDbidGenerator().getNextId();
variable.setDbid(dbid);
@@ -152,15 +151,10 @@
HistoryEvent.fire(new VariableCreate(variable));
}
-
return variable;
}
-
- public void setVariable(String key, Object value) {
- setVariable(key, value, false);
- }
- public void setVariable(String key, Object value, boolean historyEnabled) {
+ public void setVariable(String key, Object value) {
if (key==null) {
throw new JbpmException("variableName is null");
}
@@ -179,22 +173,17 @@
if (variable!=null) {
log.debug("updating variable '"+key+"' in '"+this+"' to value '"+value+"'");
variable.setValue(value, this);
-
} else if (getParentVariableScope()==null) {
- createVariable(key, value, null, historyEnabled);
-
+ createVariable(key, value, null, false);
} else {
- getParentVariableScope().setVariable(key,value, historyEnabled);
+ getParentVariableScope().setVariable(key,value);
}
}
+
public void setVariables(Map<String, ?> variables) {
- setVariables(variables, false);
- }
-
- public void setVariables(Map<String, ?> variables, boolean historyEnabled) {
if (variables!=null) {
for (Map.Entry<String, ?> entry : variables.entrySet()) {
- setVariable(entry.getKey(), entry.getValue(), historyEnabled);
+ setVariable(entry.getKey(), entry.getValue());
}
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -152,17 +152,15 @@
commandService.execute(cmd);
}
- public void setVariable(String executionId, String name, Object value, boolean historyEnabled) {
- SetExecutionVariablesCmd cmd = new SetExecutionVariablesCmd(executionId);
+ public void createVariable(String executionId, String name, Object value, boolean historyEnabled) {
+ CreateExecutionVariablesCmd cmd = new CreateExecutionVariablesCmd(executionId, historyEnabled);
cmd.addVariable(name, value);
- cmd.setHistoryEnabled(historyEnabled);
commandService.execute(cmd);
}
- public void setVariables(String executionId, Map<String, ?> variables, boolean historyEnabled) {
- SetExecutionVariablesCmd cmd = new SetExecutionVariablesCmd(executionId);
+ public void createVariables(String executionId, Map<String, ?> variables, boolean historyEnabled) {
+ CreateExecutionVariablesCmd cmd = new CreateExecutionVariablesCmd(executionId, historyEnabled);
cmd.setVariables(variables);
- cmd.setHistoryEnabled(historyEnabled);
commandService.execute(cmd);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -81,21 +81,19 @@
query.setCommandService(commandService);
return query;
}
-
+
public Set<String> getVariableNames(String processInstanceId) {
return commandService.execute(new GetHistoryVariableNamesCmd(processInstanceId));
}
-
+
public Object getVariable(String processInstanceId, String variableName) {
Set<String> variableNames = new HashSet<String>();
variableNames.add(variableName);
Map<String, Object> variables = commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
return variables.get(variableName);
}
-
- public Map<String, Object> getVariables(String processInstanceId, Set<String> variableNames) {
+ public Map<String, Object> getVariables(String processInstanceId, Set<String> variableNames) {
return commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
-
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -79,29 +79,25 @@
public void setValue(Object value, ScopeInstanceImpl scopeInstance) {
if (converter!=null) {
- if (! converter.supports(value, scopeInstance, this)) {
+ if (!converter.supports(value, scopeInstance, this)) {
throw new JbpmException("the converter '"+converter.getClass().getName()+"' in variable instance '"+this.getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'. to change the type of a variable, you have to delete it first");
}
value = converter.convert(value, scopeInstance, this);
}
- if ( (value!=null)
- && (! this.isStorable(value)) ) {
- throw new JbpmException("variable instance '"+this.getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'. to change the type of a variable, you have to delete it first");
+ if (value!=null && !isStorable(value)) {
+ throw new JbpmException("variable instance '"+getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'. to change the type of a variable, you have to delete it first");
}
setObject(value);
HistorySession historySession = EnvironmentImpl.getFromCurrent(HistorySession.class, false);
- if ( isHistoryEnabled
- && (historySession!=null) && (this.getDbid() != -1)
- ) {
+ if (isHistoryEnabled && historySession!=null && getDbid()!=-1) {
HistoryEvent.fire(new VariableUpdate(this));
}
}
public Object getValue(ScopeInstanceImpl scopeInstance) {
Object value = getObject();
- if ( (value!=null)
- && (converter!=null) ) {
+ if (value!=null && converter!=null) {
value = converter.revert(value, scopeInstance, this);
}
return value;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -65,8 +65,7 @@
public void setValue(Object value, ScopeInstanceImpl scopeInstance) {
super.setValue(value, scopeInstance);
cachedValue = value;
- this.textValue = value.toString();
-
+ textValue = value.toString();
}
public Lob getLob() {
Deleted: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -1,33 +0,0 @@
-package org.jbpm.test.variables;
-
-import java.io.Serializable;
-
-
-public class HistoryVariable implements Serializable {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- private String name;
-
-
- public String getName() {
- return name;
- }
-
-
- public void setName(String name) {
- this.name = name;
- }
-
- public HistoryVariable() {
- this.name = "Poul";
- }
-
-
- @Override
- public String toString() {
- return "my name is Poul";
- }
-}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java 2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java 2010-06-10 18:43:18 UTC (rev 6402)
@@ -1,232 +1,202 @@
-package org.jbpm.test.variables;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.jbpm.test.JbpmTestCase;
-
-
-public class HistoryVariableTest extends JbpmTestCase {
-
- public void testDeclaredVariableWithHistory() {
- deployJpdlXmlString(
- "<process name='var'>" +
- " <variable name='test' type='string' init-expr='test value' history='true'/>"+
- " <start name='a'>" +
- " <transition to='b' />" +
- " </start>" +
- " <state name='b'/>" +
- "</process>"
- );
-
- executionService.startProcessInstanceByKey("var", "one");
-
- Set<String> variableNames = executionService.getVariableNames("var.one");
- String testVariableValue = (String) executionService.getVariable("var.one", "test");
- assertNotNull(variableNames);
- assertEquals(1, variableNames.size());
- assertEquals("test", variableNames.iterator().next());
- assertEquals("test value", testVariableValue);
!
-
- Set<String> historyVariables = historyService.getVariableNames("var.one");
- assertEquals(1, historyVariables.size());
- assertEquals("test", historyVariables.iterator().next());
-
-
- String value = (String) historyService.getVariable("var.one", "test");
- assertEquals("test value", value);
-
- }
-
- public void testSetVariableViaAPIwithHistory() {
- deployJpdlXmlString(
- "<process name='var'>" +
- " <start name='a'>" +
- " <transition to='b' />" +
- " </start>" +
- " <state name='b'/>" +
- "</process>");
-
- executionService.startProcessInstanceByKey("var", "one");
-
- executionService.setVariable("var.one", "test2", "test3", true);
-
- Set<String> variableNames = executionService.getVariableNames("var.one");
- String testVariableValue = (String) executionService.getVariable("var.one", "test2");
- assertNotNull(variableNames);
- assertEquals(1,!
variableNames.size());
- assertEquals("test2", variableNam!
es.itera
tor().next());
- assertEquals("test3", testVariableValue);
-
- Set<String> historyVariables = historyService.getVariableNames("var.one");
- assertEquals(1, historyVariables.size());
- assertEquals("test2", historyVariables.iterator().next());
-
- String value = (String) historyService.getVariable("var.one", "test2");
- assertEquals("test3", value);
- }
-
- public void testSetVariablesViaAPIwithHistory() {
- deployJpdlXmlString(
- "<process name='var'>" +
- " <start name='a'>" +
- " <transition to='b' />" +
- " </start>" +
- " <state name='b'/>" +
- "</process>");
-
- executionService.startProcessInstanceByKey("var", "one");
-
- Map<String, String> simpleVariables = new HashMap<String, String>();
- simpleVariables.put("simple-var", "hello history");
- simpleVariables.put("test-var", "good day");
- simpleVariables.put("my-var", "cheers");
-
- executionService!
.setVariables("var.one", simpleVariables, true);
-
- Set<String> variableNames = executionService.getVariableNames("var.one");
-
- assertNotNull(variableNames);
- assertEquals(3, variableNames.size());
-
- String testVariableValue = (String) executionService.getVariable("var.one", "test-var");
- assertEquals("good day", testVariableValue);
-
- Set<String> historyVariables = historyService.getVariableNames("var.one");
- assertEquals(3, historyVariables.size());
-
- String value = (String) historyService.getVariable("var.one", "simple-var");
- assertEquals("hello history", value);
- }
-
- public void testDeclaredVariablesWithHistory() {
- deployJpdlXmlString(
- "<process name='var'>" +
- " <variable name='test' type='string' init-expr='test value' history='true'/>"+
- " <variable name='real' type='string' init-expr='real value' history='true'/>"+
- " <start name='a'>" +
- " <transition to='b' />" +
- !
" </start>" +
- " <state name='b'/>" +
- "</proces!
s>"
-
);
-
- executionService.startProcessInstanceByKey("var", "one");
-
- Set<String> variableNames = executionService.getVariableNames("var.one");
-
- assertNotNull(variableNames);
- assertEquals(2, variableNames.size());
-
- String testVariableValue = (String) executionService.getVariable("var.one", "test");
- assertEquals("test value", testVariableValue);
-
- Set<String> historyVariables = historyService.getVariableNames("var.one");
- assertEquals(2, historyVariables.size());
-
-
- String value = (String) historyService.getVariable("var.one", "real");
- assertEquals("real value", value);
-
- }
-
- public void testDeclaredVariablesMixed() {
- deployJpdlXmlString(
- "<process name='var'>" +
- " <variable name='test' type='string' init-expr='test value' history='true'/>"+
- " <variable name='real' type='string' init-expr='real value' history='false'/>"+
- " <start name='a'>" +
- " <tran!
sition to='b' />" +
- " </start>" +
- " <state name='b'/>" +
- "</process>"
- );
-
- executionService.startProcessInstanceByKey("var", "one");
-
- Set<String> variableNames = executionService.getVariableNames("var.one");
-
- assertNotNull(variableNames);
- assertEquals(2, variableNames.size());
-
- String testVariableValue = (String) executionService.getVariable("var.one", "test");
- assertEquals("test value", testVariableValue);
-
- Set<String> historyVariables = historyService.getVariableNames("var.one");
- assertEquals(1, historyVariables.size());
-
-
- String value = (String) historyService.getVariable("var.one", "test");
- assertEquals("test value", value);
-
- assertNull(historyService.getVariable("var.one", "real"));
-
- }
-
- public void testDeclaredELVariableWithHistory() {
- deployJpdlXmlString(
- "<process name='var'>" +
- " <variable name='test' type='integer' i!
nit-expr='#{testV}' history='true'/>"+
- " <start name='!
a'>" +
-
" <transition to='b' />" +
- " </start>" +
- " <state name='b'/>" +
- "</process>"
- );
- HashMap<String, Integer> vars = new HashMap<String, Integer>();
- vars.put("testV", 35);
- executionService.startProcessInstanceByKey("var", vars, "one");
-
- Set<String> variableNames = executionService.getVariableNames("var.one");
- Integer testVariableValue = (Integer) executionService.getVariable("var.one", "test");
- assertNotNull(variableNames);
- assertEquals(2, variableNames.size());
- assertEquals("test", variableNames.iterator().next());
- assertTrue(35 == testVariableValue);
-
- Set<String> historyVariables = historyService.getVariableNames("var.one");
- assertEquals(1, historyVariables.size());
- assertEquals("test", historyVariables.iterator().next());
-
-
- String value = (String) historyService.getVariable("var.one", "test");
- assertEquals("35", value);
-
- }
-
- public void testDe!
claredSerializableVariableWithHistory() {
- deployJpdlXmlString(
- "<process name='var'>" +
- " <variable name='test' type='serializable' history='true'>" +
- " <object class='org.jbpm.test.variables.HistoryVariable' />" +
- " </variable>"+
- " <start name='a'>" +
- " <transition to='b' />" +
- " </start>" +
- " <state name='b'/>" +
- "</process>"
- );
-
- executionService.startProcessInstanceByKey("var", "one");
-
- Set<String> variableNames = executionService.getVariableNames("var.one");
- HistoryVariable testVariableValue = (HistoryVariable) executionService.getVariable("var.one", "test");
- assertNotNull(variableNames);
- assertEquals(1, variableNames.size());
- assertEquals("test", variableNames.iterator().next());
- assertNotNull(testVariableValue);
- assertEquals("Poul", testVariableValue.getName());
-
- Set<String> historyVariables = historyService.getVariableNames("var.!
one");
- assertEquals(1, historyVariables.size());
- ass!
ertEqual
s("test", historyVariables.iterator().next());
-
-
- String value = (String) historyService.getVariable("var.one", "test");
- assertEquals("my name is Poul", value);
-
- }
-}
-
-
+package org.jbpm.test.variables;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.test.JbpmTestCase;
+
+public class HistoryVariableTest extends JbpmTestCase {
+
+ public void testDeclaredVariableWithHistory() {
+ deployJpdlXmlString("<process name='var'>"
+ + " <variable name='test' type='string' init-expr='history' history='true'/>"
+ + " <start name='a'>"
+ + " <transition to='b' />"
+ + " </start>"
+ + " <state name='b'/>"
+ + "</process>");
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ assertEquals(1, variableNames.size());
+ assertEquals("test", variableNames.iterator().next());
+
+ String executionValue = (String) executionService.getVariable("var.one", "test");
+ assertEquals("history", executionValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+ assertEquals("test", historyVariables.iterator().next());
+
+ String historyValue = (String) historyService.getVariable("var.one", "test");
+ assertEquals("history", historyValue);
+ }
+
+ public void testDeclaredVariablesWithHistory() {
+ deployJpdlXmlString("<process name='var'>"
+ + " <variable name='test' type='string' init-expr='test value' history='true'/>"
+ + " <variable name='real' type='string' init-expr='real value' history='true'/>"
+ + " <start name='a'>"
+ + " <transition to='b' />"
+ + " </start>"
+ + " <state name='b'/>"
+ + "</process>");
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ assertEquals(2, variableNames.size());
+
+ String executionValue = (String) executionService.getVariable("var.one", "test");
+ assertEquals("test value", executionValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(2, historyVariables.size());
+
+ String historyValue = (String) historyService.getVariable("var.one", "real");
+ assertEquals("real value", historyValue);
+ }
+
+ public void testCreateVariableWithHistory() {
+ deployJpdlXmlString("<process name='var'>"
+ + " <start name='a'>"
+ + " <transition to='b' />"
+ + " </start>"
+ + " <state name='b'/>"
+ + "</process>");
+
+ executionService.startProcessInstanceByKey("var", "one");
+ executionService.createVariable("var.one", "test2", "test3", true);
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ assertEquals(1, variableNames.size());
+ assertEquals("test2", variableNames.iterator().next());
+
+ String executionValue = (String) executionService.getVariable("var.one", "test2");
+ assertEquals("test3", executionValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+ assertEquals("test2", historyVariables.iterator().next());
+
+ String historyValue = (String) historyService.getVariable("var.one", "test2");
+ assertEquals("test3", historyValue);
+ }
+
+ public void testCreateVariablesWithHistory() {
+ deployJpdlXmlString("<process name='var'>"
+ + " <start name='a'>"
+ + " <transition to='b' />"
+ + " </start>"
+ + " <state name='b'/>"
+ + "</process>");
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Map<String, String> variables = new HashMap<String, String>();
+ variables.put("simple-var", "hello history");
+ variables.put("test-var", "good day");
+ variables.put("my-var", "cheers");
+ executionService.createVariables("var.one", variables, true);
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ assertEquals(3, variableNames.size());
+
+ String executionValue = (String) executionService.getVariable("var.one", "test-var");
+ assertEquals("good day", executionValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(3, historyVariables.size());
+
+ String historyValue = (String) historyService.getVariable("var.one", "simple-var");
+ assertEquals("hello history", historyValue);
+ }
+
+ public void testDeclaredVariablesMixed() {
+ deployJpdlXmlString("<process name='var'>"
+ + " <variable name='test' type='string' init-expr='test value' history='true'/>"
+ + " <variable name='real' type='string' init-expr='real value' history='false'/>"
+ + " <start name='a'>"
+ + " <transition to='b' />"
+ + " </start>"
+ + " <state name='b'/>"
+ + "</process>");
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ assertEquals(2, variableNames.size());
+
+ String executionValue = (String) executionService.getVariable("var.one", "test");
+ assertEquals("test value", executionValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+
+ String historyValue = (String) historyService.getVariable("var.one", "test");
+ assertEquals("test value", historyValue);
+
+ assertNull(historyService.getVariable("var.one", "real"));
+ }
+
+ public void testDeclaredIntegerVariableWithHistory() {
+ deployJpdlXmlString("<process name='var'>"
+ + " <variable name='test' type='integer' init-expr='#{testV}' history='true'/>"
+ + " <start name='a'>"
+ + " <transition to='b' />"
+ + " </start>"
+ + " <state name='b'/>"
+ + "</process>");
+
+ Map<String, ?> vars = Collections.singletonMap("testV", 35);
+ executionService.startProcessInstanceByKey("var", vars, "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ assertEquals(2, variableNames.size());
+ assertEquals("test", variableNames.iterator().next());
+
+ Integer executionValue = (Integer) executionService.getVariable("var.one", "test");
+ assertEquals(35, executionValue.intValue());
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+ assertEquals("test", historyVariables.iterator().next());
+
+ String historyValue = (String) historyService.getVariable("var.one", "test");
+ assertEquals("35", historyValue);
+ }
+
+ public void testDeclaredSerializableVariableWithHistory() {
+ deployJpdlXmlString("<process name='var'>"
+ + " <variable name='test' type='serializable' history='true'>"
+ + " <object class='java.util.Date'>"
+ + " <constructor><arg><long value='1276086573250'/></arg></constructor>"
+ + " </object>"
+ + " </variable>"
+ + " <start name='a'>"
+ + " <transition to='b' />"
+ + " </start>"
+ + " <state name='b'/>"
+ + "</process>");
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ assertEquals(1, variableNames.size());
+ assertEquals("test", variableNames.iterator().next());
+
+ Date variableValue = (Date) executionService.getVariable("var.one", "test");
+ assertEquals(1276086573250L, variableValue.getTime());
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+ assertEquals("test", historyVariables.iterator().next());
+
+ String historyValue = (String) historyService.getVariable("var.one", "test");
+ assertEquals(variableValue.toString(), historyValue);
+ }
+}
13 years, 11 months
JBoss JBPM SVN: r6401 - in jbpm4/trunk/modules: jpdl/src/test/java/org/jbpm/jpdl/parsing and 1 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-06-10 12:58:19 -0400 (Thu, 10 Jun 2010)
New Revision: 6401
Added:
jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/ArgParsingTest.java
jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/CacheParsingTest.java
jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/MailParsingTest.java
Modified:
jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/MailTest.java
Log:
JBPM-2715: add cache attribute to wireObjectType
add wireObjectGroup to argType
derive mailType from wireObjectType
Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd 2010-06-10 16:11:57 UTC (rev 6400)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd 2010-06-10 16:58:19 UTC (rev 6401)
@@ -961,6 +961,10 @@
should be automatically wired based on matching the property names and types with the
object names and types</documentation></annotation>
</attribute>
+ <attribute name="cache" type="tns:booleanValueType">
+ <annotation><documentation>Indicates if the user code should be cached
+ </documentation></annotation>
+ </attribute>
</complexType>
<complexType name="argType">
@@ -968,6 +972,7 @@
Each 'arg' element should have exactly one child element
that represents the value of the argument.
</documentation></annotation>
+ <group ref="tns:wireObjectGroup" />
<attribute name="type" type="string">
<annotation><documentation>The java class name representing
the type of the method. This is optional and can be used to
@@ -1364,36 +1369,39 @@
</group>
<complexType name="mailType">
- <sequence>
- <element name="description" minOccurs="0" maxOccurs="unbounded" type="string" />
- <element name="from" type="tns:mailRecipientType" minOccurs="0" />
- <element name="to" type="tns:mailRecipientType" minOccurs="0" />
- <element name="cc" type="tns:mailRecipientType" minOccurs="0" />
- <element name="bcc" type="tns:mailRecipientType" minOccurs="0" />
- <element name="subject" type="string" minOccurs="0" />
- <element name="text" type="string" minOccurs="0" />
- <element name="html" type="string" minOccurs="0" />
- <element name="attachments" minOccurs="0" >
- <complexType>
- <sequence>
- <element name="attachment" maxOccurs="unbounded">
- <complexType>
- <attribute name="url" type="string">
- <annotation><documentation>URL reference to the attachment</documentation></annotation>
- </attribute>
- <attribute name="resource" type="string">
- <annotation><documentation>Name of the attachment resource on the classpath</documentation></annotation>
- </attribute>
- <attribute name="file" type="string">
- <annotation><documentation>File reference to the attachment</documentation></annotation>
- </attribute>
- </complexType>
- </element>
- </sequence>
- </complexType>
- </element>
- </sequence>
- <attribute name="template" type="tns:templateType" />
+ <complexContent>
+ <extension base="tns:wireObjectType">
+ <sequence>
+ <element name="from" type="tns:mailRecipientType" minOccurs="0" />
+ <element name="to" type="tns:mailRecipientType" minOccurs="0" />
+ <element name="cc" type="tns:mailRecipientType" minOccurs="0" />
+ <element name="bcc" type="tns:mailRecipientType" minOccurs="0" />
+ <element name="subject" type="string" minOccurs="0" />
+ <element name="text" type="string" minOccurs="0" />
+ <element name="html" type="string" minOccurs="0" />
+ <element name="attachments" minOccurs="0" >
+ <complexType>
+ <sequence>
+ <element name="attachment" maxOccurs="unbounded">
+ <complexType>
+ <attribute name="url" type="string">
+ <annotation><documentation>URL reference to the attachment</documentation></annotation>
+ </attribute>
+ <attribute name="resource" type="string">
+ <annotation><documentation>Name of the attachment resource on the classpath</documentation></annotation>
+ </attribute>
+ <attribute name="file" type="string">
+ <annotation><documentation>File reference to the attachment</documentation></annotation>
+ </attribute>
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+ </element>
+ </sequence>
+ <attribute name="template" type="tns:templateType" />
+ </extension>
+ </complexContent>
</complexType>
<complexType name="jmsType">
Added: jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/ArgParsingTest.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/ArgParsingTest.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/ArgParsingTest.java 2010-06-10 16:58:19 UTC (rev 6401)
@@ -0,0 +1,57 @@
+package org.jbpm.jpdl.parsing;
+
+import java.util.List;
+
+import org.jbpm.pvm.internal.xml.Problem;
+
+/**
+ * JBPM-2715.
+ * @author Huisheng Xu
+ */
+public class ArgParsingTest extends JpdlParseTestCase {
+
+ public void testArgOneValue() {
+ String xmlString = "<process name='MyProcess' version='1' xmlns='http://jbpm.org/jpdl/4.4'>\n"
+ + " <start name='start'>\n"
+ + " <transition name='myTransition' to='end'>\n"
+ + " <event-listener class='com.comp.MyEventListener'>\n"
+ + " <constructor>\n"
+ + " <arg type='java.lang.String'><string value='hello world'/></arg>\n"
+ + " </constructor>\n"
+ + " </event-listener>\n"
+ + " </transition>\n"
+ + " </start>\n"
+ + " <end name='end'/>\n"
+ + "</process>\n";
+
+ List<Problem> problems = jpdlParser.createParse()
+ .setString(xmlString)
+ .execute()
+ .getProblems();
+ assertEquals(0, problems.size());
+ }
+
+ public void testArgTwoValues() {
+ String xmlString = "<process name='MyProcess' version='1' xmlns='http://jbpm.org/jpdl/4.4'>\n"
+ + " <start name='start'>\n"
+ + " <transition name='myTransition' to='end'>\n"
+ + " <event-listener class='com.comp.MyEventListener'>\n"
+ + " <constructor>\n"
+ + " <arg type='java.lang.String'>\n"
+ + " <string value='hello world'/>\n"
+ + " <string value='goodbye world'/>\n"
+ + " </arg>\n"
+ + " </constructor>\n"
+ + " </event-listener>\n"
+ + " </transition>\n"
+ + " </start>\n"
+ + " <end name='end'/>\n"
+ + "</process>\n";
+
+ List<Problem> problems = jpdlParser.createParse()
+ .setString(xmlString)
+ .execute()
+ .getProblems();
+ assertEquals(1, problems.size());
+ }
+}
Property changes on: jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/ArgParsingTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/CacheParsingTest.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/CacheParsingTest.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/CacheParsingTest.java 2010-06-10 16:58:19 UTC (rev 6401)
@@ -0,0 +1,46 @@
+package org.jbpm.jpdl.parsing;
+
+import java.util.List;
+
+import org.jbpm.pvm.internal.xml.Problem;
+
+/**
+ * JBPM-2849.
+ * @author Huisheng Xu
+ */
+public class CacheParsingTest extends JpdlParseTestCase {
+
+ public void testCacheDisabled() {
+ String xmlString = "<process name='MyProsess' version='1' xmlns='http://jbpm.org/jpdl/4.4'>\n"
+ + " <start name='start'>\n"
+ + " <transition name='myTransition' to='end'>\n"
+ + " <event-listener class='com.comp.MyEventListener' cache='disabled'/>\n"
+ + " </transition>\n"
+ + " </start>\n"
+ + " <end name='end'/>\n"
+ + "</process>\n";
+
+ List<Problem> problems = jpdlParser.createParse()
+ .setString(xmlString)
+ .execute()
+ .getProblems();
+ assertEquals(0, problems.size());
+ }
+
+ public void testCachePowered() {
+ String xmlString = "<process name='MyProsess' version='1' xmlns='http://jbpm.org/jpdl/4.4'>\n"
+ + " <start name='start'>\n"
+ + " <transition name='myTransition' to='end'>\n"
+ + " <event-listener class='com.comp.MyEventListener' cache='powered'/>\n"
+ + " </transition>\n"
+ + " </start>\n"
+ + " <end name='end'/>\n"
+ + "</process>\n";
+
+ List<Problem> problems = jpdlParser.createParse()
+ .setString(xmlString)
+ .execute()
+ .getProblems();
+ assert !problems.isEmpty();
+ }
+}
Property changes on: jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/CacheParsingTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Added: jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/MailParsingTest.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/MailParsingTest.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/MailParsingTest.java 2010-06-10 16:58:19 UTC (rev 6401)
@@ -0,0 +1,30 @@
+package org.jbpm.jpdl.parsing;
+
+import java.util.List;
+
+import org.jbpm.pvm.internal.xml.Problem;
+
+/**
+ * JBPM-2843.
+ * @author Huisheng Xu
+ */
+public class MailParsingTest extends JpdlParseTestCase {
+
+ public void testMailParse() {
+ String xmlString = "<process name='MyProsess' version='1' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start name='start'>"
+ + " <transition to='mail'/>"
+ + " </start>"
+ + " <mail name='mail' lang='java' class='org.MyMailProducer'>"
+ + " <transition to='end'/>"
+ + " </mail>"
+ + " <end name='end'/>"
+ + "</process>";
+
+ List<Problem> problems = jpdlParser.createParse()
+ .setString(xmlString)
+ .execute()
+ .getProblems();
+ assertEquals(0, problems.size());
+ }
+}
Property changes on: jbpm4/trunk/modules/jpdl/src/test/java/org/jbpm/jpdl/parsing/MailParsingTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ native
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java 2010-06-10 16:11:57 UTC (rev 6400)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/CustomMailProducerTest.java 2010-06-10 16:58:19 UTC (rev 6401)
@@ -80,7 +80,7 @@
public void testCustomMailProducer() {
// deploy process
- deployJpdlXmlString("<process name='custommail'>"
+ deployJpdlXmlString("<process name='custommail' xmlns='http://jbpm.org/jpdl/4.4'>"
+ " <start>"
+ " <transition to='send mail' />"
+ " </start>"
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/MailTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/MailTest.java 2010-06-10 16:11:57 UTC (rev 6400)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/mail/MailTest.java 2010-06-10 16:58:19 UTC (rev 6401)
@@ -50,7 +50,7 @@
}
public void testMailToPlainAddress() {
- deployJpdlXmlString("<process name='plainaddress'>"
+ deployJpdlXmlString("<process name='plainaddress' xmlns='http://jbpm.org/4.3/jpdl'>"
+ " <start>"
+ " <transition to='mailtestmail' />"
+ " </start>"
13 years, 11 months
JBoss JBPM SVN: r6400 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/activity and 4 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-06-10 12:11:57 -0400 (Thu, 10 Jun 2010)
New Revision: 6400
Modified:
jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/ForkTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java
Log:
JBPM-2414: enable and fix 4.4 schema
allow multiple outgoing transitions from foreach (e.g. timers)
end execution trunk if no execution branch meets the condition
Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd 2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd 2010-06-10 16:11:57 UTC (rev 6400)
@@ -8,15 +8,15 @@
<annotation>
<documentation>Schema for jPDL 4 process descriptions;
- element process is the top level element.
+ the top level element is process.
</documentation>
</annotation>
<!-- ### PROCESS DEFINITION ############################################# -->
<element name="process">
- <annotation><documentation>A jPDL process definition description; This
- is the top level element in a jPDL process file.</documentation></annotation>
+ <annotation><documentation>jPDL process definition.
+ This is the top level element in a jPDL process file.</documentation></annotation>
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element name="description" minOccurs="0" type="string" />
@@ -29,24 +29,25 @@
<attribute name="name" use="required" type="string">
<annotation>
<documentation>
- The process name. Multiple processes can be deployed with the same name, as long as they have a different
- version.
+ The process name. Multiple processes can be deployed with the same name,
+ as long as they have a different version.
</documentation>
</annotation>
</attribute>
<attribute name="key" type="string">
<annotation>
<documentation>
- The key can be used to provide a short acronym that will replace the name as the basis for the generated
- process definition id
+ The key can be used to provide a short acronym that replaces the name as
+ the basis for the generated process definition id.
</documentation>
</annotation>
</attribute>
<attribute name="version" type="int">
<annotation>
<documentation>
- Indicates the sequence number of this version for all processes with the same name. By specifying a version
- automatic deployment can figure out if this process is already deployed or not.
+ Indicates the version number of this process definition among its homonyms.
+ By specifying a version, automatic deployment can tell whether this process
+ is already deployed.
</documentation>
</annotation>
</attribute>
@@ -218,7 +219,7 @@
</complexType>
</element>
- <!-- ~~~ FORK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
+ <!-- ~~~ FOREACH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<element name="foreach">
<annotation><documentation>Spawns concurrent paths of execution
over each element of a collection.
@@ -230,7 +231,7 @@
<element ref="tns:transition" minOccurs="0" maxOccurs="unbounded" />
</sequence>
<attributeGroup ref="tns:activityAttributes" />
- <attribute name="var" type="string" default="var"/>
+ <attribute name="var" type="string" use="required"/>
<attribute name="in" type="string" use="required"/>
</complexType>
</element>
@@ -409,24 +410,23 @@
<extension base="tns:wireObjectType">
<sequence>
<element ref="tns:on" minOccurs="0" maxOccurs="unbounded"/>
- <element ref="tns:transition" minOccurs="0" maxOccurs="unbounded" >
+ <element name="transition" minOccurs="0" maxOccurs="unbounded">
<complexType>
- <complexContent>
- <extension base="tns:transitionType">
- <sequence>
- <element ref="tns:timer" minOccurs="0" />
- </sequence>
- </extension>
- </complexContent>
- </complexType>
+ <complexContent>
+ <extension base="tns:transitionType">
+ <sequence>
+ <element ref="tns:timer" minOccurs="0" />
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
</element>
</sequence>
<attributeGroup ref="tns:activityAttributes" />
</extension>
</complexContent>
</complexType>
- </element>
-
+ </element>
<!-- ~~~ TASK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<element name="task">
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java 2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java 2010-06-10 16:11:57 UTC (rev 6400)
@@ -70,8 +70,7 @@
execution.end();
}
else {
- // TODO is any other state possible?
- concurrentRoot = execution;
+ throw new AssertionError(execution.getState());
}
// evaluate transition condition and create concurrent executions
@@ -80,39 +79,44 @@
int index = 1;
//execution context needs to be temporarily replaced to give access to child execution variables
- ExecutionContext originalExecutionContext = null;
- ExecutionContext concurrentExecutionContext = null;
+ ExecutionContext originalContext = null;
EnvironmentImpl environment = EnvironmentImpl.getCurrent();
- if (environment!=null) {
- originalExecutionContext = (ExecutionContext) environment.removeContext(Context.CONTEXTNAME_EXECUTION);
+ if (environment != null) {
+ originalContext = (ExecutionContext) environment.removeContext(Context.CONTEXTNAME_EXECUTION);
}
-
- for (Object value : collection) {
- ExecutionImpl concurrentExecution = concurrentRoot.createExecution(Integer
- .toString(index++));
- concurrentExecution.setActivity(activity);
- concurrentExecution.setState(Execution.STATE_ACTIVE_CONCURRENT);
- concurrentExecution.createVariable(variable, value);
- // repla!
ce in the current environment execution context for expression evaluation purpose
- concurrentExecutionContext = new ExecutionContext(concurrentExecution);
- environment.setContext(concurrentExecutionContext);
-
- Condition condition = transition.getCondition();
- if (condition == null || condition.evaluate(concurrentExecution)) {
- concurrentExecutions.add(concurrentExecution);
+ try {
+ for (Object value : collection) {
+ ExecutionImpl concurrentExecution = concurrentRoot.createExecution(Integer
+ .toString(index++));
+ concurrentExecution.setActivity(activity);
+ concurrentExecution.setState(Execution.STATE_ACTIVE_CONCURRENT);
+ concurrentExecution.createVariable(variable, value);
+
+ // replace the current execution context for expression evaluation purposes
+ if (environment != null) {
+ environment.setContext(new ExecutionContext(concurrentExecution));
+ }
+
+ !
Condition condition = transition.getCondition();
+ !
if (cond
ition == null || condition.evaluate(concurrentExecution)) {
+ concurrentExecutions.add(concurrentExecution);
+ }
+ else {
+ concurrentExecution.end();
+ }
}
- else {
- concurrentExecution.end();
+ }
+ finally {
+ // reset original execution context after creating concurrent executions
+ if (environment != null) {
+ environment.setContext(originalContext);
}
}
- // after all concurrent execution were processed reset original execution context
- environment.setContext(originalExecutionContext);
- // if no concurrent executions should be launched
if (concurrentExecutions.isEmpty()) {
- // throw exceptions to be consistent with decision activity
- throw new JbpmException("no outgoing transition condition evaluated to true for " + activity);
+ // if no outgoing transitions should be forked, end this execution
+ execution.end();
}
else {
!
for (ExecutionImpl concurrentExecution : concurrentExecutions) {
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java 2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java 2010-06-10 16:11:57 UTC (rev 6400)
@@ -21,7 +21,7 @@
*/
package org.jbpm.jpdl.internal.activity;
-import java.util.List;
+import org.w3c.dom.Element;
import org.jbpm.jpdl.internal.xml.JpdlParser;
import org.jbpm.pvm.internal.el.Expression;
@@ -32,7 +32,6 @@
import org.jbpm.pvm.internal.wire.usercode.UserCodeCondition;
import org.jbpm.pvm.internal.wire.usercode.UserCodeReference;
import org.jbpm.pvm.internal.xml.Parse;
-import org.w3c.dom.Element;
/**
* @author Alejandro Guizar
@@ -58,50 +57,43 @@
}
if (element.hasAttribute(COLLECTION)) {
- Expression collection = Expression
- .create(element.getAttribute(COLLECTION), Expression.LANGUAGE_UEL_VALUE);
+ Expression collection = Expression.create(element.getAttribute(COLLECTION), Expression.LANGUAGE_UEL_VALUE);
activity.setCollection(collection);
}
else {
parse.addProblem(COLLECTION + " attribute missing", element);
}
-
+
// process transition elements
- List<Element> transitionElements = XmlUtil.elements(element, "transition");
-
- if (transitionElements.size() != 1) {
- parse.addProblem("foreach activity can/must have one outgoing transition, found "+ transitionElements.size() + " transitions ", element);
- } else {
-
+ Element transitionElement = XmlUtil.element(element, "transition");
+
+ if (transitionElement == null) {
+ parse.addProblem("outgoing transition expected", element);
+ }
+ else {
ActivityImpl a!
ctivityFromStack = parse.contextStackFind(ActivityImpl.class);
TransitionImpl transition = activityFromStack.getDefaultOutgoingTransition();
-
- // get first transition
- Element transitionElement = transitionElements.get(0);
-
+
Element conditionElement = XmlUtil.element(transitionElement, "condition");
if (conditionElement != null) {
-
if (conditionElement.hasAttribute("expr")) {
- ExpressionCondition expressionCondition = new ExpressionCondition();
- expressionCondition.setExpression(conditionElement.getAttribute("expr"));
- expressionCondition.setLanguage(XmlUtil.attribute(conditionElement, "lang"));
- transition.setCondition(expressionCondition);
-
- } else {
- Element conditionHandlerElement = XmlUtil.element(conditionElement, "handler");
- if (conditionHandlerElement != null) {
- UserCodeCondition userCodeCondition = new UserCodeCondition();
-
- !
UserCodeReference conditionReference = parser.parseU!
serCodeR
eference(conditionHandlerElement, parse);
- userCodeCondition.setConditionReference(conditionReference);
-
- transition.setCondition(userCodeCondition);
+ ExpressionCondition condition = new ExpressionCondition();
+ condition.setExpression(conditionElement.getAttribute("expr"));
+ condition.setLanguage(XmlUtil.attribute(conditionElement, "lang"));
+ transition.setCondition(condition);
+ }
+ else {
+ Element handlerElement = XmlUtil.element(conditionElement, "handler");
+ if (handlerElement != null) {
+ UserCodeReference conditionReference = parser.parseUserCodeReference(handlerElement, parse);
+ UserCodeCondition condition = new UserCodeCondition();
+ condition.setConditionReference(conditionReference);
+ transition.setCondition(condition);
}
}
}
}
-
+
return activity;
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java 2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java 2010-06-10 16:11:57 UTC (rev 6400)
@@ -35,7 +35,6 @@
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.TransitionImpl;
-
/**
* @author Tom Baeyens
*/
@@ -50,40 +49,39 @@
public void execute(ExecutionImpl execution) {
Activity activity = execution.getActivity();
- // evaluate the conditions and find the transitions that should be forked
+ // evaluate the conditions and select the forking transitions
List<Transition> forkingTransitions = new ArrayList<Transition>();
for (Transition transition: activity.getOutgoingTransitions()) {
Condition condition = ((TransitionImpl) transition).getCondition();
- if ( (condition==null)
- || (condition.evaluate(execution))
- ) {
+ if (condition==null || condition.evaluate(execution)) {
forkingTransitions.add(transition);
}
}
- // if no outgoing transitions should be forked,
- if (forkingTransitions.size()==0) {
- // end this execution
+ switch (forkingTransitions.size()) {
+ case 0:
+ // if no outgoing transitions should be forked, end this execution
execution.end();
-
- // if there is exactly 1 transition to be taken, just use the incoming execution
- } else if (forkingTransitions.size()==1) {
+ break;
+ case 1:
+ // if there is exactly one transition to be taken, just use the incoming execution
execution.take(forkingTransitions.get(0));
-
- // if there are more transitions
- } else {
+ break;
+ default:
+ // if there are more transitions, perform full fork
ExecutionImpl concurrentRoot;
if (Execution.STATE_ACTIVE_ROOT.equals(execution.getState())) {
concurrentRoot = execution;
execution.setState(Execution.STATE_INACTIVE_CONCURRENT_ROOT);
execution.setActivity(null);
- } else if (Execution.STATE_ACTIVE_CONCURRENT.equals(execution.getState())) {
+ }
+ else if (Execution.STATE_ACTIVE_CONCURRENT.equals(execution.getState())) {
concurrentRoot = execution.getParent();
execution.end();
- } else {
- // TODO is any other state possible?
- concurrentRoot = execution;
}
+ else {
+ throw new AssertionError(execution.getState());
+ }
Map<Transition, ExecutionImpl> concurrentExecutions = new HashMap<Transition, ExecutionImpl>();
for (Transition transition : forkingTransitions) {
@@ -93,13 +91,9 @@
concurrentExecutions.put(transition, concurrentExecution);
}
-
for (Entry<Transition, ExecutionImpl> entry : concurrentExecutions.entrySet()) {
entry.getValue().take(entry.getKey());
-
- if (concurrentRoot.isEnded()) {
- break;
- }
+ if (concurrentRoot.isEnded()) break;
}
}
}
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 2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2010-06-10 16:11:57 UTC (rev 6400)
@@ -25,6 +25,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
@@ -84,26 +85,23 @@
public static final String NAMESPACE_JPDL_40 = "http://jbpm.org/4.0/jpdl";
public static final String NAMESPACE_JPDL_42 = "http://jbpm.org/4.2/jpdl";
public static final String NAMESPACE_JPDL_43 = "http://jbpm.org/4.3/jpdl";
+ public static final String NAMESPACE_JPDL_44 = "http://jbpm.org/jpdl/4.4";
- public static final String CURRENT_VERSION_JBPM = "4.3";
- public static final String CURRENT_VERSION_NAMESPACE = "http://jbpm.org/"+CURRENT_VERSION_JBPM+"/jpdl";
+ public static final String CURRENT_VERSION_JBPM = "4.4";
+ public static final String CURRENT_VERSION_NAMESPACE = "http://jbpm.org/jpdl/"+CURRENT_VERSION_JBPM;
public static final String CURRENT_VERSION_PROCESS_LANGUAGE_ID = "jpdl-"+CURRENT_VERSION_JBPM;
- public static final List<String> SCHEMA_RESOURCES = new ArrayList<String>();
- static {
- SCHEMA_RESOURCES.add("jpdl-4.0.xsd");
- SCHEMA_RESOURCES.add("jpdl-4.2.xsd");
- SCHEMA_RESOURCES.add("jpdl-4.3.xsd");
- }
+ private static final List<String> SCHEMA_RESOURCES = Arrays.asList("jpdl-4.0.xsd",
+ "jpdl-4.2.xsd", "jpdl-4.3.xsd", "jpdl-4.4.xsd");
// array elements are mutable, even when final
// never make a static array public
- static final String[] DEFAULT_BINDING_RESOURCES = {
+ private static final String[] DEFAULT_BINDING_RESOURCES = {
"jbpm.jpdl.bindings.xml",
"jbpm.user.bindings.xml"
};
- static JpdlBindingsParser jpdlBindingsParser = new JpdlBindingsParser();
+ private static JpdlBindingsParser jpdlBindingsParser = new JpdlBindingsParser();
public static final String CATEGORY_ACTIVITY = "activity";
public static final String CATEGORY_EVENT_LISTENER = "eventlistener";
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/ForkTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/ForkTest.java 2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/ForkTest.java 2010-06-10 16:11:57 UTC (rev 6400)
@@ -24,11 +24,9 @@
*/
package org.jbpm.test.activities;
-import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
-
/**
* @author Joram Barrez
*/
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java 2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java 2010-06-10 16:11:57 UTC (rev 6400)
@@ -33,7 +33,7 @@
public class AssignTest extends JbpmTestCase {
public void testFromExprToVar() {
- deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
+ " <start>"
+ " <transition to='resolve' />"
+ " </start>"
@@ -52,7 +52,7 @@
}
public void testFromMethodExprToVar() {
- deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
+ " <start>"
+ " <transition to='resolve' />"
+ " </start>"
@@ -71,7 +71,7 @@
}
public void testFromMethodParamExprToVar() {
- deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
+ " <start>"
+ " <transition to='resolve' />"
+ " </start>"
@@ -90,7 +90,7 @@
}
public void testFromDescToExpr() {
- deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
+ " <start>"
+ " <transition to='resolve' />"
+ " </start>"
@@ -111,7 +111,7 @@
}
public void testFromVarToVar() {
- deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/jpdl/4.4'>"
+ " <start>"
+ " <transition to='resolve' />"
+ " </start>"
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java 2010-06-10 12:36:42 UTC (rev 6399)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java 2010-06-10 16:11:57 UTC (rev 6400)
@@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
+import java.util.List;
import java.util.Map;
import org.jbpm.api.Execution;
@@ -37,7 +38,7 @@
* @author Maciej Swiderski
*/
public class ForEachTest extends JbpmTestCase {
-
+
public void testForEachLiteral() {
deployJpdlXmlString(""
+ "<process name='ForEachLiteral' xmlns='http://jbpm.org/jpdl/4.4'>"
@@ -235,6 +236,7 @@
}
catch (JbpmException e) {
// expected result
+ e.printStackTrace();
}
}
@@ -250,7 +252,7 @@
+ " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ " <transition name='to state' to='join2' g='-43,-18'/>"
+ " </task>"
- + " <join name='join2' g='192,511,57,44' multiplicity='#{actors.size() - 1}'>"
+ + " <join name='join2' g='192,511,57,44' multiplicity='#{actors.size()-1}'>"
+ " <transition name='to end1' to='end1' g='-42,-18'/>"
+ " </join>"
+ " <end g='193,606,38,33' name='end1'/>"
@@ -272,17 +274,17 @@
assertEquals(ProcessInstance.STATE_ENDED, history.getState());
assertEquals("end1", history.getEndActivityName());
}
-
- public void testForEachLiteralWithTransitionExpr() {
+
+ public void testForEachConditionMet() {
deployJpdlXmlString(""
- + "<process name='ForEachCondition' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + "<process name='ForEachConditionMet' xmlns='http://jbpm.org/jpdl/4.4'>"
+ " <start g='179,17,32,29' name='start1'>"
+ " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ " </start>"
+ " <foreach g='185,95,49,50' name='foreach1' var='assign' in='alex, mike, peter'>"
+ " <transition name='left' to='task1' g='-44,-18'>"
- + " <condition expr='#{assign=="alex" or assign=="mike"}' /> "
- + " </transition>"
+ + " <condition expr='#{assign != "peter"}' /> "
+ + " </transition>"
+ " </foreac!
h>"
+ " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ " <transition name='to state' to='Big car' g='-43,-18'/>"
@@ -296,7 +298,7 @@
+ " <end g='193,606,38,33' name='end1'/>"
+ "</process>");
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachCondition");
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachConditionMet");
Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
assertEquals("task1", taskAlex.getActivityName());
@@ -320,37 +322,41 @@
assertEquals(ProcessInstance.STATE_ENDED, history.getState());
assertEquals("end1", history.getEndActivityName());
}
-
- public void testForEachTooManyTransitions() {
- try {
- deployJpdlXmlString(""
- + "<process name='ForEachTooManyTransitions' xmlns='http://jbpm.org/jpdl/4.4'>"
- + " <start g='179,17,32,29' name='start1'>"
- + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
- + " </start>"
- + " <foreach g='185,95,49,50' name='foreach1' in='#{actors}' var='assign'>"
- + " <transition name='left' to='task1' g='-44,-18'/>"
- + " <transition name='right' to='task1' g='-44,-18'/>"
- + " </foreach>"
- + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
- + " <transition name='to state' to='Big car' g='-43,-18'/>"
- + " </task>"
- + " <state name='Big car' > "
- + " <transition name='to join2' to='join2' !
g='-43,-18'/>"
- + " </state> "
- + " <join name='join2' g='192,511,57,44'>"
- + " <transition name='to end1' to='end1' g='-42,-18'/>"
- + " </join>"
- + " <end g='193,606,38,33' name='end1'/>"
- + "</process>");
- fail("expected foreach with too many transitions");
- }
- catch (JbpmException e) {
- // expected result
- }
+ public void testForEachConditionNotMet() {
+ deployJpdlXmlString(""
+ + "<process name='ForEachConditionNotMet' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' var='assign' in='alex, mike'>"
+ + " <transition name='left' to='task1' g='-44,-18'>"
+ + " <condition expr='#{assign=="peter"}' /> "
+ + " </transition>"
+ + " </foreach>"
!
+ + " <task name='task1' g='90,177,73,44' assignee='#{a!
ssign}'>
"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachConditionNotMet");
+
+ List<Task> tasks = taskService.createTaskQuery().list();
+ assertEquals(0, tasks.size());
+
+ HistoryProcessInstance history = historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
}
-
+
public void testForEachNoTransitions() {
try {
deployJpdlXmlString(""
@@!
-358,7 +364,7 @@
+ " <start g='179,17,32,29' name='start1'>"
+ " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ " </start>"
- + " <foreach g='185,95,49,50' name='foreach1' in='#{actors}' var='assign' >"
+ + " <foreach g='185,95,49,50' name='foreach1' var='assign' in='#{actors}'>"
+ " </foreach>"
+ " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ " <transition name='to state' to='Big car' g='-43,-18'/>"
@@ -372,44 +378,10 @@
+ " <end g='193,606,38,33' name='end1'/>"
+ "</process>");
- fail("expected foreach with too many transitions");
+ fail("expected deployment failure");
}
catch (JbpmException e) {
// expected result
}
}
-
- public void testForEachConditionTransitionsEvaluatedToFalse() {
- try {
- deployJpdlXmlString(""
- + "<process name='ForEachConditionFalse' xmlns='http://jbpm.org/jpdl/4.4'>"
- + " <start g='179,17,32,29' name='start1'>"
- + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
- + " </start>"
- + " <foreach g='185,95,49,50' name='foreach1' in='#{actors}' var='assign' >"
- + " <transition name='left' to='task1' g='-44,-18'>"
- + " <condition expr='#{assign=="peter"}' /> "
- + " </transition>"
- + " </foreach>"
- + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
- !
+ " <transition name='to state' to='Big car' g='-43,-18'/>"
- + " </task>"
- + " <state name='Big car' > "
- + " <transition name='to join2' to='join2' g='-43,-18'/>"
- + " </state> "
- + " <join name='join2' g='192,511,57,44'>"
- + " <transition name='to end1' to='end1' g='-42,-18'/>"
- + " </join>"
- + " <end g='193,606,38,33' name='end1'/>"
- + "</process>");
-
- Map<String, ?> variables = Collections.singletonMap("actors", Arrays.asList("alex", "mike"));
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachConditionFalse", variables);
-
- fail("expected foreach all conditions evaluated to false");
- }
- catch (JbpmException e) {
- // expected result
- }
- }
}
13 years, 11 months
JBoss JBPM SVN: r6399 - in jbpm4/trunk/modules: examples/src/test/resources/org/jbpm/examples/concurrency/foreach and 1 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-06-10 08:36:42 -0400 (Thu, 10 Jun 2010)
New Revision: 6399
Modified:
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/ForEachTest.java
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/process.jpdl.xml
jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml
Log:
JBPM-2414: document foreach activity
Modified: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/ForEachTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/ForEachTest.java 2010-06-10 11:10:39 UTC (rev 6398)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/ForEachTest.java 2010-06-10 12:36:42 UTC (rev 6399)
@@ -24,6 +24,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;
@@ -74,14 +75,11 @@
}
public void testForEachCompleteAll() {
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("departments", new String[] { "sales-dept", "hr-dept", "finance-dept" });
+ variables.put("quorum", 3);
- HashMap<String, Object> variables = new HashMap<String, Object>();
- variables.put("listOfDepartments", new String[] { "sales-dept", "hr-dept", "finance-dept" });
- variables.put("joinAt", 3);
-
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachFork", variables);
- String processInstanceId = processInstance.getId();
-
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEach", variables);
// there should be 3 forked executions - same as number of departments
assertEquals(3, processInstance.getExecutions().size());
@@ -119,18 +117,15 @@
taskService.completeTask(taskListFinance.get(0).getId());
Date endTime = historyService.createHistoryProcessInstanceQuery().processInstanceId(processInstance.getId()).uniqueResult().getEndTime();
-
assertNotNull(endTime);
}
public void testForEachCompleteAfterTwoJoined() {
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("departments", new String[] { "sales-dept", "hr-dept", "finance-dept" });
+ variables.put("quorum", 2);
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEach", variables);
- HashMap<String, Object> variables = new HashMap<String, Object>();
- variables.put("listOfDepartments", new String[] { "sales-dept", "hr-dept", "finance-dept" });
- variables.put("joinAt", 2);
-
- ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachFork", variables);
-
// there should be 3 forked executions - same as number of departme!
nts
assertEquals(3, processInstance.getExecutions().size());
@@ -160,7 +155,6 @@
taskService.completeTask(taskListSales.get(0).getId());
Date endTime = historyService.createHistoryProcessInstanceQuery().processInstanceId(processInstance.getId()).uniqueResult().getEndTime();
-
assertNotNull(endTime);
}
}
Modified: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/process.jpdl.xml 2010-06-10 11:10:39 UTC (rev 6398)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/process.jpdl.xml 2010-06-10 12:36:42 UTC (rev 6399)
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
-<process name="ForEachFork" xmlns="http://jbpm.org/4.3/jpdl">
+<process name="ForEach" xmlns="http://jbpm.org/4.4/jpdl">
<start g="28,61,48,48" name="start1">
<transition to="foreach1"/>
</start>
- <foreach var="department" in="#{listOfDepartments}" g="111,60,48,48" name="foreach1">
+ <foreach var="department" in="#{departments}" g="111,60,48,48" name="foreach1">
<transition to="Collect data"/>
</foreach>
<task candidate-groups="#{department}" g="201,58,92,52" name="Collect data">
<transition to="join1"/>
</task>
- <join g="343,59,48,48" multiplicity="#{joinAt}" name="join1">
+ <join g="343,59,48,48" multiplicity="#{quorum}" name="join1">
<transition to="end1"/>
</join>
<end g="433,60,48,48" name="end1"/>
Modified: jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml
===================================================================
--- jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml 2010-06-10 11:10:39 UTC (rev 6398)
+++ jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml 2010-06-10 12:36:42 UTC (rev 6399)
@@ -495,9 +495,43 @@
<section id="concurrency">
<title><literal>concurrency</literal></title>
- <para>With the <literal>fork</literal> and <literal>join</literal> activities,
- concurrent paths of executions can be modeled.
- </para>
+ <para>With the <literal>fork</literal>, <literal>foreach</literal> and
+ <literal>join</literal> activities, concurrent paths of executions can be modeled.
+ The next two tables describe the <literal>foreach</literal> and <literal>join</literal>
+ attributes; <literal>fork</literal> has no specific attributes.</para>
+ <table><title><literal>foreach</literal> attributes:</title>
+ <tgroup cols="5" rowsep="1" colsep="1">
+ <thead>
+ <row>
+ <entry>Attribute</entry>
+ <entry>Type</entry>
+ <entry>Default</entry>
+ <entry>Required?</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>in</literal></entry>
+ <entry>expression or text</entry>
+ <entry></entry>
+ <entry>required</entry>
+ <entry>The collection to be iterated. Each item in the collection spawns a new
+ concurrent execution leaving over the default transition. <literal>in</literal>
+ supports collections of any kind, arrays and comma separated strings.</entry>
+ </row>
+ <row>
+ <entry><literal>var</literal></entry>
+ <entry>text</entry>
+ <entry></entry>
+ <entry>required</entry>
+ <entry>The variable where the current item of the collection is stored.
+ This variable is set in the concurrent execution and is visible only to that
+ execution.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
<table><title><literal>join</literal> attributes:</title>
<tgroup cols="5" rowsep="1" colsep="1">
<thead>
@@ -512,7 +546,7 @@
<tbody>
<row>
<entry><literal>multiplicity</literal></entry>
- <entry>integer</entry>
+ <entry>integer or expression</entry>
<entry>nbr of incoming transitions</entry>
<entry>optional</entry>
<entry>The number of executions that should arrive in this join
@@ -533,14 +567,17 @@
</tbody>
</tgroup>
</table>
- <para>For example:</para>
- <figure id="process.concurrency">
- <title>The concurrency example process</title>
- <mediaobject><imageobject><imagedata align="center" fileref="images/process.concurrency.png"/></imageobject></mediaobject>
- </figure>
-
- <programlisting><process name="ConcurrencyGraphBased" xmlns="http://jbpm.org/4.3/jpdl">
+ <section>
+ <title>Parallel split with <literal>fork</literal></title>
+ <para>The <literal>fork</literal> activity allows a single path of execution to be
+ split into two or more branches which can execute activities concurrently.</para>
+ <figure id="process.concurrency">
+ <title>Parallel split example process</title>
+ <mediaobject><imageobject><imagedata align="center" fileref="images/process.concurrency.png"/></imageobject></mediaobject>
+ </figure>
+ <programlisting><process name="ConcurrencyGraphBased" xmlns="http://jbpm.org/4.3/jpdl">
+
<start>
<transition to="fork"/>
</start>
@@ -578,6 +615,50 @@
<end name="end" />
</process></programlisting>
+ </section>
+
+ <section>
+ <title>Iterative split with <literal>foreach</literal></title>
+ <para>At a given point in a process, several paths of execution can be initiated
+ in a single branch of the same process instance. In the example, there is a need
+ to collect time sheet reports (called data) from different departments. With
+ <literal>foreach</literal> this can be quite easily achieved. The same task
+ is to be performed by different groups. Process variable <literal>departments</literal>
+ provides the group names, whereas the variable <literal>quota</literal> indicates
+ how many tasks must be completed before execution will leave the <literal>join</literal>
+ activity.</para>
+ <programlisting><![CDATA[<process name="ForEach" xmlns="http://jbpm.org/4.4/jpdl">
+
+ <start g="28,61,48,48" name="start1">
+ <transition to="foreach1"/>
+ </start>
+
+ <foreach var="department" in="#{departments}" g="111,60,48,48" name="foreach1">
+ <transition to="Collect data"/>
+ </foreach>
+
+ <task candidate-groups="#{department}" g="201,58,92,52" name="Collect data">
+ <transition to="join1"/>
+ </task>
+
+ <join g="343,59,48,48" multiplicity="#{quorum}" name="join1">
+ <transition to="end1"/>
+ </join>
+
+ <end g="433,60,48,48" name="end1"/>
+
+</process>]]></programlisting>
+ <important><para>When using foreach, the corresponding join must have the
+ multiplicity attribute set. In general, join continues execution based on its
+ incoming transitions. When using foreach, join has a single incoming transition.
+ If multiplicity is not specified, the first execution that reaches the join
+ activity will trigger continuation.</para></important>
+ <para>Here is how to initialize the iterative process variables.</para>
+ <programlisting><![CDATA[Map<String, Object> variables = new HashMap<String, Object>();
+variables.put("departments", new String[] { "sales-dept", "hr-dept", "finance-dept" });
+variables.put("quorum", 3);
+ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEach", variables);]]></programlisting>
+ </section>
</section>
<!-- ### END ########################################################### -->
13 years, 11 months
JBoss JBPM SVN: r6398 - in jbpm4/trunk/modules: bpmn/src/main/java/org/jbpm/bpmn/flownodes and 11 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-06-10 07:10:39 -0400 (Thu, 10 Jun 2010)
New Revision: 6398
Modified:
jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/AbstractTaskBinding.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskBinding.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/StartEventBinding.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/UserTaskBinding.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java
jbpm4/trunk/modules/enterprise/src/main/java/org/jbpm/enterprise/internal/wire/binding/EjbRemoteCommandServiceBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/EndBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JmsBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JpdlBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SubProcessBinding.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlBindingsParser.java
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/UnresolvedTransition.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/EventListenerReference.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/TagBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/XmlUtil.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/AbstractCollectionBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/BasicTypeBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/CommandServiceBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateConfigurationBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/JobExecutorBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MapBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MessageSessionBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PropertiesBinding.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/Parser.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/Person.java
jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml
Log:
JBPM-2775: complete, test and document assign activity
Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd 2010-06-10 11:10:39 UTC (rev 6398)
@@ -382,6 +382,23 @@
</complexType>
</element>
+ <!-- ~~~ ASSIGN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
+ <element name="assign">
+ <annotation><documentation>Assigns a source value to a target location
+ </documentation></annotation>
+ <complexType>
+ <complexContent>
+ <extension base="tns:assignType">
+ <sequence>
+ <element ref="tns:on" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="tns:transition" minOccurs="0" maxOccurs="unbounded" />
+ </sequence>
+ <attributeGroup ref="tns:activityAttributes" />
+ </extension>
+ </complexContent>
+ </complexType>
+ </element>
+
<!-- ~~~ CUSTOM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<element name="custom">
<annotation><documentation>Uses a user defined, custom implementation of
@@ -1051,6 +1068,45 @@
of the script evaluation will be stored</documentation></annotation>
</attribute>
</complexType>
+
+ <complexType name="assignType">
+ <sequence>
+ <element name="description" minOccurs="0" maxOccurs="unbounded" type="string" />
+ <element name="from" minOccurs="0">
+ <annotation>
+ <documentation>Descriptor that constructs the source value</documentation>
+ </annotation>
+ <complexType>
+ <group ref="tns:wireObjectGroup" />
+ </complexType>
+ </element>
+ </sequence>
+ <attribute name="from-expr" type="string">
+ <annotation>
+ <documentation>Expression that resolves the source value</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="lang" type="string">
+ <annotation>
+ <documentation>Language in which from-expr is written</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="from-var" type="string">
+ <annotation>
+ <documentation>Variable that provides the source value</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="to-expr" type="string">
+ <annotation>
+ <documentation>Expression that resolves the target location</documentation>
+ </annotation>
+ </attribute>
+ <attribute name="to-var" type="string">
+ <annotation>
+ <documentation>Variable that provides the target location</documentation>
+ </annotation>
+ </attribute>
+ </complexType>
<complexType name="qlType">
<sequence>
@@ -1277,6 +1333,15 @@
</complexContent>
</complexType>
</element>
+ <element name="assign">
+ <complexType>
+ <complexContent>
+ <extension base="tns:assignType">
+ <attribute name="propagation" type="tns:booleanValueType" />
+ </extension>
+ </complexContent>
+ </complexType>
+ </element>
<element name="script">
<complexType>
<complexContent>
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/AbstractTaskBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/AbstractTaskBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/AbstractTaskBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -35,13 +35,13 @@
}
protected void addActivityResources(TaskDefinitionImpl taskDefinition, BpmnActivity taskActivity, Element element, Parse parse) {
- Element performer = XmlUtil.element(element, PERFORMER, false, parse);
+ Element performer = XmlUtil.element(element, PERFORMER);
if (performer != null) {
taskActivity.addActivityResource(addPerformer(taskDefinition, PERFORMER, performer, parse));
}
// Overrides 'performer'
- Element humanPerformer = XmlUtil.element(element, HUMAN_PERFORMER, false, parse);
+ Element humanPerformer = XmlUtil.element(element, HUMAN_PERFORMER);
if (humanPerformer != null) {
taskActivity.addActivityResource(addPerformer(taskDefinition, HUMAN_PERFORMER, humanPerformer, parse));
}
@@ -54,19 +54,19 @@
private ActivityResource addPerformer(TaskDefinitionImpl taskDefinition, String type, Element performer, Parse parse) {
- String resourceRef = XmlUtil.attribute(performer, "resourceRef", true, parse);
+ String resourceRef = XmlUtil.attribute(performer, "resourceRef", parse);
BpmnProcessDefinition bpmnProcessDefinition = parse.contextStackFind(BpmnProcessDefinition.class);
ActivityResource activityResource = new ActivityResource();
activityResource.setResourceRef(bpmnProcessDefinition.getResource(resourceRef));
- String scope = XmlUtil.attribute(performer, "jbpm:type", false, parse); // Todo refactor for namespaces
+ String scope = XmlUtil.attribute(performer, "jbpm:type"); // Todo refactor for namespaces
- Element rae = XmlUtil.element(performer, "resourceAssignmentExpression", false, parse);
+ Element rae = XmlUtil.element(performer, "resourceAssignmentExpression");
if (rae != null) {
- String formalExpression = XmlUtil.element(rae, "formalExpression", true, parse).getTextContent().trim();
- String lang = XmlUtil.attribute(rae, "language", false, parse);
+ String formalExpression = XmlUtil.element(rae, "formalExpression", parse).getTextContent().trim();
+ String lang = XmlUtil.attribute(rae, "language");
Expression expression = Expression.create(formalExpression, lang);
if (PERFORMER.equals(type) || HUMAN_PERFORMER.equals(type)) {
taskDefinition.setAssigneeExpression(expression);
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ServiceTaskBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -47,7 +47,7 @@
BpmnProcessDefinition bpmnProcessDefinition = parse.contextStackFind(BpmnProcessDefinition.class);
// Operation parsing
- String operationRef = XmlUtil.attribute(element, "operationRef", true, parse, null);
+ String operationRef = XmlUtil.attribute(element, "operationRef", parse);
Element operationElement = bpmnProcessDefinition.getOperations().get(operationRef);
if (operationElement == null) {
parse.addProblem("No operation found for operationRef " + operationRef, operationElement);
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-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/StartEventBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -56,7 +56,7 @@
parse.addProblem("multiple start events not yet supported", element);
}
- String id = XmlUtil.attribute(element, "id", true, parse);
+ 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);
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/UserTaskBinding.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/UserTaskBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/UserTaskBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -48,9 +48,9 @@
addActivityResources(taskDefinition, taskActivity, element, parse);
- Element rendering = XmlUtil.element(element, "rendering", false, parse);
+ Element rendering = XmlUtil.element(element, "rendering");
if (rendering != null) {
- Element jBPMForm = XmlUtil.element(rendering, "form", false, parse);
+ Element jBPMForm = XmlUtil.element(rendering, "form");
taskDefinition.setFormResourceName(jBPMForm != null ? jBPMForm.getTextContent().trim() : null);
}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java
===================================================================
--- jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -53,7 +53,7 @@
}
protected Binding instantiateBinding(Element bindingElement, Parse parse) {
- String bindingClassName = XmlUtil.attribute(bindingElement, "binding", true, parse);
+ String bindingClassName = XmlUtil.attribute(bindingElement, "binding", parse);
log.trace("adding bpmn binding " + bindingClassName);
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-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BpmnParser.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -118,8 +118,8 @@
parse.contextStackPush(processDefinition);
try {
- String id = XmlUtil.attribute(processElement, "id", true, parse);
- String name = XmlUtil.attribute(processElement, "name", false, parse);
+ String id = XmlUtil.attribute(processElement, "id", parse);
+ String name = XmlUtil.attribute(processElement, "name");
if (id != null && !"".equals(id)) {
processDefinition.setName(id);
@@ -207,7 +207,7 @@
for (Element dataElement : XmlUtil.elements(element, "dataObject")) {
VariableDefinitionImpl variableDefinition = new VariableDefinitionImpl();
- String name = XmlUtil.attribute(dataElement, "id", true, parse);
+ String name = XmlUtil.attribute(dataElement, "id", parse);
variableDefinition.setName(name);
String typeRef = XmlUtil.attribute(dataElement, "itemSubjectRef");
@@ -222,9 +222,9 @@
public void parseActivities(Element element, Parse parse, CompositeElementImpl compositeElement) {
List<Element> elements = XmlUtil.elements(element);
for (Element nestedElement : elements) {
- String tagName = XmlUtil.getTagLocalName(nestedElement);
- String name = XmlUtil.attribute(nestedElement, "name", false, parse);
- String id = XmlUtil.attribute(nestedElement, "id", true, parse);
+ String tagName = nestedElement.getLocalName();
+ String name = XmlUtil.attribute(nestedElement, "name");
+ String id = XmlUtil.attribute(nestedElement, "id", parse);
TagBinding activityBinding = (TagBinding) getBinding(nestedElement, CATEGORY_ACTIVITY);
if (activityBinding == null) {
@@ -258,10 +258,10 @@
for (Element transitionElement : transitionElements) {
// Parse attributes
- String transitionName = XmlUtil.attribute(transitionElement, "name", false, parse);
- String transitionId = XmlUtil.attribute(transitionElement, "id", true, parse);
- String sourceRef = XmlUtil.attribute(transitionElement, "sourceRef", true, parse);
- String targetRef = XmlUtil.attribute(transitionElement, "targetRef", true, parse);
+ String transitionName = XmlUtil.attribute(transitionElement, "name");
+ String transitionId = XmlUtil.attribute(transitionElement, "id", parse);
+ String sourceRef = XmlUtil.attribute(transitionElement, "sourceRef", parse);
+ String targetRef = XmlUtil.attribute(transitionElement, "targetRef", parse);
if (log.isDebugEnabled()) {
log.debug(transitionId + ": " + sourceRef + " -> " + targetRef);
Modified: jbpm4/trunk/modules/enterprise/src/main/java/org/jbpm/enterprise/internal/wire/binding/EjbRemoteCommandServiceBinding.java
===================================================================
--- jbpm4/trunk/modules/enterprise/src/main/java/org/jbpm/enterprise/internal/wire/binding/EjbRemoteCommandServiceBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/enterprise/src/main/java/org/jbpm/enterprise/internal/wire/binding/EjbRemoteCommandServiceBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -41,10 +41,10 @@
}
public Object parse(Element element, Parse parse, Parser parser) {
- String initialContextFactory = XmlUtil.attribute(element, "initial-context-factory", true, parse);
- String providerUrl = XmlUtil.attribute(element, "provider-url", true, parse);
- String urlPkgPrefixes = XmlUtil.attribute(element, "url-pkg-prefixes", true, parse);
- String jndiName = XmlUtil.attribute(element, "jndi-name", false, parse, "jbpm/CommandExecutor");
+ String initialContextFactory = XmlUtil.attribute(element, "initial-context-factory", parse);
+ String providerUrl = XmlUtil.attribute(element, "provider-url", parse);
+ String urlPkgPrefixes = XmlUtil.attribute(element, "url-pkg-prefixes", parse);
+ String jndiName = XmlUtil.attribute(element, "jndi-name", "jbpm/CommandExecutor");
EjbRemoteCommandService ejbRemoteCommandService = new EjbRemoteCommandService(initialContextFactory, providerUrl, urlPkgPrefixes, jndiName);
Descriptor descriptor = new ProvidedObjectDescriptor(ejbRemoteCommandService, true);
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignActivity.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignActivity.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -24,11 +24,10 @@
import org.jbpm.api.model.OpenExecution;
import org.jbpm.pvm.internal.el.Expression;
import org.jbpm.pvm.internal.el.UelValueExpression;
-import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
-
/**
* @author Tom Baeyens
*/
@@ -37,38 +36,46 @@
private static final long serialVersionUID = 1L;
protected Expression fromExpression;
- protected Descriptor fromValueDescriptor;
+ protected String fromVariable;
+ protected Descriptor fromDescriptor;
- protected String toVariableName;
protected UelValueExpression toExpression;
+ protected String toVariable;
void perform(OpenExecution execution) throws Exception {
Object value = null;
-
- if (fromExpression!=null) {
+
+ if (fromExpression != null) {
value = fromExpression.evaluate(execution);
-
- } else if (fromValueDescriptor!=null) {
- value = WireContext.create(fromValueDescriptor, (ScopeInstanceImpl) execution);
}
-
- if (toVariableName!=null) {
- execution.setVariable(toVariableName, value);
- } else {
+ else if (fromVariable != null) {
+ value = execution.getVariable(fromVariable);
+ }
+ else if (fromDescriptor != null) {
+ value = WireContext.create(fromDescriptor, (ExecutionImpl) execution);
+ }
+
+ if (toExpression != null) {
toExpression.setValue(execution, value);
}
+ else {
+ execution.setVariable(toVariable, value);
+ }
}
- public void setToVariableName(String variableName) {
- this.toVariableName = variableName;
+ public void setFromDescriptor(Descriptor descriptor) {
+ fromDescriptor = descriptor;
}
- public void setFromValueDescriptor(Descriptor valueDescriptor) {
- this.fromValueDescriptor = valueDescriptor;
+ public void setFromExpression(Expression expression) {
+ fromExpression = expression;
}
- public void setFromExpression(Expression fromExpression) {
- this.fromExpression = fromExpression;
+ public void setFromVariable(String variableName) {
+ fromVariable = variableName;
}
- public void setToExpression(UelValueExpression toExpression) {
- this.toExpression = toExpression;
+ public void setToExpression(UelValueExpression expression) {
+ toExpression = expression;
}
+ public void setToVariable(String variableName) {
+ toVariable = variableName;
+ }
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -33,12 +33,18 @@
import org.jbpm.pvm.internal.xml.Parse;
import org.w3c.dom.Element;
-
/**
* @author Tom Baeyens
*/
public class AssignBinding extends JpdlBinding {
-
+
+ private static final String FROM_EXPR = "from-expr";
+ private static final String LANG = "lang";
+ private static final String FROM_VAR = "from-var";
+ private static final String FROM_DESC = "from";
+ private static final String TO_EXPR = "to-expr";
+ private static final String TO_VAR = "to-var";
+
public AssignBinding() {
super("assign");
}
@@ -46,43 +52,47 @@
public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
AssignActivity assignActivity = new AssignActivity();
- String toVar = XmlUtil.attribute(element, "to-var");
- String toExpr = XmlUtil.attribute(element, "to-expr");
- if (toVar!=null) {
- assignActivity.setToVariableName(toVar);
- } else if (toExpr!=null) {
- Expression expression = Expression.create(toExpr, Expression.LANGUAGE_UEL_VALUE);
- assignActivity.setToExpression((UelValueExpression) expression);
+ // from expression
+ if (element.hasAttribute(FROM_EXPR)) {
+ String lang = XmlUtil.attribute(element, LANG);
+ Expression fromExpression = Expression.create(element.getAttribute(FROM_EXPR), lang);
+ assignActivity.setFromExpression(fromExpression);
}
-
- String exprText = XmlUtil.attribute(element, "expr");
- String exprType = XmlUtil.attribute(element, "expr-type");
-
- // if there is an expr specified
- if (exprText!=null) {
- Expression expression = Expression.create(exprText, exprType);
- assignActivity.setFromExpression(expression);
-
- } else { // there is no expr specified
- Set<String> descriptorTagNames = WireParser.getInstance().getBindings().getTagNames(WireParser.CATEGORY_DESCRIPTOR);
- Descriptor valueDescriptor = null;
- List<Element> assignContentElements = XmlUtil.elements(element);
-
- for (int i=0; ((i<assignContentElements.size()) && (valueDescriptor==null)); i++) {
- Element assignContentElement = assignContentElements.get(i);
- String assignContentElementTagName = XmlUtil.getTagLocalName(assignContentElement);
- if (descriptorTagNames.contains(assignContentElementTagName)) {
- valueDescriptor = parser.parseDescriptor(assignContentElement, parse);
+ // from variable
+ else if (element.hasAttribute(FROM_VAR)) {
+ assignActivity.setFromVariable(element.getAttribute(FROM_VAR));
+ }
+ else {
+ // neither expression nor variable
+ Element fromElement = XmlUtil.element(element, FROM_DESC);
+ if (fromElement != null) {
+ Set<String> descriptorTags = WireParser.getInstance()
+ .getBindings()
+ .getTagNames(WireParser.CATEGORY_DESCRIPTOR);
+ Element descriptorElement = XmlUtil.element(fromElement);
+ if (descriptorElement != null
+ && descriptorTags.contains(descriptorElement.getTagName())) {
+ Descriptor descriptor = parser.parseDescriptor(descriptorElement, parse);
+ assignActivity.setFromDescriptor(descriptor);
}
+ else {
+ parse.addProblem("missing descriptor element", fromElement);
+ }
}
-
- if (valueDescriptor!=null) {
- assignActivity.setFromValueDescriptor(valueDescriptor);
- } else {
- parse.addProblem("no value for assignment specified. 'assign' must have attribute 'expr' or a wire object element.", element);
+ else {
+ parse.addProblem("missing " + FROM_EXPR + " attribute, " + FROM_VAR + " attribute or "
+ + FROM_DESC + " element", element);
}
}
-
+
+ if (element.hasAttribute(TO_VAR)) {
+ assignActivity.setToVariable(element.getAttribute(TO_VAR));
+ }
+ else if (element.hasAttribute(TO_EXPR)) {
+ Expression expression = Expression.create(element.getAttribute(TO_EXPR), Expression.LANGUAGE_UEL_VALUE);
+ assignActivity.setToExpression((UelValueExpression) expression);
+ }
+
return assignActivity;
}
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/EndBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/EndBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/EndBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -43,12 +43,12 @@
public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
boolean endProcessInstance = true;
- String ends = XmlUtil.attribute(element, "ends", false, parse);
+ String ends = XmlUtil.attribute(element, "ends");
if ("execution".equalsIgnoreCase(ends)) {
endProcessInstance = false;
}
- String state = XmlUtil.attribute(element, "state", false, parse);
+ String state = XmlUtil.attribute(element, "state");
EndActivity endActivity = new EndActivity();
endActivity.setEndProcessInstance(endProcessInstance);
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/HqlBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -51,17 +51,18 @@
public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
HqlActivity hqlActivity = createHqlActivity();
- Element queryElement = XmlUtil.element(element, "query", true, parse);
+ Element queryElement = XmlUtil.element(element, "query", parse);
if (queryElement!=null) {
String query = XmlUtil.getContentText(queryElement);
hqlActivity.setQuery(query);
}
- if (XmlUtil.attributeBoolean(element, "unique", false, parse, Boolean.FALSE)) {
- hqlActivity.setResultUnique(true);
+ Boolean resultUnique = XmlUtil.attributeBoolean(element, "unique", parse);
+ if (resultUnique!=null) {
+ hqlActivity.setResultUnique(resultUnique);
}
- String variableName = XmlUtil.attribute(element, "var", true, parse);
+ String variableName = XmlUtil.attribute(element, "var", parse);
hqlActivity.setResultVariableName(variableName);
Element parametersElement = XmlUtil.element(element, "parameters");
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JavaBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -47,8 +47,8 @@
public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
JavaActivity javaActivity = new JavaActivity();
- if (XmlUtil.attribute(element, "method", true, parse, null)!=null) {
- String jndiName = XmlUtil.attribute(element, "ejb-jndi-name", false, parse, null);
+ if (XmlUtil.attribute(element, "method", parse)!=null) {
+ String jndiName = XmlUtil.attribute(element, "ejb-jndi-name");
if (jndiName != null) {
parseEjbInvocation(javaActivity, element, parse, parser);
} else {
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JmsBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JmsBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JmsBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -51,13 +51,13 @@
// attributes /////////////////////////////////////////////////////////////
- String connectionFactoryName = XmlUtil.attribute(element, "connection-factory", true, parse);
+ String connectionFactoryName = XmlUtil.attribute(element, "connection-factory", parse);
jmsActivity.setConnectionFactoryName(connectionFactoryName);
- String destinationName = XmlUtil.attribute(element, "destination", true, parse);
+ String destinationName = XmlUtil.attribute(element, "destination", parse);
jmsActivity.setDestinationName(destinationName);
- Boolean transacted = XmlUtil.attributeBoolean(element, "transacted", false, parse, null);
+ Boolean transacted = XmlUtil.attributeBoolean(element, "transacted", parse);
if (transacted!=null) {
jmsActivity.setTransacted(transacted);
}
@@ -77,7 +77,7 @@
// elements ///////////////////////////////////////////////////////////////
- Element textElement = XmlUtil.element(element, "text", false, parse);
+ Element textElement = XmlUtil.element(element, "text");
if (textElement != null) {
String expressionText = XmlUtil.getContentText(textElement);
jmsActivity.setType("text");
@@ -85,7 +85,7 @@
jmsActivity.setTextExpression(expression);
}
- Element objectElement = XmlUtil.element(element, "object", false, parse);
+ Element objectElement = XmlUtil.element(element, "object");
if (objectElement != null) {
jmsActivity.setType("object");
String expressionText = XmlUtil.attribute(objectElement, "expr");
@@ -93,7 +93,7 @@
jmsActivity.setObjectExpression(expression);
}
- Element mapElement = XmlUtil.element(element, "map", false, parse);
+ Element mapElement = XmlUtil.element(element, "map");
if (mapElement != null) {
jmsActivity.setType("map");
Descriptor descriptor = parser.parseDescriptor(mapElement, parse);
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JpdlBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JpdlBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JpdlBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -21,22 +21,15 @@
*/
package org.jbpm.jpdl.internal.activity;
+import org.w3c.dom.Element;
-import java.util.List;
-
-import org.jbpm.api.model.Event;
import org.jbpm.jpdl.internal.xml.JpdlParser;
-import org.jbpm.jpdl.internal.xml.UnresolvedTransitions;
import org.jbpm.pvm.internal.model.ActivityImpl;
-import org.jbpm.pvm.internal.model.TimerDefinitionImpl;
-import org.jbpm.pvm.internal.model.TransitionImpl;
import org.jbpm.pvm.internal.util.TagBinding;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.xml.Parse;
import org.jbpm.pvm.internal.xml.Parser;
-import org.w3c.dom.Element;
-
/**
* @author Tom Baeyens
*/
@@ -53,7 +46,7 @@
}
public void parseName(Element element, ActivityImpl activity, Parse parse) {
- String name = XmlUtil.attribute(element, "name", isNameRequired(), parse);
+ String name = XmlUtil.attribute(element, "name", isNameRequired() ? parse : null);
if (name!=null) {
// basic name validation
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SubProcessBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SubProcessBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/SubProcessBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -154,8 +154,8 @@
Map<String, String> swimlaneMappings = new HashMap<String, String>();
for (Element inElement: XmlUtil.elements(element, "swimlane-mapping")) {
- String swimlane = XmlUtil.attribute(inElement, "swimlane", true, parse);
- String subSwimlane = XmlUtil.attribute(inElement, "sub-swimlane", true, parse);
+ String swimlane = XmlUtil.attribute(inElement, "swimlane", parse);
+ String subSwimlane = XmlUtil.attribute(inElement, "sub-swimlane", parse);
swimlaneMappings.put(swimlane, subSwimlane);
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/repository/JpdlDeployer.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -67,7 +67,7 @@
.execute()
.getDocument();
Element documentElement = document.getDocumentElement();
- String tagName = XmlUtil.getTagLocalName(documentElement);
+ String tagName = documentElement.getLocalName();
if ("process-update".equals(tagName)) {
updateJpdlProcessResource(deployment, resourceName, document);
@@ -173,7 +173,7 @@
Map<String, Element> activityMap = new HashMap<String, Element>();
for (Element element: XmlUtil.elements(containerElement)) {
- String tagName = XmlUtil.getTagLocalName(element);
+ String tagName = element.getLocalName();
if (activityNames.contains(tagName)) {
String activityName = element.getAttribute("name");
activityMap.put(activityName, element);
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlBindingsParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlBindingsParser.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlBindingsParser.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -51,7 +51,7 @@
}
protected Binding instantiateBinding(Element bindingElement, Parse parse) {
- String bindingClassName = XmlUtil.attribute(bindingElement, "binding", true, parse);
+ String bindingClassName = XmlUtil.attribute(bindingElement, "binding", parse);
log.trace("adding jpdl binding "+bindingClassName);
@@ -60,7 +60,7 @@
Class<?> bindingClass = ReflectUtil.classForName(bindingClassName);
TagBinding binding = (TagBinding) bindingClass.newInstance();
- String tagLocalName = XmlUtil.getTagLocalName(bindingElement);
+ String tagLocalName = bindingElement.getLocalName();
if ("activity".equals(tagLocalName)) {
binding.setCategory(JpdlParser.CATEGORY_ACTIVITY);
} else if ("eventlistener".equals(tagLocalName)) {
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 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -160,7 +160,7 @@
parse.contextStackPush(processDefinition);
try {
// process attribues
- String name = XmlUtil.attribute(documentElement, "name", true, parse);
+ String name = XmlUtil.attribute(documentElement, "name", parse);
processDefinition.setName(name);
// make the process language version available for bindings
@@ -210,12 +210,12 @@
String packageName = XmlUtil.attribute(documentElement, "package");
processDefinition.setPackageName(packageName);
- Integer version = XmlUtil.attributeInteger(documentElement, "version", false, parse);
+ Integer version = XmlUtil.attributeInteger(documentElement, "version", parse);
if (version!=null) {
processDefinition.setVersion(version);
}
- String key = XmlUtil.attribute(documentElement, "key", false, parse);
+ String key = XmlUtil.attribute(documentElement, "key");
if (key!=null) {
processDefinition.setKey(key);
}
@@ -232,7 +232,7 @@
// swimlanes
List<Element> swimlaneElements = XmlUtil.elements(documentElement, "swimlane");
for (Element swimlaneElement: swimlaneElements) {
- String swimlaneName = XmlUtil.attribute(swimlaneElement, "name", true, parse);
+ String swimlaneName = XmlUtil.attribute(swimlaneElement, "name", parse);
if (swimlaneName!=null) {
SwimlaneDefinitionImpl swimlaneDefinition =
processDefinition.createSwimlaneDefinition(swimlaneName);
@@ -282,7 +282,7 @@
public void parseActivities(Element documentElement, Parse parse, CompositeElementImpl compositeElement) {
List<Element> elements = XmlUtil.elements(documentElement);
for (Element nestedElement : elements) {
- String tagName = XmlUtil.getTagLocalName(nestedElement);
+ String tagName = nestedElement.getLocalName();
if ("on".equals(tagName)
|| "timer".equals(tagName)
|| "swimlane".equals(tagName)
@@ -391,7 +391,7 @@
// event listeners
List<Element> onElements = XmlUtil.elements(element, "on");
for (Element onElement: onElements) {
- String eventName = XmlUtil.attribute(onElement, "event", true, parse);
+ String eventName = XmlUtil.attribute(onElement, "event", parse);
parseOnEvent(onElement, parse, scopeElement, eventName);
Element timerElement = XmlUtil.element(onElement, "timer");
@@ -431,8 +431,9 @@
eventListenerReference = event.createEventListenerReference(eventListenerDescriptor);
}
- if (XmlUtil.attributeBoolean(eventListenerElement, "propagation", false, parse, false)) {
- eventListenerReference.setPropagationEnabled(true);
+ Boolean propagationEnabled = XmlUtil.attributeBoolean(eventListenerElement, "propagation", parse);
+ if (propagationEnabled!=null) {
+ eventListenerReference.setPropagationEnabled(propagationEnabled);
}
continuationText = XmlUtil.attribute(eventListenerElement, "continue");
@@ -455,7 +456,7 @@
}
} else {
- String tagName = XmlUtil.getTagLocalName(eventListenerElement);
+ String tagName = eventListenerElement.getLocalName();
if ( ! ( (observableElement instanceof TransitionImpl)
&& ( "condition".equals(tagName)
|| "timer".equals(tagName)
@@ -473,7 +474,7 @@
List<Element> transitionElements = XmlUtil.elements(element, "transition");
UnresolvedTransitions unresolvedTransitions = parse.contextStackFind(UnresolvedTransitions.class);
for (Element transitionElement: transitionElements) {
- String transitionName = XmlUtil.attribute(transitionElement, "name", false, parse);
+ String transitionName = XmlUtil.attribute(transitionElement, "name");
Element timerElement = XmlUtil.element(transitionElement, "timer");
if (timerElement!=null) {
@@ -538,7 +539,7 @@
String duedate = XmlUtil.attribute(element, "duedate");
taskDefinition.setDueDateDescription(duedate);
- Integer priority = XmlUtil.attributeInteger(element, "priority", false, parse);
+ Integer priority = XmlUtil.attributeInteger(element, "priority", parse);
if (priority != null) {
taskDefinition.setPriority(priority);
}
@@ -586,13 +587,13 @@
for (Element variableElement: XmlUtil.elements(element, "variable")) {
VariableDefinitionImpl variableDefinition = scopeElement.createVariableDefinition();
- String name = XmlUtil.attribute(variableElement, "name", true, parse);
+ String name = XmlUtil.attribute(variableElement, "name", parse);
variableDefinition.setName(name);
- String type = XmlUtil.attribute(variableElement, "type", true, parse);
+ String type = XmlUtil.attribute(variableElement, "type", parse);
variableDefinition.setTypeName(type);
- Boolean isHistoryEnabled = XmlUtil.attributeBoolean(variableElement, "history", false, parse);
+ Boolean isHistoryEnabled = XmlUtil.attributeBoolean(variableElement, "history", parse);
if (isHistoryEnabled != null) {
variableDefinition.setHistoryEnabled(isHistoryEnabled);
}
@@ -710,7 +711,7 @@
userCodeReference.setCached(false);
}
- Boolean isCached = XmlUtil.attributeBoolean(element, "cache", false, parse, null);
+ Boolean isCached = XmlUtil.attributeBoolean(element, "cache", parse);
if (isCached!=null) {
userCodeReference.setCached(isCached.booleanValue());
}
@@ -719,7 +720,7 @@
}
public ObjectDescriptor parseObjectDescriptor(Element element, Parse parse) {
- return (ObjectDescriptor) ObjectBinding.parseObjectDescriptor(element, parse, WireParser.getInstance());
+ return ObjectBinding.parseObjectDescriptor(element, parse, WireParser.getInstance());
}
public Descriptor parseDescriptor(Element element, Parse parse) {
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/UnresolvedTransition.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/UnresolvedTransition.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/UnresolvedTransition.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -36,7 +36,7 @@
this.transitionElement = transitionElement;
}
public void resolve(ProcessDefinitionImpl processDefinition, Parse parse) {
- String to = XmlUtil.attribute(transitionElement, "to", true, parse);
+ String to = XmlUtil.attribute(transitionElement, "to", parse);
if (to!=null) {
ActivityImpl destination = (ActivityImpl) processDefinition.findActivity(to);
if (destination!=null) {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/EventListenerReference.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/EventListenerReference.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/EventListenerReference.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -33,10 +33,10 @@
private static final long serialVersionUID = 1L;
protected EventListener eventListener;
- protected boolean isEventListenerStateful= false;
+ protected boolean isEventListenerStateful;
protected Descriptor eventListenerDescriptor;
/** does this action accept propagated events ? */
- protected boolean isPropagationEnabled = false;
+ protected boolean isPropagationEnabled;
protected Continuation continuation = Continuation.SYNCHRONOUS;
/** does this action accept propagated events ? Default is false. */
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/TagBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/TagBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/TagBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -59,7 +59,7 @@
) {
return false;
}
- String elementTagLocalName = XmlUtil.getTagLocalName(element);
+ String elementTagLocalName = element.getLocalName();
if (!tagName.equals(elementTagLocalName)) {
return false;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/XmlUtil.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/XmlUtil.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/XmlUtil.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -28,9 +28,6 @@
import java.util.Set;
import java.util.StringTokenizer;
-import org.jbpm.api.JbpmException;
-import org.jbpm.pvm.internal.xml.Parse;
-
import javax.xml.namespace.QName;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
@@ -43,11 +40,12 @@
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
+import org.jbpm.api.JbpmException;
+import org.jbpm.pvm.internal.xml.Parse;
+
/**
* convenience methods to make reading org.w3c.dom models easier.
- *
* @author Tom Baeyens
*/
public class XmlUtil {
@@ -57,52 +55,32 @@
}
public static List<Element> elements(Element element, String tagName) {
- if (element==null) {
+ if (element == null || !element.hasChildNodes()) {
return Collections.emptyList();
}
- NodeList activityList = element.getChildNodes();
- if ( (activityList == null)
- || (activityList.getLength()==0)
- ) {
- return Collections.emptyList();
- }
+
List<Element> elements = new ArrayList<Element>();
- for (int i = 0; i < activityList.getLength(); i++) {
- Node child = activityList.item(i);
- if (Element.class.isAssignableFrom(child.getClass())) {
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) child;
- String childTagName = getTagLocalName(childElement);
- if (childTagName.equals(tagName)) {
- if (elements == null) {
- elements = new ArrayList<Element>();
- }
- elements.add(childElement);
- }
+ String childTagName = childElement.getLocalName();
+
+ if (tagName.equals(childTagName)) elements.add(childElement);
}
}
return elements;
}
public static List<Element> elements(Element element, Set<String> allowedTagNames) {
- if (element==null) {
+ if (element == null || !element.hasChildNodes()) {
return Collections.emptyList();
}
- NodeList activityList = element.getChildNodes();
- if ( (activityList == null)
- || (activityList.getLength()==0)
- ) {
- return Collections.emptyList();
- }
+
List<Element> elements = new ArrayList<Element>();
- for (int i = 0; i < activityList.getLength(); i++) {
- Node child = activityList.item(i);
- if (Element.class.isAssignableFrom(child.getClass())) {
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) child;
- String childTagName = getTagLocalName(childElement);
- if (allowedTagNames.contains(childTagName)) {
- if (elements == null) {
- elements = new ArrayList<Element>();
- }
+ if (allowedTagNames.contains(child.getLocalName())) {
elements.add(childElement);
}
}
@@ -111,95 +89,68 @@
}
public static Element element(Element element, String tagName) {
- return element(element, tagName, false, null);
+ return element(element, tagName, null);
}
- public static Element element(Element element, String tagName, boolean required, Parse parse) {
- if (element==null) {
- return null;
- }
- NodeList activityList = element.getChildNodes();
- for (int i = 0; (i < activityList.getLength()); i++) {
- Node child = activityList.item(i);
- if ((Element.class.isAssignableFrom(child.getClass())) && (getTagLocalName((Element) child)).equals(tagName)) {
- return (Element) child;
+ public static Element element(Element element, String tagName, Parse parse) {
+ if (element != null && element.hasChildNodes()) {
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE && tagName.equals(child.getLocalName())) {
+ return (Element) child;
+ }
}
}
-
- if (required && (parse!=null)) {
- parse.addProblem("nested element <"+XmlUtil.getTagLocalName(element)+"><"+tagName+" ... />... is required", element);
+
+ if (parse != null) {
+ parse.addProblem("missing element " + tagName, element);
}
return null;
}
-
public static List<Element> elements(Element element) {
- if (element==null) {
+ if (element == null || !element.hasChildNodes()) {
return Collections.emptyList();
}
- NodeList activityList = element.getChildNodes();
- if ( (activityList == null)
- || (activityList.getLength()==0)
- ) {
- return Collections.emptyList();
- }
+
List<Element> elements = new ArrayList<Element>();
- if ((activityList != null) && (activityList.getLength() > 0)) {
- elements = new ArrayList<Element>();
- for (int i = 0; i < activityList.getLength(); i++) {
- Node activity = activityList.item(i);
- if (activity instanceof Element) {
- elements.add((Element) activity);
- }
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ elements.add((Element) child);
}
}
return elements;
}
- public static List<Element> elements(Element element, String ns, String localName) {
- if (element==null) {
+ public static List<Element> elements(Element element, String namespace, String localName) {
+ if (element == null || !element.hasChildNodes()) {
return Collections.emptyList();
}
- NodeList activityList = element.getChildNodes();
- if ( (activityList == null)
- || (activityList.getLength()==0)
- ) {
- return Collections.emptyList();
- }
- List<Element> matchingElements = new ArrayList<Element>();
- NodeList nl = element.getChildNodes();
- for (int i=0;i<nl.getLength();i++) {
- Node n = nl.item(i);
- if (n instanceof Element && n.getLocalName() != null && n.getLocalName().equals(localName) && n.getNamespaceURI() != null && n.getNamespaceURI().equals(ns)) {
- matchingElements.add((Element)n);
+
+ List<Element> elements = new ArrayList<Element>();
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ String childNamespace = element.getNamespaceURI();
+ if (child.getNodeType() == Node.ELEMENT_NODE
+ && (namespace != null ? namespace.equals(childNamespace) : childNamespace == null)
+ && localName.equals(element.getLocalName())) {
+ elements.add((Element) child);
}
}
- return matchingElements;
+ return elements;
}
public static List<Element> elementsQName(Element element, Set<QName> allowedTagNames) {
- if (element==null) {
+ if (element == null || !element.hasChildNodes()) {
return Collections.emptyList();
}
- NodeList activityList = element.getChildNodes();
- if ( (activityList == null)
- || (activityList.getLength()==0)
- ) {
- return Collections.emptyList();
- }
+
List<Element> elements = new ArrayList<Element>();
- if (activityList != null) {
- for (int i = 0; i < activityList.getLength(); i++) {
- Node child = activityList.item(i);
- if (Element.class.isAssignableFrom(child.getClass())) {
- Element childElement = (Element) child;
- QName childElementQName = new QName(childElement.getNamespaceURI(), childElement.getLocalName());
- if (allowedTagNames.contains(childElementQName)) {
- if (elements == null) {
- elements = new ArrayList<Element>();
- }
- elements.add(childElement);
- }
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ Element childElement = (Element) child;
+ QName childQName = new QName(childElement.getNamespaceURI(),
+ childElement.getLocalName());
+ if (allowedTagNames.contains(childQName)) {
+ elements.add(childElement);
}
}
}
@@ -207,12 +158,14 @@
}
public static Element element(Element element) {
- Element onlyChild = null;
- List<Element> elements = elements(element);
- if (!elements.isEmpty()) {
- onlyChild = elements.get(0);
+ if (element != null && element.hasChildNodes()) {
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ return (Element) child;
+ }
+ }
}
- return onlyChild;
+ return null;
}
public static String toString(Node node) {
@@ -226,7 +179,7 @@
StringWriter stringWriter = new StringWriter();
transformer.transform(new DOMSource(node), new StreamResult(stringWriter));
return stringWriter.toString();
- }
+ }
catch (TransformerException e) {
throw new JbpmException("could not transform dom node to string", e);
}
@@ -238,8 +191,7 @@
public static boolean isTextOnly(Element element) {
for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child.getNodeType() == Node.ELEMENT_NODE)
- return false;
+ if (child.getNodeType() == Node.ELEMENT_NODE) return false;
}
return true;
}
@@ -259,130 +211,118 @@
}
public static List<Node> contents(Element element) {
- NodeList activityList = element.getChildNodes();
- if ((activityList == null) || (activityList.getLength() == 0)) {
+ if (element == null || !element.hasChildNodes()) {
return Collections.emptyList();
}
List<Node> contents = new ArrayList<Node>();
- for (int i = 0; i < activityList.getLength(); i++) {
- contents.add((Node) activityList.item(i));
+ for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
+ contents.add(child);
}
-
return contents;
}
- public static String getTagLocalName(Element element) {
- if (element == null) {
- return null;
- }
- String localName = element.getLocalName();
- if (localName != null) {
- return localName;
- }
- return element.getTagName();
- }
-
- /** the attribute value or null if the attribute is not present */
+ /**
+ * retrieves an attribute value by name.
+ * @return the attribute value or <code>null</code> if there is no such attribute
+ */
public static String attribute(Element element, String attributeName) {
Attr attribute = element.getAttributeNode(attributeName);
return attribute != null ? attribute.getValue() : null;
}
- /** convenience method to combine extraction of a string attribute value.
- *
- * If the attribute exists, it is returned. If the attribute is not present, null
- * is returned. The attribute is not present and it is required,
- * a problem will be added to the parse. */
- public static String attribute(Element element, String attributeName, boolean required, Parse parse) {
- return attribute(element, attributeName, required, parse, null);
+ /**
+ * retrieves an attribute value by name.
+ * @return the attribute value or <code>defaultValue</code> if there is no such attribute
+ */
+ public static String attribute(Element element, String attributeName, String defaultValue) {
+ return attribute(element, attributeName, null, defaultValue);
}
- /** convenience method to combine extraction of a string attribute value.
- *
- * If the attribute exists, it is returned. If the attribute is not present, the
- * defaultValue is returned. The attribute is not present and it is required,
- * a problem will be added to the parse. */
- public static String attribute(Element element, String attributeName, boolean required, Parse parse, String defaultValue) {
+ /**
+ * retrieves an attribute value by name. if the attribute is not present, a problem will be
+ * added to the parse.
+ * @return the attribute value or <code>null</code> if there is no such attribute
+ */
+ public static String attribute(Element element, String attributeName, Parse parse) {
+ return attribute(element, attributeName, parse, null);
+ }
+
+ /**
+ * retrieves an attribute value by name. if the attribute is not present, a problem will be
+ * added to the parse.
+ * @return the attribute value or <code>defaultValue</code> if there is no such attribute
+ */
+ public static String attribute(Element element, String attributeName, Parse parse,
+ String defaultValue) {
Attr attribute = element.getAttributeNode(attributeName);
if (attribute != null) {
String value = attribute.getValue();
- if (value.length() == 0 && required) {
- parse.addProblem("attribute <"+XmlUtil.getTagLocalName(element)+" "+attributeName+"=\"\" is empty", element);
+ if (value.length() == 0) {
+ parse.addProblem("attribute <"+element.getLocalName()+" "+attributeName+"=\"\" is empty", element);
}
return value;
}
- if (required) {
- parse.addProblem("attribute <"+XmlUtil.getTagLocalName(element)+" "+attributeName+"=\"...\" is required", element);
+ if (parse != null) {
+ parse.addProblem("attribute <"+element.getLocalName()+" "+attributeName+"=\"...\" is required", element);
}
-
return defaultValue;
}
-
-
- /** parse an attribute as an integer. */
- public static Integer attributeInteger(Element element, String attributeName, boolean required, Parse parse) {
- String valueText = attribute(element, attributeName, required, parse);
- if (valueText!=null) {
+ /** retrieves an attribute value by name. */
+ public static Integer attributeInteger(Element element, String attributeName, Parse parse) {
+ Attr attribute = element.getAttributeNode(attributeName);
+ if (attribute != null) {
+ String attributeValue = attribute.getValue();
try {
- return Integer.parseInt(valueText);
- } catch (NumberFormatException e) {
- parse.addProblem(errorMessageAttribute(element, attributeName, valueText, "value not parsable as integer"), element);
+ return Integer.parseInt(attributeValue);
}
+ catch (NumberFormatException e) {
+ parse.addProblem(errorMessageAttribute(element, attributeName, attributeValue, e.getMessage()), element);
+ }
}
-
return null;
}
/** parse an attribute as an boolean. */
- public static Boolean attributeBoolean(Element element, String attributeName, boolean required, Parse parse) {
- return attributeBoolean(element, attributeName, required, parse, null);
- }
-
- /** parse an attribute as an boolean. */
- public static Boolean attributeBoolean(Element element, String attributeName, boolean required, Parse parse, Boolean defaultValue) {
- String valueText = attribute(element, attributeName, required, parse);
- if (valueText!=null) {
- Boolean value = parseBooleanValue(valueText);
- if (value==null) {
- parse.addProblem(errorMessageAttribute(element, attributeName, valueText, "value not in {true, enabled, on, false, disabled, off}"), element);
- }
- return value;
+ public static Boolean attributeBoolean(Element element, String attributeName, Parse parse) {
+ Attr attribute = element.getAttributeNode(attributeName);
+ if (attribute != null) {
+ String attributeValue = attribute.getValue();
+ Boolean value = parseBooleanValue(attributeValue);
+ if (value != null) return value;
+
+ String message = errorMessageAttribute(element, attributeName, attributeValue,
+ "value not in {true, enabled, on, false, disabled, off}");
+ parse.addProblem(message, element);
}
- return defaultValue;
+ return null;
}
public static Boolean parseBooleanValue(String valueText) {
- if (valueText!=null) {
+ if (valueText != null) {
// if we have to check for value true
- if ( ("true".equals(valueText))
- || ("enabled".equals(valueText))
- || ("on".equals(valueText))
- ) {
- return Boolean.TRUE;
-
- } else if ( ("false".equals(valueText))
- || ("disabled".equals(valueText))
- || ("off".equals(valueText))
- ) {
+ if ("true".equals(valueText) || "enabled".equals(valueText) || "on".equals(valueText)) {
+ return Boolean.TRUE;
+ }
+ if ("false".equals(valueText) || "disabled".equals(valueText) || "off".equals(valueText)) {
return Boolean.FALSE;
}
}
-
return null;
}
-
- public static String errorMessageAttribute(Element element, String attributeName, String attributeValue, String message) {
- return "attribute <"+XmlUtil.getTagLocalName(element)+" "+attributeName+"=\""+attributeValue+"\" "+message;
+
+ public static String errorMessageAttribute(Element element, String attributeName,
+ String attributeValue, String message) {
+ return "attribute <" + element.getLocalName() + " " + attributeName + "=\""
+ + attributeValue + "\" " + message;
}
public static List<String> parseList(Element element, String singularTagName) {
// a null value for text represents a wildcard
String text = XmlUtil.attribute(element, singularTagName + "s");
- // so next we'll convert a '*' into the text null value, which indicates a
- // wildcard
+ // convert '*' into the text null value, which indicates a wildcard
if ("*".equals(text)) {
text = null;
}
@@ -396,9 +336,7 @@
/**
* parses comma or space separated list. A null return value means a wildcard.
- *
- * @return List of tokens or null if the commaSeparatedListText is null, '*',
- * or empty
+ * @return List of tokens or null if the commaSeparatedListText is null, '*', or empty
*/
public static List<String> parseCommaSeparatedList(String commaSeparatedListText) {
List<String> entries = null;
@@ -434,7 +372,8 @@
int colonIndex = text.indexOf(':');
if (colonIndex == -1) {
namespaceValue = new NamespaceValue(null, text);
- } else {
+ }
+ else {
String prefix = text.substring(0, colonIndex);
String localPart = null;
if (text.length() > colonIndex + 1) {
@@ -451,16 +390,19 @@
NamespaceValue namespaceValue = attributeNamespaceValue(element, attributeName);
String text = attribute(element, attributeName);
- if (namespaceValue!=null) {
- if (namespaceValue.prefix==null) {
+ if (namespaceValue != null) {
+ if (namespaceValue.prefix == null) {
qname = new QName(text);
- } else {
+ }
+ else {
String uri = element.lookupNamespaceURI(namespaceValue.prefix);
- if (uri==null) {
- throw new JbpmException("unknown prefix in qname "+text);
- } else if (namespaceValue.localPart==null) {
- throw new JbpmException("no local part in qname "+text);
- } else {
+ if (uri == null) {
+ throw new JbpmException("unknown prefix in qname " + text);
+ }
+ else if (namespaceValue.localPart == null) {
+ throw new JbpmException("no local part in qname " + text);
+ }
+ else {
qname = new QName(uri, namespaceValue.localPart, namespaceValue.prefix);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/AbstractCollectionBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/AbstractCollectionBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/AbstractCollectionBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -28,9 +28,9 @@
descriptor.setClassName(className);
}
- Boolean isSynchronized = XmlUtil.attributeBoolean(element, "synchronized", false, parse);
+ Boolean isSynchronized = XmlUtil.attributeBoolean(element, "synchronized", parse);
if (isSynchronized!=null) {
- descriptor.setSynchronized(isSynchronized.booleanValue());
+ descriptor.setSynchronized(isSynchronized);
}
List<Descriptor> valueDescriptors = new ArrayList<Descriptor>();
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/BasicTypeBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/BasicTypeBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/BasicTypeBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -20,14 +20,14 @@
String value = element.getAttribute("value");
descriptor = createDescriptor(value, element, parse);
} else {
- parse.addProblem("attribute 'value' is required in element '"+XmlUtil.getTagLocalName(element)+"': "+XmlUtil.toString(element), element);
+ parse.addProblem("attribute 'value' is required in element '"+element.getLocalName()+"': "+XmlUtil.toString(element), element);
}
return descriptor;
}
public String createValueExceptionMessage(String message, Element element) {
- return XmlUtil.getTagLocalName(element)+" has invalid formatted value attribute: "+(message!=null ? message+": " : "")+XmlUtil.toString(element);
+ return element.getLocalName()+" has invalid formatted value attribute: "+(message!=null ? message+": " : "")+XmlUtil.toString(element);
}
/** subclasses can be sure that the value is not null.
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/CommandServiceBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/CommandServiceBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/CommandServiceBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -23,17 +23,17 @@
import java.util.List;
+import org.w3c.dom.Element;
+
import org.jbpm.pvm.internal.cmd.CommandService;
import org.jbpm.pvm.internal.svc.AsyncCommandService;
import org.jbpm.pvm.internal.svc.DefaultCommandService;
-import org.jbpm.pvm.internal.svc.SerializeInterceptor;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.descriptor.CommandServiceDescriptor;
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;
/** parses a descriptor for a creating {@link DefaultCommandService}.
*
@@ -67,11 +67,13 @@
}
protected CommandService getCommandService(Element element, Parse parse, Parser parser) {
- if ( XmlUtil.attributeBoolean(element, "async", false, parse, Boolean.FALSE)) {
+ Boolean async = XmlUtil.attributeBoolean(element, "async", parse);
+ if (Boolean.TRUE.equals(async)) {
+ AsyncCommandService asyncCommandService = new AsyncCommandService();
- AsyncCommandService asyncCommandService = new AsyncCommandService();
- if (XmlUtil.attributeBoolean(element, "propagate-auth", false, parse)) {
- asyncCommandService.setPropagateUserId(true);
+ Boolean propagateUserId = XmlUtil.attributeBoolean(element, "propagate-auth", parse);
+ if (propagateUserId!=null) {
+ asyncCommandService.setPropagateUserId(propagateUserId);
}
return asyncCommandService;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateConfigurationBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateConfigurationBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateConfigurationBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -88,7 +88,7 @@
List<Element> configElements = XmlUtil.elements(element);
for (Element configElement: configElements) {
- if ("cfg".equals(XmlUtil.getTagLocalName(configElement))) {
+ if ("cfg".equals(configElement.getLocalName())) {
if (configElement.hasAttribute("resource")) {
String resource = configElement.getAttribute("resource");
log.trace("adding hibernate configuration resource "+resource);
@@ -108,7 +108,7 @@
parse.addProblem("exactly 1 attribute in {resource, file, url} was expected in cfg: "+XmlUtil.toString(configElement), element);
}
- } else if ("mapping".equals(XmlUtil.getTagLocalName(configElement))) {
+ } else if ("mapping".equals(configElement.getLocalName())) {
if (configElement.hasAttribute("resource")) {
String resource = configElement.getAttribute("resource");
log.trace("adding hibernate mapping resource "+resource);
@@ -133,11 +133,11 @@
parse.addProblem("exactly 1 attribute in {resource, file, class, url} was expected in mapping: "+XmlUtil.toString(element));
}
- } else if ("properties".equals(XmlUtil.getTagLocalName(configElement))) {
+ } else if ("properties".equals(configElement.getLocalName())) {
PropertiesDescriptor propertiesDescriptor = (PropertiesDescriptor) propertiesBinding.parse(configElement, parse, parser);
descriptor.setPropertiesDescriptor(propertiesDescriptor);
- } else if ("cache-configuration".equals(XmlUtil.getTagLocalName(configElement))) {
+ } else if ("cache-configuration".equals(configElement.getLocalName())) {
StreamInput streamSource = null;
String cacheUsage = configElement.getAttribute("usage");
@@ -192,11 +192,11 @@
if (cacheElements!=null) {
for (Element cacheElement : cacheElements) {
- if ("class-cache".equals(XmlUtil.getTagLocalName(cacheElement))) {
+ if ("class-cache".equals(cacheElement.getLocalName())) {
String className = cacheElement.getAttribute("class");
descriptor.addClassToCache(className, cacheUsage);
- } else if ("collection-cache".equals(XmlUtil.getTagLocalName(cacheElement))) {
+ } else if ("collection-cache".equals(cacheElement.getLocalName())) {
String collection = cacheElement.getAttribute("collection");
descriptor.addCollectionToCache(collection, cacheUsage);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/HibernateSessionBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -46,12 +46,12 @@
descriptor.setFactoryName(element.getAttribute("factory"));
}
- Boolean tx = XmlUtil.attributeBoolean(element, "tx", false, parse);
+ Boolean tx = XmlUtil.attributeBoolean(element, "tx", parse);
if (tx!=null) {
descriptor.setTx(tx);
}
- Boolean useCurrent = XmlUtil.attributeBoolean(element, "current", false, parse);
+ Boolean useCurrent = XmlUtil.attributeBoolean(element, "current", parse);
// if usage of current session is specified
if (useCurrent!=null) {
// set it accordingly
@@ -60,7 +60,7 @@
descriptor.setClose( !useCurrent );
}
- Boolean close = XmlUtil.attributeBoolean(element, "close", false, parse);
+ Boolean close = XmlUtil.attributeBoolean(element, "close", parse);
if (close!=null) {
descriptor.setClose(close);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/JobExecutorBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/JobExecutorBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/JobExecutorBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -75,7 +75,8 @@
parseIntAttribute(element, "lock", descriptor, "lockMillis", parse);
// by default invoke the start method, unless auto-start is disabled
- if (XmlUtil.attributeBoolean(element, "auto-start", false, parse, true)) {
+ Boolean autoStart = XmlUtil.attributeBoolean(element, "auto-start", parse);
+ if (autoStart == null || autoStart.booleanValue()) {
InvokeOperation invokeStartOperation = new InvokeOperation();
invokeStartOperation.setMethodName("start");
descriptor.addOperation(invokeStartOperation);
@@ -87,7 +88,7 @@
}
private void parseIntAttribute(Element element, String attributeName, ObjectDescriptor descriptor, String fieldName, Parse parse) {
- Integer intValue = XmlUtil.attributeInteger(element, attributeName, false, parse);
+ Integer intValue = XmlUtil.attributeInteger(element, attributeName, parse);
if (intValue!=null) {
descriptor.addInjection(fieldName, new IntegerDescriptor(intValue));
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailTemplateBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -67,7 +67,7 @@
// create the mail template and add it to the registry
MailTemplate mailTemplate = parseMailTemplate(element, parse);
- String templateName = XmlUtil.attribute(element, "name", true, parse);
+ String templateName = XmlUtil.attribute(element, "name", parse);
templateRegistry.addTemplate(templateName, mailTemplate);
return templateRegistryDescriptor;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MapBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MapBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MapBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -53,16 +53,16 @@
descriptor.setClassName(className);
}
- Boolean isSynchronized = XmlUtil.attributeBoolean(element, "synchronized", false, parse);
+ Boolean isSynchronized = XmlUtil.attributeBoolean(element, "synchronized", parse);
if (isSynchronized!=null) {
- descriptor.setSynchronized(isSynchronized.booleanValue());
+ descriptor.setSynchronized(isSynchronized);
}
List<Descriptor> keyDescriptors = new ArrayList<Descriptor>();
List<Descriptor> valueDescriptors = new ArrayList<Descriptor>();
List<Element> elements = XmlUtil.elements(element);
for (Element entryElement: elements) {
- if ("entry".equals(XmlUtil.getTagLocalName(entryElement))) {
+ if ("entry".equals(entryElement.getLocalName())) {
// key
Element keyElement = XmlUtil.element(entryElement, "key");
Element keyDescriptorElement = (keyElement!=null ? XmlUtil.element(keyElement) : null);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MessageSessionBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MessageSessionBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MessageSessionBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -59,7 +59,7 @@
JndiDescriptor jndiDescriptor = new JndiDescriptor(jmsSessionJndiName);
objectDescriptor.addInjection("jmsSession", jndiDescriptor);
} else {
- parse.addProblem("attribute <"+XmlUtil.getTagLocalName(element)+" session-jndi=\"...\" is required when target=\"jms\"", element);
+ parse.addProblem("attribute <"+element.getLocalName()+" session-jndi=\"...\" is required when target=\"jms\"", element);
}
if (element.hasAttribute("destination-jndi")) {
@@ -67,7 +67,7 @@
JndiDescriptor jndiDescriptor = new JndiDescriptor(jmsDestinationJndiName);
objectDescriptor.addInjection("jmsDestination", jndiDescriptor);
} else {
- parse.addProblem("attribute <"+XmlUtil.getTagLocalName(element)+" destination-jndi=\"...\" is required when target=\"jms\"", element);
+ parse.addProblem("attribute <"+element.getLocalName()+" destination-jndi=\"...\" is required when target=\"jms\"", element);
}
} else {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/ObjectBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -73,7 +73,6 @@
public static ObjectDescriptor parseObjectDescriptor(Element element, Parse parse, Parser parser) {
ObjectDescriptor descriptor = new ObjectDescriptor();
- Parser wireParser = (Parser) parser;
String className = XmlUtil.attribute(element, "class");
String expr = XmlUtil.attribute(element, "expr");
String factoryObjectName = XmlUtil.attribute(element, "factory");
@@ -91,7 +90,7 @@
Element constructorElement = XmlUtil.element(element, "constructor");
if (constructorElement!=null) {
List<Element> argElements = XmlUtil.elements(constructorElement, "arg");
- List<ArgDescriptor> argDescriptors = wireParser.parseArgs(argElements, parse);
+ List<ArgDescriptor> argDescriptors = parser.parseArgs(argElements, parse);
descriptor.setArgDescriptors(argDescriptors);
if (element.hasAttribute("method")) {
@@ -123,7 +122,7 @@
descriptor.setMethodName(element.getAttribute("method"));
List<Element> argElements = XmlUtil.elements(element, "arg");
- List<ArgDescriptor> argDescriptors = wireParser.parseArgs(argElements, parse);
+ List<ArgDescriptor> argDescriptors = parser.parseArgs(argElements, parse);
descriptor.setArgDescriptors(argDescriptors);
} else if ( (factoryObjectName!=null)
|| (factoryElement!=null)
@@ -161,9 +160,9 @@
descriptor.setOperations(operations);
// autowiring
- Boolean isAutoWireEnabled = XmlUtil.attributeBoolean(element, "auto-wire", false, parse);
+ Boolean isAutoWireEnabled = XmlUtil.attributeBoolean(element, "auto-wire", parse);
if (isAutoWireEnabled!=null) {
- descriptor.setAutoWireEnabled(isAutoWireEnabled.booleanValue());
+ descriptor.setAutoWireEnabled(isAutoWireEnabled);
}
return descriptor;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PropertiesBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PropertiesBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PropertiesBinding.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -59,9 +59,9 @@
descriptor.setUrl(element.getAttribute("url"));
}
- Boolean isXml = XmlUtil.attributeBoolean(element, "is-xml", false, parse);
+ Boolean isXml = XmlUtil.attributeBoolean(element, "is-xml", parse);
if (isXml!=null) {
- descriptor.setXml(isXml.booleanValue());
+ descriptor.setXml(isXml);
}
List<Descriptor> keyDescriptors = new ArrayList<Descriptor>();
@@ -69,7 +69,7 @@
List<Element> elements = XmlUtil.elements(element);
for (Element propertyElement: elements) {
- if ("property".equals(XmlUtil.getTagLocalName(propertyElement))) {
+ if ("property".equals(propertyElement.getLocalName())) {
// key
String name = XmlUtil.attribute(propertyElement, "name");
// value
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/Parser.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/Parser.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/xml/Parser.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -507,7 +507,7 @@
public Object parseElement(Element element, Parse parse, String category) {
Object object = null;
- String tagName = XmlUtil.getTagLocalName(element);
+ String tagName = element.getLocalName();
Binding binding = getBinding(element, category);
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/AssignTest.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -21,113 +21,112 @@
*/
package org.jbpm.test.activity.assign;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.Map;
import org.jbpm.api.ProcessInstance;
import org.jbpm.test.JbpmTestCase;
-
/**
* @author Tom Baeyens
*/
public class AssignTest extends JbpmTestCase {
- public void testValueExpressionToVar() {
- deployJpdlXmlString(
- "<process name='AssignTest'>" +
- " <start>" +
- " <transition to='resolve' />" +
- " </start>" +
- " <assign name='resolve' expr='#{person.name}' to-var='result'>" +
- " <transition to='wait' />" +
- " </assign>" +
- " <state name='wait' />" +
- "</process>"
- );
-
+ public void testFromExprToVar() {
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ + " <start>"
+ + " <transition to='resolve' />"
+ + " </start>"
+ + " <assign name='resolve' from-expr='#{person.name}' to-var='result'>"
+ + " <transition to='wait' />"
+ + " </assign>"
+ + " <state name='wait' />"
+ + "</process>");
+
Person person = new Person();
person.setName("johndoe");
+ Map<String, ?> variables = Collections.singletonMap("person", person);
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("person", person);
ProcessInstance processInstance = executionService.startProcessInstanceByKey("AssignTest", variables);
- executionService.signalExecutionById(processInstance.getId());
-
assertEquals("johndoe", executionService.getVariable(processInstance.getId(), "result"));
}
- public void testMethodExpressionToVar() {
- deployJpdlXmlString(
- "<process name='AssignTest'>" +
- " <start>" +
- " <transition to='resolve' />" +
- " </start>" +
- " <assign name='resolve' expr='#{person.hello()}' to-var='result'>" +
- " <transition to='wait' />" +
- " </assign>" +
- " <state name='wait' />" +
- "</process>"
- );
-
+ public void testFromMethodExprToVar() {
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ + " <start>"
+ + " <transition to='resolve' />"
+ + " </start>"
+ + " <assign name='resolve' from-expr='#{person.toString()}' to-var='result'>"
+ + " <transition to='wait' />"
+ + " </assign>"
+ + " <state name='wait' />"
+ + "</process>");
+
Person person = new Person();
person.setName("johndoe");
+ Map<String, ?> variables = Collections.singletonMap("person", person);
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("person", person);
ProcessInstance processInstance = executionService.startProcessInstanceByKey("AssignTest", variables);
- executionService.signalExecutionById(processInstance.getId());
-
- assertEquals("goodby", executionService.getVariable(processInstance.getId(), "result"));
+ assertEquals("Person(johndoe)", executionService.getVariable(processInstance.getId(), "result"));
}
- public void testMethodWithParameterExpressionToVar() {
- deployJpdlXmlString(
- "<process name='AssignTest'>" +
- " <start>" +
- " <transition to='resolve' />" +
- " </start>" +
- " <assign name='resolve' expr=\"#{person.hello('Joe')}\" to-var='result'>" +
- " <transition to='wait' />" +
- " </assign>" +
- " <state name='wait' />" +
- "</process>"
- );
-
+ public void testFromMethodParamExprToVar() {
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ + " <start>"
+ + " <transition to='resolve' />"
+ + " </start>"
+ + " <assign name='resolve' from-expr=\"#{person.sayHi('Joe')}\" to-var='result'>"
+ + " <transition to='wait' />"
+ + " </assign>"
+ + " <state name='wait' />"
+ + "</process>");
+
Person person = new Person();
person.setName("johndoe");
+ Map<String, ?> variables = Collections.singletonMap("person", person);
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("person", person);
ProcessInstance processInstance = executionService.startProcessInstanceByKey("AssignTest", variables);
- executionService.signalExecutionById(processInstance.getId());
-
assertEquals("Hi, Joe", executionService.getVariable(processInstance.getId(), "result"));
}
- public void testWireObjectToExpression() {
- deployJpdlXmlString(
- "<process name='AssignTest'>" +
- " <start>" +
- " <transition to='resolve' />" +
- " </start>" +
- " <assign name='resolve' to-expr='#{person.address.street}'>" +
- " <string value='gasthuisstraat' />" +
- " <transition to='wait' />" +
- " </assign>" +
- " <state name='wait' />" +
- "</process>"
- );
-
+ public void testFromDescToExpr() {
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ + " <start>"
+ + " <transition to='resolve' />"
+ + " </start>"
+ + " <assign name='resolve' to-expr='#{person.address.street}'>"
+ + " <from><string value='gasthuisstraat' /></from>"
+ + " <transition to='wait' />"
+ + " </assign>"
+ + " <state name='wait' />"
+ + "</process>");
+
Person person = new Person();
person.setName("johndoe");
+ Map<String, ?> variables = Collections.singletonMap("person", person);
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("person", person);
ProcessInstance processInstance = executionService.startProcessInstanceByKey("AssignTest", variables);
- executionService.signalExecutionById(processInstance.getId());
-
person = (Person) executionService.getVariable(processInstance.getId(), "person");
assertEquals("gasthuisstraat", person.getAddress().getStreet());
}
+
+ public void testFromVarToVar() {
+ deployJpdlXmlString("<process name='AssignTest' xmlns='http://jbpm.org/4.4/jpdl'>"
+ + " <start>"
+ + " <transition to='resolve' />"
+ + " </start>"
+ + " <assign name='resolve' from-var='person' to-var='result'>"
+ + " <transition to='wait' />"
+ + " </assign>"
+ + " <state name='wait' />"
+ + "</process>");
+
+ Person person = new Person();
+ person.setName("johndoe");
+ Map<String, ?> variables = Collections.singletonMap("person", person);
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("AssignTest", variables);
+ person = (Person) executionService.getVariable(processInstance.getId(), "result");
+ assertEquals("johndoe", person.getName());
+ }
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/Person.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/Person.java 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/assign/Person.java 2010-06-10 11:10:39 UTC (rev 6398)
@@ -23,38 +23,33 @@
import java.io.Serializable;
-
/**
* @author Tom Baeyens
*/
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
-
+
String name;
Address address = new Address();
String[] emails;
-
- public String hello() {
- return "goodby";
+
+ public String sayHi(String name) {
+ return "Hi, " + name;
}
-
- public String hello(String name) {
- return "Hi, "+name;
- }
-
+
public String getName() {
return name;
}
-
+
public void setName(String name) {
this.name = name;
}
-
+
public Address getAddress() {
return address;
}
-
+
public void setAddress(Address address) {
this.address = address;
}
@@ -66,4 +61,8 @@
public void setEmails(String[] emails) {
this.emails = emails;
}
+
+ public String toString() {
+ return "Person(" + name + ')';
+ }
}
Modified: jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml
===================================================================
--- jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml 2010-06-09 17:46:55 UTC (rev 6397)
+++ jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch06-Jpdl.xml 2010-06-10 11:10:39 UTC (rev 6398)
@@ -2165,11 +2165,102 @@
</para>
</section>
+ <!-- ### ASSIGN ######################################################## -->
+
+ <section id="assign">
+ <title><literal>assign</literal></title>
+ <para>The <literal>assign</literal> activity retrieves a value and assigns it
+ to a target location.</para>
+ <table><title><literal>assign</literal> attributes:</title>
+ <tgroup cols="5" rowsep="1" colsep="1">
+ <thead>
+ <row>
+ <entry>Attribute</entry>
+ <entry>Type</entry>
+ <entry>Default</entry>
+ <entry>Required?</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>from-var</literal></entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry morerows="1">one of <literal>from-var</literal>, <literal>from-expr</literal>, <literal>from</literal> is required</entry>
+ <entry>variable that provides the source value</entry>
+ </row>
+ <row>
+ <entry><literal>from-expr</literal></entry>
+ <entry>expression</entry>
+ <entry></entry>
+ <entry>expression that resolves the source value</entry>
+ </row>
+ <row>
+ <entry><literal>lang</literal></entry>
+ <entry>string</entry>
+ <entry>default <emphasis role="bold">expression</emphasis> language defined in <xref linkend="scripting"/></entry>
+ <entry>optional</entry>
+ <entry>language in which <literal>from-expr</literal> is written</entry>
+ </row>
+ <row>
+ <entry><literal>to-var</literal></entry>
+ <entry>string</entry>
+ <entry></entry>
+ <entry morerows="1">one of <literal>to-var</literal>, <literal>to-expr</literal> is required</entry>
+ <entry>variable that provides the target location</entry>
+ </row>
+ <row>
+ <entry><literal>to-expr</literal></entry>
+ <entry>expression</entry>
+ <entry></entry>
+ <entry>expression that resolves the target location</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <table><title><literal>assign</literal> elements:</title>
+ <tgroup cols="3" rowsep="1" colsep="1">
+ <thead>
+ <row>
+ <entry>Element</entry>
+ <entry>Multiplicity</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>from</literal></entry>
+ <entry>0..1</entry>
+ <entry>descriptor that constructs the source value</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <para>Every form of <literal>from</literal> can be combined with any form
+ of <literal>to</literal>. The listing below simply assigns a variable to
+ another.</para>
+ <programlisting><![CDATA[<assign name='resolve' from-expr='#{person.name}' to-var='result'>
+ <transition to='wait' />
+</assign>]]></programlisting>
+ <para>The next example shows an expression value being assigned to a
+ variable.</para>
+ <programlisting><![CDATA[<assign name='resolve' from-var='person' to-var='result'>
+ <transition to='wait' />
+</assign>]]></programlisting>
+ <para>Our last example presents a value constructed by a descriptor being
+ assigned to the expression location.</para>
+ <programlisting><![CDATA[<assign name='resolve' to-expr='#{person.address.street}'>
+ <from><string value='gasthuisstraat' /></from>
+ <transition to='wait' />
+</assign>]]></programlisting>
+ </section>
+
<!-- ### HQL ########################################################### -->
<section id="hql">
<title><literal>hql</literal></title>
- <para>With the<literal>hql</literal> activity, a HQL query can be performed
+ <para>With the <literal>hql</literal> activity, a HQL query can be performed
on the database and the result is stored in a process variable.
</para>
<table><title><literal>hql</literal> attributes:</title>
13 years, 11 months
JBoss JBPM SVN: r6397 - in jbpm4/trunk/modules: examples/src/test/java/org/jbpm/examples/concurrency and 9 other directories.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-06-09 13:46:55 -0400 (Wed, 09 Jun 2010)
New Revision: 6397
Added:
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/ForEachTest.java
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/process.jpdl.xml
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java
Modified:
jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java
jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.bindings.xml
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
Log:
JBPM-2414: for each activity
Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd 2010-06-09 17:35:57 UTC (rev 6396)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl-4.4.xsd 2010-06-09 17:46:55 UTC (rev 6397)
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
- targetNamespace="http://jbpm.org/4.4/jpdl"
- xmlns:tns="http://jbpm.org/4.4/jpdl"
+ targetNamespace="http://jbpm.org/jpdl/4.4"
+ xmlns:tns="http://jbpm.org/jpdl/4.4"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
@@ -219,6 +219,23 @@
</element>
<!-- ~~~ FORK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
+ <element name="foreach">
+ <annotation><documentation>Spawns concurrent paths of execution
+ over each element of a collection.
+ </documentation></annotation>
+ <complexType>
+ <sequence>
+ <element name="description" minOccurs="0" type="string" />
+ <element ref="tns:on" minOccurs="0" maxOccurs="unbounded"/>
+ <element ref="tns:transition" minOccurs="0" maxOccurs="unbounded" />
+ </sequence>
+ <attributeGroup ref="tns:activityAttributes" />
+ <attribute name="var" type="string" default="var"/>
+ <attribute name="in" type="string" use="required"/>
+ </complexType>
+ </element>
+
+ <!-- ~~~ FORK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<element name="fork">
<annotation><documentation>Spawns multiple concurrent paths of
execution.
@@ -245,7 +262,7 @@
<element ref="tns:transition" minOccurs="0" maxOccurs="unbounded" />
</sequence>
<attributeGroup ref="tns:activityAttributes" />
- <attribute name="multiplicity" type="int" />
+ <attribute name="multiplicity" type="string" />
<attribute name="lockmode" default="upgrade">
<simpleType>
<restriction base="string">
Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/ForEachTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/ForEachTest.java (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/concurrency/foreach/ForEachTest.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -0,0 +1,166 @@
+/*
+ * 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.concurrency.foreach;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class ForEachTest extends JbpmTestCase {
+
+ String deploymentId;
+ String deptSales;
+ String deptHR;
+ String deptFinance;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // create identities
+ deptSales = identityService.createGroup("sales-dept");
+ deptHR = identityService.createGroup("hr-dept");
+ deptFinance = identityService.createGroup("finance-dept");
+
+ identityService.createUser("johndoe", "John", "Doe");
+ identityService.createMembership("johndoe", deptSales, "SalesManager");
+
+ identityService.createUser("joesmoe", "Joe", "Smoe");
+ identityService.createMembership("joesmoe", deptHR, "HRMana!
ger");
+
+ identityService.createUser("janedoe", "Jane", "D!
oe");
+
identityService.createMembership("janedoe", deptFinance, "FinanceManager");
+
+ deploymentId = repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/examples/concurrency/foreach/process.jpdl.xml").deploy();
+ }
+
+ protected void tearDown() throws Exception {
+ repositoryService.deleteDeploymentCascade(deploymentId);
+
+ // delete identities
+ identityService.deleteGroup(deptSales);
+ identityService.deleteGroup(deptHR);
+ identityService.deleteGroup(deptFinance);
+ identityService.deleteUser("johndoe");
+ identityService.deleteUser("joesmoe");
+ identityService.deleteUser("janedoe");
+
+ super.tearDown();
+ }
+
+ public void testForEachCompleteAll() {
+
+ HashMap<String, Object> variables = new HashMap<String, Object>();
+ variables.put("listOfDepartments", new String[] { "sales-dept", "hr-dept", "finance-dept" });
+ variables.put("joinAt", 3);
+
+ ProcessInstance processInstance = executionService.startProc!
essInstanceByKey("ForEachFork", variables);
+ String processInstanceId = processInstance.getId();
+
+ // there should be 3 forked executions - same as number of departments
+ assertEquals(3, processInstance.getExecutions().size());
+
+ List<Task> taskListSales = taskService.findGroupTasks("johndoe");
+ assertEquals("Expected a single task in johndoe's task list", 1, taskListSales.size());
+
+ List<Task> taskListHR = taskService.findGroupTasks("joesmoe");
+ assertEquals("Expected a single task in joesmoe's task list", 1, taskListHR.size());
+
+ List<Task> taskListFinance = taskService.findGroupTasks("janedoe");
+ assertEquals("Expected a single task in janedoe's task list", 1, taskListFinance.size());
+
+ // a member of sales department takes the task
+ taskService.takeTask(taskListSales.get(0).getId(), "johndoe");
+
+ taskListSales = taskService.findPersonalTasks("johndoe");
+ assertEquals("Expected a single task being created", 1, tas!
kListSales.size());
+ // complete collect data from sales d!
epartmen
t
+ taskService.completeTask(taskListSales.get(0).getId());
+
+ // next a member of HR department takes the task
+ taskService.takeTask(taskListHR.get(0).getId(), "joesmoe");
+
+ taskListHR = taskService.findPersonalTasks("joesmoe");
+ assertEquals("Expected a single task being created", 1, taskListHR.size());
+ // complete collect data from HR department
+ taskService.completeTask(taskListHR.get(0).getId());
+
+ // finally a member of Finance department takes the task
+ taskService.takeTask(taskListFinance.get(0).getId(), "janedoe");
+
+ taskListFinance = taskService.findPersonalTasks("janedoe");
+ assertEquals("Expected a single task being created", 1, taskListFinance.size());
+ // complete collect data from HR department
+ taskService.completeTask(taskListFinance.get(0).getId());
+
+ Date endTime = historyService.createHistoryProcessInstanceQuery().processInstanceId(processInstance.getId()).uniqueResult().getEndTime();
+
+ !
assertNotNull(endTime);
+ }
+
+ public void testForEachCompleteAfterTwoJoined() {
+
+ HashMap<String, Object> variables = new HashMap<String, Object>();
+ variables.put("listOfDepartments", new String[] { "sales-dept", "hr-dept", "finance-dept" });
+ variables.put("joinAt", 2);
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachFork", variables);
+
+ // there should be 3 forked executions - same as number of departments
+ assertEquals(3, processInstance.getExecutions().size());
+
+ List<Task> taskListSales = taskService.findGroupTasks("johndoe");
+ assertEquals("Expected a single task in johndoe's task list", 1, taskListSales.size());
+
+ List<Task> taskListHR = taskService.findGroupTasks("joesmoe");
+ assertEquals("Expected a single task in joesmoe's task list", 1, taskListHR.size());
+
+ List<Task> taskListFinance = taskService.findGroupTasks("janedoe");
+ assertEquals("Expected a single task in j!
anedoe's task list", 1, taskListFinance.size());
+
+ // a m!
ember of
sales department takes the task
+ taskService.takeTask(taskListSales.get(0).getId(), "johndoe");
+
+ taskListSales = taskService.findPersonalTasks("johndoe");
+ assertEquals("Expected a single task being created", 1, taskListSales.size());
+ // complete collect data from sales department
+ taskService.completeTask(taskListSales.get(0).getId());
+
+ // next a member of HR department takes the task
+ taskService.takeTask(taskListHR.get(0).getId(), "joesmoe");
+
+ taskListSales = taskService.findPersonalTasks("joesmoe");
+ assertEquals("Expected a single task being created", 1, taskListSales.size());
+ // complete collect data from HR department
+ taskService.completeTask(taskListSales.get(0).getId());
+
+ Date endTime = historyService.createHistoryProcessInstanceQuery().processInstanceId(processInstance.getId()).uniqueResult().getEndTime();
+
+ assertNotNull(endTime);
+ }
+}
Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/process.jpdl.xml (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/concurrency/foreach/process.jpdl.xml 2010-06-09 17:46:55 UTC (rev 6397)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process name="ForEachFork" xmlns="http://jbpm.org/4.3/jpdl">
+ <start g="28,61,48,48" name="start1">
+ <transition to="foreach1"/>
+ </start>
+ <foreach var="department" in="#{listOfDepartments}" g="111,60,48,48" name="foreach1">
+ <transition to="Collect data"/>
+ </foreach>
+ <task candidate-groups="#{department}" g="201,58,92,52" name="Collect data">
+ <transition to="join1"/>
+ </task>
+ <join g="343,59,48,48" multiplicity="#{joinAt}" name="join1">
+ <transition to="end1"/>
+ </join>
+ <end g="433,60,48,48" name="end1"/>
+</process>
\ No newline at end of file
Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachActivity.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -0,0 +1,151 @@
+/*
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.activity.ActivityExecution;
+import org.jbpm.pvm.internal.el.Expression;
+import org.jbpm.pvm.internal.env.Context;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.env.ExecutionContext;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.Condition;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.TransitionImpl;
+
+/**
+ * @author Maciej Swiderski
+ * @author Alejandro Guizar
+ */
+public class ForEachActivity extends JpdlActivity {
+
+ private String variable;
+ private Expression collection;
+
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ActivityExecu!
tion execution) throws Exception {
+ execute((ExecutionImpl!
) execut
ion);
+ }
+
+ public void execute(ExecutionImpl execution) {
+ // resolve collection values
+ Collection<?> collection = evaluateCollection(execution);
+ ActivityImpl activity = execution.getActivity();
+
+ // get concurrent root
+ ExecutionImpl concurrentRoot;
+ if (Execution.STATE_ACTIVE_ROOT.equals(execution.getState())) {
+ concurrentRoot = execution;
+ execution.setState(Execution.STATE_INACTIVE_CONCURRENT_ROOT);
+ execution.setActivity(null);
+ }
+ else if (Execution.STATE_ACTIVE_CONCURRENT.equals(execution.getState())) {
+ concurrentRoot = execution.getParent();
+ execution.end();
+ }
+ else {
+ // TODO is any other state possible?
+ concurrentRoot = execution;
+ }
+
+ // evaluate transition condition and create concurrent executions
+ TransitionImpl transition = activity.getDefaultOutgoingTransition();
+ List<ExecutionImpl> concurrentExecutions = new ArrayList<ExecutionImpl>();
+ int in!
dex = 1;
+
+ //execution context needs to be temporarily replaced to give access to child execution variables
+ ExecutionContext originalExecutionContext = null;
+ ExecutionContext concurrentExecutionContext = null;
+ EnvironmentImpl environment = EnvironmentImpl.getCurrent();
+ if (environment!=null) {
+ originalExecutionContext = (ExecutionContext) environment.removeContext(Context.CONTEXTNAME_EXECUTION);
+ }
+
+ for (Object value : collection) {
+ ExecutionImpl concurrentExecution = concurrentRoot.createExecution(Integer
+ .toString(index++));
+ concurrentExecution.setActivity(activity);
+ concurrentExecution.setState(Execution.STATE_ACTIVE_CONCURRENT);
+ concurrentExecution.createVariable(variable, value);
+
+ // replace in the current environment execution context for expression evaluation purpose
+ concurrentExecutionContext = new ExecutionContext(concurrentExecution);
+ environment.setContext!
(concurrentExecutionContext);
+
+ Condition condition = t!
ransitio
n.getCondition();
+ if (condition == null || condition.evaluate(concurrentExecution)) {
+ concurrentExecutions.add(concurrentExecution);
+ }
+ else {
+ concurrentExecution.end();
+ }
+ }
+ // after all concurrent execution were processed reset original execution context
+ environment.setContext(originalExecutionContext);
+
+ // if no concurrent executions should be launched
+ if (concurrentExecutions.isEmpty()) {
+ // throw exceptions to be consistent with decision activity
+ throw new JbpmException("no outgoing transition condition evaluated to true for " + activity);
+ }
+ else {
+ for (ExecutionImpl concurrentExecution : concurrentExecutions) {
+ concurrentExecution.take(transition);
+ if (concurrentRoot.isEnded()) break;
+ }
+ }
+ }
+
+ private Collection<?> evaluateCollection(ExecutionImpl execution) {
+ Object value = collection.evaluate(execution);
+ if (value instanceo!
f Collection<?>) {
+ // return collection verbatim
+ return (Collection<?>) value;
+ }
+ else if (value instanceof Object[]) {
+ // wrap array in list
+ return Arrays.asList((Object[]) value);
+ }
+ else if (value instanceof String) {
+ // split string around commas or spaces
+ String csv = (String) value;
+ return Arrays.asList(csv.split("[,\\s]+"));
+ }
+ throw new JbpmException("not a collection: " + value);
+ }
+
+ public void setVariable(String variable) {
+ this.variable = variable;
+ }
+
+ public void setCollection(Expression collection) {
+ this.collection = collection;
+ }
+
+}
Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForEachBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -0,0 +1,108 @@
+/*
+ * 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 org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.el.Expression;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.ExpressionCondition;
+import org.jbpm.pvm.internal.model.TransitionImpl;
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.usercode.UserCodeCondition;
+import org.jbpm.pvm.internal.wire.usercode.UserCodeReference;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.w3c.dom.Element;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class ForEachBinding extends JpdlBinding {
+
+ private static final String VARIABLE = "var";
+ private static final String COLLECTION = "in";
+
+ public ForEachBinding() {
+ super("foreach");
+ }
+
+ @Override
+ public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
+ ForEachActivity activity = new !
ForEachActivity();
+
+ if (element.hasAttribute(VARIABLE)) !
{
+
activity.setVariable(element.getAttribute(VARIABLE));
+ }
+ else {
+ parse.addProblem(VARIABLE + " attribute missing", element);
+ }
+
+ if (element.hasAttribute(COLLECTION)) {
+ Expression collection = Expression
+ .create(element.getAttribute(COLLECTION), Expression.LANGUAGE_UEL_VALUE);
+ activity.setCollection(collection);
+ }
+ else {
+ parse.addProblem(COLLECTION + " attribute missing", element);
+ }
+
+ // process transition elements
+ List<Element> transitionElements = XmlUtil.elements(element, "transition");
+
+ if (transitionElements.size() != 1) {
+ parse.addProblem("foreach activity can/must have one outgoing transition, found "+ transitionElements.size() + " transitions ", element);
+ } else {
+
+ ActivityImpl activityFromStack = parse.contextStackFind(ActivityImpl.class);
+ TransitionImpl transition = activityFromStack.getDefaultOutgoingTransition();
+
+ // get first tr!
ansition
+ Element transitionElement = transitionElements.get(0);
+
+ Element conditionElement = XmlUtil.element(transitionElement, "condition");
+ if (conditionElement != null) {
+
+ if (conditionElement.hasAttribute("expr")) {
+ ExpressionCondition expressionCondition = new ExpressionCondition();
+ expressionCondition.setExpression(conditionElement.getAttribute("expr"));
+ expressionCondition.setLanguage(XmlUtil.attribute(conditionElement, "lang"));
+ transition.setCondition(expressionCondition);
+
+ } else {
+ Element conditionHandlerElement = XmlUtil.element(conditionElement, "handler");
+ if (conditionHandlerElement != null) {
+ UserCodeCondition userCodeCondition = new UserCodeCondition();
+
+ UserCodeReference conditionReference = parser.parseUserCodeReference(conditionHandlerElement, parse);
+ userCodeCondition.setConditionReference(conditionRe!
ference);
+
+ transition.setCondition(userCodeCon!
dition);
+ }
+ }
+ }
+ }
+
+ return activity;
+ }
+
+}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java 2010-06-09 17:35:57 UTC (rev 6396)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkActivity.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.jbpm.api.Execution;
import org.jbpm.api.activity.ActivityExecution;
@@ -51,9 +52,8 @@
// evaluate the conditions and find the transitions that should be forked
List<Transition> forkingTransitions = new ArrayList<Transition>();
- List<TransitionImpl> outgoingTransitions = (List) activity.getOutgoingTransitions();
- for (TransitionImpl transition: outgoingTransitions) {
- Condition condition = transition.getCondition();
+ for (Transition transition: activity.getOutgoingTransitions()) {
+ Condition condition = ((TransitionImpl) transition).getCondition();
if ( (condition==null)
|| (condition.evaluate(execution))
) {
@@ -72,7 +72,7 @@
// if there are more transitions
} else {
- ExecutionImpl concurrentRoot = null;
+ ExecutionImpl concurrentRoot;
if (Execution.STATE_ACTIVE_ROOT.equals(execution.getState())) {
concurrentRoot = execution;
execution.setState(Execution.STATE_INACTIVE_CONCURRENT_ROOT);
@@ -80,20 +80,22 @@
} else if (Execution.STATE_ACTIVE_CONCURRENT.equals(execution.getState())) {
concurrentRoot = execution.getParent();
execution.end();
+ } else {
+ // TODO is any other state possible?
+ concurrentRoot = execution;
}
- Map<Transition, ExecutionImpl> childExecutionsMap = new HashMap<Transition, ExecutionImpl>();
+ Map<Transition, ExecutionImpl> concurrentExecutions = new HashMap<Transition, ExecutionImpl>();
for (Transition transition : forkingTransitions) {
- // launch a concurrent path of execution
- String childExecutionName = transition.getName();
- ExecutionImpl concurrentExecution = concurrentRoot.createExecution(childExecutionName);
+ ExecutionImpl concurrentExecution = concurrentRoot.createExecution(transition.getName());
concurrentExecution.setActivity(activity);
concurrentExecution.setState(Execution.STATE_ACTIVE_CONCURRENT);
- childExecutionsMap.put(transition, concurrentExecution);
+ concurrentExecutions.put(transition, concurrentExecution);
}
+
- for (Transition transition : childExecutionsMap.keySet()) {
- childExecutionsMap.get(transition).take(transition);
+ for (Entry<Transition, ExecutionImpl> entry : concurrentExecutions.entrySet()) {
+ entry.getValue().take(entry.getKey());
if (concurrentRoot.isEnded()) {
break;
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java 2010-06-09 17:35:57 UTC (rev 6396)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinActivity.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -22,6 +22,7 @@
package org.jbpm.jpdl.internal.activity;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.hibernate.LockMode;
@@ -33,9 +34,9 @@
import org.jbpm.api.model.Transition;
import org.jbpm.pvm.internal.el.Expression;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.model.ActivityImpl;
import org.jbpm.pvm.internal.model.ExecutionImpl;
-
/**
* @author Tom Baeyens
*/
@@ -43,26 +44,16 @@
private static final long serialVersionUID = 1L;
- int multiplicity = -1;
- LockMode lockMode = LockMode.UPGRADE;
- Expression multiplicityExpression;
+ private LockMode lockMode = LockMode.UPGRADE;
+ private Expression multiplicity;
public void execute(ActivityExecution execution) {
execute((ExecutionImpl)execution);
}
public void execute(ExecutionImpl execution) {
- Activity activity = execution.getActivity();
+ ActivityImpl activity = execution.getActivity();
- // evaluate multiplicity expression
- if (multiplicityExpression != null) {
- try {
- multiplicity = Integer.valueOf(multiplicityExpression.evaluate(execution).toString());
- } catch (Exception e) {
- throw new JbpmException("Problem while evaluating multiplicity attribute: " + e.getMessage());
- }
- }
-
// if this is a single, non concurrent root
if (Execution.STATE_ACTIVE_ROOT.equals(execution.getState())) {
// just pass through
@@ -84,23 +75,22 @@
ExecutionImpl concurrentRoot = execution.getParent();
List<ExecutionImpl> joinedExecutions = getJoinedExecutions(concurrentRoot, activity);
- if (isComplete(joinedExecutions, activity)) {
- endJoinedExecutions(joinedExecutions);
-
- if (multiplicity != -1) {
- // remove forked but not joined executions only when multiplicity attribute was used
- List<ExecutionImpl> forkedExecutionsToRemove = new ArrayList<ExecutionImpl>();
+ if (isComplete(execution, joinedExecutions)) {
+ endExecutions(joinedExecutions);
+ // if multiplicity was used
+ if (multiplicity != null) {
+ // collect concurrent executions still active
+ List<ExecutionImpl> danglingExecutions = new ArrayList<ExecutionImpl>();
for (ExecutionImpl concurrentExecution : concurrentRoot.getExecutions()) {
- //collect all executions from the parent that are forked
- if ( (Execution.STATE_ACTIVE_CONCURRENT.equals(concurrentExecution.getState()))) {
- forkedExecutionsToRemove.add(concurrentExecution);
+ if (Execution.STATE_ACTIVE_CONCURRENT.equals(concurrentExecution.getState())) {
+ danglingExecutions.add(concurrentExecution);
}
}
- // end all of found forked (but not joined) executions
- endJoinedExecutions(forkedExecutionsToRemove);
+ // end dangling executions
+ endExecutions(danglingExecutions);
}
ExecutionImpl outgoingExecution = null;
- if (concurrentRoot.getExecutions().size()==0) {
+ if (concurrentRoot.getExecutions().isEmpty()) {
outgoingExecution = concurrentRoot;
outgoingExecution.setState(Execution.STATE_ACTIVE_ROOT);
} else {
@@ -120,19 +110,22 @@
throw new JbpmException("invalid execution state");
}
}
-
- protected boolean isComplete(List<ExecutionImpl> joinedExecutions, Activity activity) {
- int nbrOfExecutionsToJoin = multiplicity;
- if (multiplicity==-1) {
- nbrOfExecutionsToJoin = activity.getIncomingTransitions().size();
+
+ protected boolean isComplete(ExecutionImpl execution, List<ExecutionImpl> joinedExecutions) {
+ int executionsToJoin;
+ if (multiplicity != null) {
+ executionsToJoin = evaluateMultiplicity(execution);
}
- return joinedExecutions.size()==nbrOfExecutionsToJoin;
+ else {
+ executionsToJoin = execution.getActivity().getIncomingTransitions().size();
+ }
+ return joinedExecutions.size() == executionsToJoin;
}
protected List<ExecutionImpl> getJoinedExecutions(ExecutionImpl concurrentRoot, Activity activity) {
List<ExecutionImpl> joinedExecutions = new ArrayList<ExecutionImpl>();
- List concurrentExecutions = (List)concurrentRoot.getExecutions();
- for (ExecutionImpl concurrentExecution: (List<ExecutionImpl>)concurrentExecutions) {
+ Collection<ExecutionImpl> concurrentExecutions = concurrentRoot.getExecutions();
+ for (ExecutionImpl concurrentExecution: concurrentExecutions) {
if ( (Execution.STATE_INACTIVE_JOIN.equals(concurrentExecution.getState()))
&& (concurrentExecution.getActivity()==activity)
) {
@@ -142,16 +135,30 @@
return joinedExecutions;
}
- protected void endJoinedExecutions(List<ExecutionImpl> joinedExecutions) {
- for (ExecutionImpl joinedExecution: joinedExecutions) {
- joinedExecution.end();
+ protected void endExecutions(List<ExecutionImpl> executions) {
+ for (ExecutionImpl execution: executions) {
+ execution.end();
}
}
+ private int evaluateMultiplicity(ExecutionImpl execution) {
+ if (multiplicity != null) {
+ Object value = multiplicity.evaluate(execution);
+ if (value instanceof Number) {
+ Number number = (Number) value;
+ return number.intValue();
+ }
+ if (value instanceof String) {
+ return Integer.parseInt((String) value);
+ }
+ }
+ return -1;
+ }
+
public void setLockMode(LockMode lockMode) {
this.lockMode = lockMode;
}
- public void setMultiplicityExpression(Expression multiplicityExpression) {
- this.multiplicityExpression = multiplicityExpression;
+ public void setMultiplicity(Expression multiplicity) {
+ this.multiplicity = multiplicity;
}
}
Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java 2010-06-09 17:35:57 UTC (rev 6396)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/JoinBinding.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -45,16 +45,16 @@
JoinActivity joinActivity = new JoinActivity();
if (element.hasAttribute(MULTIPLICITY)) {
- String multiplicictyText = element.getAttribute(MULTIPLICITY);
- Expression expression = Expression.create(multiplicictyText, Expression.LANGUAGE_UEL_VALUE);
- joinActivity.setMultiplicityExpression(expression);
+ String multiplicityText = element.getAttribute(MULTIPLICITY);
+ Expression expression = Expression.create(multiplicityText, Expression.LANGUAGE_UEL_VALUE);
+ joinActivity.setMultiplicity(expression);
}
if (element.hasAttribute(LOCKMODE)) {
String lockModeText = element.getAttribute(LOCKMODE);
LockMode lockMode = LockMode.parse(lockModeText.toUpperCase());
if (lockMode==null) {
- parse.addProblem(LOCKMODE + " " + lockModeText + " is not a valid lock mode", element);
+ parse.addProblem(lockModeText + " is not a valid lock mode", element);
} else {
joinActivity.setLockMode(lockMode);
}
Modified: jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.bindings.xml
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.bindings.xml 2010-06-09 17:35:57 UTC (rev 6396)
+++ jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.bindings.xml 2010-06-09 17:46:55 UTC (rev 6397)
@@ -6,6 +6,7 @@
<activity binding="org.jbpm.jpdl.internal.activity.EndBinding" />
<activity binding="org.jbpm.jpdl.internal.activity.EndCancelBinding" />
<activity binding="org.jbpm.jpdl.internal.activity.EndErrorBinding" />
+ <activity binding="org.jbpm.jpdl.internal.activity.ForEachBinding" />
<activity binding="org.jbpm.jpdl.internal.activity.ForkBinding" />
<activity binding="org.jbpm.jpdl.internal.activity.JoinBinding" />
<activity binding="org.jbpm.jpdl.internal.activity.HqlBinding" />
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java 2010-06-09 17:35:57 UTC (rev 6396)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -109,14 +109,15 @@
public abstract Object evaluateInScope(ScopeInstanceImpl scopeInstance);
protected ELContext getElContext(ScopeInstanceImpl scopeInstance) {
- ELContext elContext = (ELContext) (scopeInstance!=null ? scopeInstance.getElContext() : null);
- if (elContext==null) {
- JbpmElFactory contextFactory = JbpmElFactory.getJbpmElFactory();
- elContext = contextFactory.createElContext(scopeInstance);
- if (scopeInstance!=null) {
- scopeInstance.setElContext(elContext);
- }
+ if (scopeInstance == null) {
+ return JbpmElFactory.getJbpmElFactory().createElContext();
}
+
+ ELContext elContext = (ELContext) scopeInstance.getElContext();
+ if (elContext == null) {
+ elContext = JbpmElFactory.getJbpmElFactory().createElContext(scopeInstance);
+ scopeInstance.setElContext(elContext);
+ }
return elContext;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java 2010-06-09 17:35:57 UTC (rev 6396)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -38,7 +38,7 @@
}
public Method resolveFunction(String prefix, String localName) {
- for (Method method: functionClass.getDeclaredMethods()) {
+ for (Method method: functionClass.getMethods()) {
if (method.getName().equals(localName)) {
return method;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-06-09 17:35:57 UTC (rev 6396)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -248,7 +248,7 @@
}
if (hasVariables) {
for (Map.Entry<String, Variable> entry: variables.entrySet()) {
- String name = (String) entry.getKey();
+ String name = entry.getKey();
Variable variable = entry.getValue();
Object value = variable.getValue(this);
values.put(name, value);
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/foreach/ForEachTest.java 2010-06-09 17:46:55 UTC (rev 6397)
@@ -0,0 +1,415 @@
+/*
+ * 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.activity.foreach;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Map;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Maciej Swiderski
+ */
+public class ForEachTest extends JbpmTestCase {
+
+ public void testForEachLiteral() {
+ deployJpdlXmlString(""
+ + "<process name='ForEachLiteral' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' var='assign' in='alex, mike'>"
+ + " <transition name='left' to='task1' g='-44,-18'/>"
+ + " </foreach>"
+!
+ " <task name='task1' g='90,177,73,44' assignee='#{as!
sign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44' multiplicity='2'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachLiteral");
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertEquals("task1", taskAlex.getActivityName());
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike = taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertEquals("task1", taskMike.getActivityName());
+ taskService.completeTask(taskMike.getId());
+
+ processInstance = executionService.f!
indProcessInstanceById(processInstance.getId());
+ assertEquals(2, processInstance.getExecutions().size());
+
+ for (Execution exec : processInstance.getExecutions()) {
+ assertEquals(Execution.STATE_ACTIVE_CONCURRENT, exec.getState());
+ executionService.signalExecutionById(exec.getId());
+ }
+
+ HistoryProcessInstance history = historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+ public void testForEachList() {
+ deployJpdlXmlString(""
+ + "<process name='ForEachList' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' var='assign' in='#{actors}'>"
+ !
+ " <transition name='left' to='task1' g='-44,-18'/>"!
+
+ " </foreach>"
+ + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44' multiplicity='#{actors.size()}'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ Map<String, ?> variables = Collections.singletonMap("actors", Arrays.asList("alex", "mike"));
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachList", variables);
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertEquals("task1", taskAlex.getActivityName());
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike = !
taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertEquals("task1", taskMike.getActivityName());
+ taskService.completeTask(taskMike.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+ assertEquals(2, processInstance.getExecutions().size());
+
+ for (Execution exec : processInstance.getExecutions()) {
+ assertEquals(Execution.STATE_ACTIVE_CONCURRENT, exec.getState());
+ executionService.signalExecutionById(exec.getId());
+ }
+
+ HistoryProcessInstance history = historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+ public void testForEachArray() {
+ deployJpdlXmlString(""
+ + "<process name='ForEachArray' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,!
17,32,29' name='start1'>"
+ + " <transition g='-43,-!
18' name
='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' var='assign' in='#{actors}'>"
+ + " <transition name='left' to='task1' g='-44,-18'/>"
+ + " </foreach>"
+ + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44' multiplicity='#{length(actors)}'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ Map<String, ?> variables = Collections.singletonMap("actors", new String[] { "alex", "mike" });
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachArray", variables);!
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertEquals("task1", taskAlex.getActivityName());
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike = taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertEquals("task1", taskMike.getActivityName());
+ taskService.completeTask(taskMike.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+ assertEquals(2, processInstance.getExecutions().size());
+
+ for (Execution exec : processInstance.getExecutions()) {
+ assertEquals(Execution.STATE_ACTIVE_CONCURRENT, exec.getState());
+ executionService.signalExecutionById(exec.getId());
+ }
+
+ HistoryProcessInstance history = historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEqu!
als("end1", history.getEndActivityName());
+ }
+
+ public vo!
id testF
orEachInvalid() {
+ deployJpdlXmlString(""
+ + "<process name='ForEachInvalid' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' var='assign' in='#{actors}'>"
+ + " <transition name='left' to='task1' g='-44,-18'/>"
+ + " </foreach>"
+ + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ Map<String, ?> vari!
ables = Collections.singletonMap("actors", new Date());
+ try {
+ executionService.startProcessInstanceByKey("ForEachInvalid", variables);
+ fail("It should fail, since for-each list of items is a Date object");
+ }
+ catch (JbpmException e) {
+ // expected result
+ }
+ }
+
+ public void testForEachMissingVar() {
+ try {
+ deployJpdlXmlString(""
+ + "<process name='ForEachMissingVar' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' in='#{actors}' >"
+ + " <transition name='left' to='task1' g='-44,-18'/>"
+ + " </foreach>"
+ + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state !
name='Big car' > "
+ + " <transition name='to join2' !
to='join
2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ fail("expected foreach with missing variable to fail");
+ }
+ catch (JbpmException e) {
+ // expected result
+ }
+ }
+
+ public void testForEachJoinMultiplicity() {
+ deployJpdlXmlString(""
+ + "<process name='ForEachJoinMultiplicity' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' var='assign' in='#{actors}'>"
+ + " <transition name='left' to='task1' g='-44,-18'/>"
+ + " </foreach>"
+ + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ + " !
<transition name='to state' to='join2' g='-43,-18'/>"
+ + " </task>"
+ + " <join name='join2' g='192,511,57,44' multiplicity='#{actors.size() - 1}'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ Map<String, ?> variables = Collections.singletonMap("actors", Arrays.asList("alex", "mike"));
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachJoinMultiplicity", variables);
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertEquals("task1", taskAlex.getActivityName());
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike = taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertNull(taskMike);
+
+ HistoryProcessInstance history = historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance!
.getId())
+ .uniqueResult();
+ assertEquals(ProcessIns!
tance.ST
ATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+ public void testForEachLiteralWithTransitionExpr() {
+ deployJpdlXmlString(""
+ + "<process name='ForEachCondition' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' var='assign' in='alex, mike, peter'>"
+ + " <transition name='left' to='task1' g='-44,-18'>"
+ + " <condition expr='#{assign=="alex" or assign=="mike"}' /> "
+ + " </transition>"
+ + " </foreach>"
+ + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='!
-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44' multiplicity='2'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("ForEachCondition");
+
+ Task taskAlex = taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertEquals("task1", taskAlex.getActivityName());
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike = taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertEquals("task1", taskMike.getActivityName());
+ taskService.completeTask(taskMike.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+ assertEquals(2, processInstance.getExecutions().size());
+
+ for (Execution exec : processInstance.getExecutions()) {
+ assert!
Equals(Execution.STATE_ACTIVE_CONCURRENT, exec.getState());
+ !
exe
cutionService.signalExecutionById(exec.getId());
+ }
+
+ HistoryProcessInstance history = historyService.createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+ public void testForEachTooManyTransitions() {
+ try {
+ deployJpdlXmlString(""
+ + "<process name='ForEachTooManyTransitions' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' in='#{actors}' var='assign'>"
+ + " <transition name='left' to='task1' g='-44,-18'/>"
+ + " <transition name='right' to='task1' g='-44,-18'/>"
+ + " </foreach>"
+ + " <task name='task1' g='90,177,7!
3,44' assignee='#{assign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ fail("expected foreach with too many transitions");
+ }
+ catch (JbpmException e) {
+ // expected result
+ }
+ }
+
+ public void testForEachNoTransitions() {
+ try {
+ deployJpdlXmlString(""
+ + "<process name='ForEachNoTransition' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,!
95,49,50' name='foreach1' in='#{actors}' var='assign' >"
+ !
+ "
</foreach>"
+ + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ fail("expected foreach with too many transitions");
+ }
+ catch (JbpmException e) {
+ // expected result
+ }
+ }
+
+ public void testForEachConditionTransitionsEvaluatedToFalse() {
+ try {
+ deployJpdlXmlString(""
+ + "<process name='ForEachConditionFalse' xmlns='http://jbpm.org/jpdl/4.4'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to !
foreach1' to='foreach1'/>"
+ + " </start>"
+ + " <foreach g='185,95,49,50' name='foreach1' in='#{actors}' var='assign' >"
+ + " <transition name='left' to='task1' g='-44,-18'>"
+ + " <condition expr='#{assign=="peter"}' /> "
+ + " </transition>"
+ + " </foreach>"
+ + " <task name='task1' g='90,177,73,44' assignee='#{assign}'>"
+ + " <transition name='to state' to='Big car' g='-43,-18'/>"
+ + " </task>"
+ + " <state name='Big car' > "
+ + " <transition name='to join2' to='join2' g='-43,-18'/>"
+ + " </state> "
+ + " <join name='join2' g='192,511,57,44'>"
+ + " <transition name='to end1' to='end1' g='-42,-18'/>"
+ + " </join>"
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>");
+
+ Map<String, ?> variables = Collections.singletonMap("actors", Arrays.asList("alex", "mike"));
+ !
ProcessInstance processInstance = executionService.startProces!
sInstanc
eByKey("ForEachConditionFalse", variables);
+
+ fail("expected foreach all conditions evaluated to false");
+ }
+ catch (JbpmException e) {
+ // expected result
+ }
+ }
+}
13 years, 11 months
JBoss JBPM SVN: r6396 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/xml and 7 other directories.
by do-not-reply@jboss.org
Author: swiderski.maciej
Date: 2010-06-09 13:35:57 -0400 (Wed, 09 Jun 2010)
New Revision: 6396
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/CreateExecutionVariablesCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariableNamesCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariablesCmd.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
Log:
JBPM-2506: variable declaration and variable history support
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -109,6 +109,12 @@
/** creates or overwrites the variable values on the referenced execution */
void setVariables(String executionId, Map<String, ?> variables);
+
+ /** creates or overwrites a variable value on the referenced execution and marks the variable to be stored in history*/
+ void setVariable(String executionId, String name, Object value, boolean historyEnabled);
+
+ /** creates or overwrites the variable values on the referenced execution and marks the variables to be stored in history*/
+ void setVariables(String executionId, Map<String, ?> variables, boolean historyEnabled);
/** retrieves a variable */
Object getVariable(String executionId, String variableName);
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -22,6 +22,7 @@
package org.jbpm.api;
import java.util.Map;
+import java.util.Set;
import org.jbpm.api.history.HistoryActivityInstanceQuery;
import org.jbpm.api.history.HistoryDetailQuery;
@@ -33,6 +34,7 @@
* process instances.
*
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public interface HistoryService {
@@ -53,4 +55,13 @@
/** returns for each transitionName, the number of times that transition was taken */
Map<String, Integer> choiceDistribution(String processDefinitionId, String activityName);
+
+ /** retrieves a variable */
+ Set<String> getVariableNames(String processInstanceId);
+
+ /** retrieves a map of variables */
+ Object getVariable(String processInstanceId, String variableName);
+
+ /** all the variables visible in the given history execution scope */
+ Map<String, Object> getVariables(String processInstanceId, Set<String> variableNames);
}
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 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -592,6 +592,11 @@
String type = XmlUtil.attribute(variableElement, "type", true, parse);
variableDefinition.setTypeName(type);
+ Boolean isHistoryEnabled = XmlUtil.attributeBoolean(variableElement, "history", false, parse);
+ if (isHistoryEnabled != null) {
+ variableDefinition.setHistoryEnabled(isHistoryEnabled);
+ }
+
int sources = 0;
String initExpr = XmlUtil.attribute(variableElement, "init-expr");
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/CreateExecutionVariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/CreateExecutionVariablesCmd.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/CreateExecutionVariablesCmd.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -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.pvm.internal.cmd;
+
+import java.util.Map.Entry;
+
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class CreateExecutionVariablesCmd extends VariablesCmd<Void> {
+
+ protected String executionId;
+ protected boolean historyEnabled;
+
+ private static final long serialVersionUID = 1L;
+
+ public CreateExecutionVariablesCmd(String executionId, boolean historyEnabled) {
+ this.executionId = executionId;
+ this.historyEnabled = historyEnabled;
+ }
+
+ public Void execute(Environment environment) throws Exception {
+ ExecutionImpl execution = (ExecutionImpl) getExecution(environment, executionId);
+ for (Entry<String, ?> entry : variables.entrySet()) {
+ execution.createVariable(entry.getKey(), entry.getValue(), null, historyEnabled);
+ }
+ return null;
+ }
+
+}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariableNamesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariableNamesCmd.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariableNamesCmd.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -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.pvm.internal.cmd;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.pvm.internal.history.model.HistoryVariableImpl;
+
+/**
+ * Command responsible for retrieving variable names stored as history records for given process instance id
+ *
+ *
+ * @author Maciej Swiderski
+ *
+ */
+public class GetHistoryVariableNamesCmd implements Command<Set<String>> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ private String processInstanceId;
+
+ public GetHistoryVariableNamesCmd(String processInstanceId) {
+ this.processInstanceId = processInstanceId;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set<String> execute(Environment environment) throws Exception {
+ Session dbsession = environment.get(Session.class);
+
+!
String hql = "select hv.variableName from " + HistoryVaria!
bleImpl.
class.getName() + " hv where hv.processInstanceId = '" + processInstanceId + "'";
+
+ Query query = dbsession.createQuery(hql);
+
+ Set<String> historyVariables = new HashSet<String>(query.list());
+
+ return historyVariables;
+ }
+
+}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariablesCmd.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariablesCmd.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -0,0 +1,75 @@
+/*
+ * 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.pvm.internal.cmd;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
+import org.jbpm.pvm.internal.history.model.HistoryVariableImpl;
+import org.jbpm.pvm.internal.query.HistoryProcessInstanceQueryImpl;
+
+/**
+ *
+ * @author Maciej Swiderski
+ *
+ */
+public class GetHistoryVariablesCmd extends AbstractCommand<Map<String, Object>> {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String processInstanceId;
+ protected Set<String> variableNames;
+
+
+ public GetHistoryVariablesCmd(String processInstanceId, Set<String> variableNames) {
+ super();
+ this.processInstanceId = processInstanceId;
+ this.variableNames = variableNames;
+ }
+
+
+ public Map<String, !
Object> execute(Environment environment) throws Exception {
+ !
Histo
ryProcessInstanceQueryImpl queryImpl = new HistoryProcessInstanceQueryImpl();
+
+ HistoryProcessInstance historyProcessInstance = queryImpl.processInstanceId(processInstanceId).uniqueResult();
+
+ Iterator<HistoryVariableImpl> variables = ((HistoryProcessInstanceImpl) historyProcessInstance).getHistoryVariables().iterator();
+
+ Map<String, Object> variableMap = new HashMap<String, Object>();
+
+ while (variables.hasNext()) {
+ HistoryVariableImpl historyVariableImpl = (HistoryVariableImpl) variables.next();
+
+ if (variableNames.contains(historyVariableImpl.getVariableName())) {
+ variableMap.put(historyVariableImpl.getVariableName(), historyVariableImpl.getValue());
+ }
+ }
+
+ return variableMap;
+ }
+
+}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -24,10 +24,12 @@
import org.jbpm.api.JbpmException;
import org.jbpm.api.cmd.Environment;
import org.jbpm.pvm.internal.client.ClientExecution;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class SetExecutionVariablesCmd extends VariablesCmd<Void> {
@@ -44,7 +46,11 @@
public Void execute(Environment environment) throws Exception {
ClientExecution execution = getExecution(environment, executionId);
- execution.setVariables(variables);
+ if (isHistoryEnabled()) {
+ ((ExecutionImpl) execution).setVariables(variables, historyEnabled);
+ } else {
+ execution.setVariables(variables);
+ }
return null;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -38,7 +38,9 @@
protected Map<String, ?> variables;
private Map<String, Object> internalMap;
+ protected boolean historyEnabled;
+
public void addVariable(String key, Object variable) {
if (internalMap == null) {
if (variables != null) {
@@ -57,6 +59,14 @@
this.variables = variables;
}
+ public boolean isHistoryEnabled() {
+ return historyEnabled;
+ }
+
+ public void setHistoryEnabled(boolean historyEnabled) {
+ this.historyEnabled = historyEnabled;
+ }
+
protected ClientExecution getExecution(Environment environment, String executionId) {
DbSession dbSession = environment.get(DbSession.class);
ClientExecution execution = dbSession.findExecutionById(executionId);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -126,4 +126,7 @@
public void setEndActivityName(String endActivityName) {
this.endActivityName = endActivityName;
}
+ public Set<HistoryVariableImpl> getHistoryVariables() {
+ return historyVariables;
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -99,7 +99,7 @@
}
protected Variable createVariableObject(String key, Object value, String typeName, boolean isHistoryEnabled) {
- log.debug("create variable '"+key+"' in '"+this+"' with value '"+value+"'");
+ log.debug("create variable '"+key+"' in '"+this+"' with value '"+value+"' history enabled " + isHistoryEnabled);
Type type = null;
@@ -142,9 +142,9 @@
variable.setExecution(getExecution());
variable.setTask(getTask());
variable.setHistoryEnabled(isHistoryEnabled);
-
variable.setValue(value, this);
+
long dbid = DbidGenerator.getDbidGenerator().getNextId();
variable.setDbid(dbid);
@@ -155,8 +155,12 @@
return variable;
}
+
+ public void setVariable(String key, Object value) {
+ setVariable(key, value, false);
+ }
- public void setVariable(String key, Object value) {
+ public void setVariable(String key, Object value, boolean historyEnabled) {
if (key==null) {
throw new JbpmException("variableName is null");
}
@@ -177,17 +181,20 @@
variable.setValue(value, this);
} else if (getParentVariableScope()==null) {
- createVariable(key, value, null, false);
+ createVariable(key, value, null, historyEnabled);
} else {
- getParentVariableScope().setVariable(key,value);
+ getParentVariableScope().setVariable(key,value, historyEnabled);
}
}
+ public void setVariables(Map<String, ?> variables) {
+ setVariables(variables, false);
+ }
- public void setVariables(Map<String, ?> variables) {
+ public void setVariables(Map<String, ?> variables, boolean historyEnabled) {
if (variables!=null) {
for (Map.Entry<String, ?> entry : variables.entrySet()) {
- setVariable(entry.getKey(), entry.getValue());
+ setVariable(entry.getKey(), entry.getValue(), historyEnabled);
}
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -29,6 +29,7 @@
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.ProcessInstanceQuery;
+import org.jbpm.pvm.internal.cmd.CreateExecutionVariablesCmd;
import org.jbpm.pvm.internal.cmd.CreateProcessInstanceQueryCmd;
import org.jbpm.pvm.internal.cmd.DeleteProcessInstance;
import org.jbpm.pvm.internal.cmd.EndProcessInstance;
@@ -150,4 +151,18 @@
cmd.setVariables(variables);
commandService.execute(cmd);
}
+
+ public void setVariable(String executionId, String name, Object value, boolean historyEnabled) {
+ SetExecutionVariablesCmd cmd = new SetExecutionVariablesCmd(executionId);
+ cmd.addVariable(name, value);
+ cmd.setHistoryEnabled(historyEnabled);
+ commandService.execute(cmd);
+ }
+
+ public void setVariables(String executionId, Map<String, ?> variables, boolean historyEnabled) {
+ SetExecutionVariablesCmd cmd = new SetExecutionVariablesCmd(executionId);
+ cmd.setVariables(variables);
+ cmd.setHistoryEnabled(historyEnabled);
+ commandService.execute(cmd);
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -21,12 +21,12 @@
*/
package org.jbpm.pvm.internal.svc;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.jbpm.api.HistoryService;
import org.jbpm.api.history.HistoryActivityInstanceQuery;
-import org.jbpm.api.history.HistoryComment;
import org.jbpm.api.history.HistoryDetailQuery;
import org.jbpm.api.history.HistoryProcessInstanceQuery;
import org.jbpm.api.history.HistoryTaskQuery;
@@ -34,7 +34,8 @@
import org.jbpm.pvm.internal.cmd.CreateHistoryDetailQueryCmd;
import org.jbpm.pvm.internal.cmd.CreateHistoryProcessInstanceQueryCmd;
import org.jbpm.pvm.internal.cmd.CreateHistoryTaskQueryCmd;
-import org.jbpm.pvm.internal.cmd.GetTaskCommentsCmd;
+import org.jbpm.pvm.internal.cmd.GetHistoryVariableNamesCmd;
+import org.jbpm.pvm.internal.cmd.GetHistoryVariablesCmd;
import org.jbpm.pvm.internal.query.AvgDurationPerActivityQueryCmd;
import org.jbpm.pvm.internal.query.ChoiceDistributionQueryCmd;
import org.jbpm.pvm.internal.query.HistoryActivityInstanceQueryImpl;
@@ -45,6 +46,7 @@
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class HistoryServiceImpl extends AbstractServiceImpl implements HistoryService {
@@ -79,4 +81,21 @@
query.setCommandService(commandService);
return query;
}
+
+ public Set<String> getVariableNames(String processInstanceId) {
+ return commandService.execute(new GetHistoryVariableNamesCmd(processInstanceId));
+ }
+
+ public Object getVariable(String processInstanceId, String variableName) {
+ Set<String> variableNames = new HashSet<String>();
+ variableNames.add(variableName);
+ Map<String, Object> variables = commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
+ return variables.get(variableName);
+ }
+
+ public Map<String, Object> getVariables(String processInstanceId, Set<String> variableNames) {
+
+ return commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
+
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -41,12 +41,12 @@
private static final long serialVersionUID = 1L;
protected long dbid = -1;
- protected int dbversion = 0;
+ protected int dbversion;
- protected String key = null;
- protected Converter converter = null;
- protected String textValue = null;
- protected boolean isHistoryEnabled = false;
+ protected String key;
+ protected Converter converter;
+ protected String textValue;
+ protected boolean isHistoryEnabled;
protected ExecutionImpl execution;
protected TaskImpl task;
@@ -92,7 +92,7 @@
HistorySession historySession = EnvironmentImpl.getFromCurrent(HistorySession.class, false);
if ( isHistoryEnabled
- && (historySession!=null)
+ && (historySession!=null) && (this.getDbid() != -1)
) {
HistoryEvent.fire(new VariableUpdate(this));
}
@@ -121,7 +121,7 @@
}
public ExecutionImpl getProcessInstance() {
- return (execution!=null ? execution.getProcessInstance() : null);
+ return execution!=null ? execution.getProcessInstance() : null;
}
// getters and setters //////////////////////////////////////////////////////
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2010-06-07 20:23:16 UTC (rev 6395)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -65,6 +65,8 @@
public void setValue(Object value, ScopeInstanceImpl scopeInstance) {
super.setValue(value, scopeInstance);
cachedValue = value;
+ this.textValue = value.toString();
+
}
public Lob getLob() {
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -0,0 +1,33 @@
+package org.jbpm.test.variables;
+
+import java.io.Serializable;
+
+
+public class HistoryVariable implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ private String name;
+
+
+ public String getName() {
+ return name;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public HistoryVariable() {
+ this.name = "Poul";
+ }
+
+
+ @Override
+ public String toString() {
+ return "my name is Poul";
+ }
+}
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java 2010-06-09 17:35:57 UTC (rev 6396)
@@ -0,0 +1,232 @@
+package org.jbpm.test.variables;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.test.JbpmTestCase;
+
+
+public class HistoryVariableTest extends JbpmTestCase {
+
+ public void testDeclaredVariableWithHistory() {
+ deployJpdlXmlString(
+ "<process name='var'>" +
+ " <variable name='test' type='string' init-expr='test value' history='true'/>"+
+ " <start name='a'>" +
+ " <transition to='b' />" +
+ " </start>" +
+ " <state name='b'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ String testVariableValue = (String) executionService.getVariable("var.one", "test");
+ assertNotNull(variableNames);
+ assertEquals(1, variableNames.size());
+ assertEquals("test", variableNames.iterator().next());
+ assertEquals("test value", testVariableValue);
!
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+ assertEquals("test", historyVariables.iterator().next());
+
+
+ String value = (String) historyService.getVariable("var.one", "test");
+ assertEquals("test value", value);
+
+ }
+
+ public void testSetVariableViaAPIwithHistory() {
+ deployJpdlXmlString(
+ "<process name='var'>" +
+ " <start name='a'>" +
+ " <transition to='b' />" +
+ " </start>" +
+ " <state name='b'/>" +
+ "</process>");
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ executionService.setVariable("var.one", "test2", "test3", true);
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ String testVariableValue = (String) executionService.getVariable("var.one", "test2");
+ assertNotNull(variableNames);
+ assertEquals(1,!
variableNames.size());
+ assertEquals("test2", variableNam!
es.itera
tor().next());
+ assertEquals("test3", testVariableValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+ assertEquals("test2", historyVariables.iterator().next());
+
+ String value = (String) historyService.getVariable("var.one", "test2");
+ assertEquals("test3", value);
+ }
+
+ public void testSetVariablesViaAPIwithHistory() {
+ deployJpdlXmlString(
+ "<process name='var'>" +
+ " <start name='a'>" +
+ " <transition to='b' />" +
+ " </start>" +
+ " <state name='b'/>" +
+ "</process>");
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Map<String, String> simpleVariables = new HashMap<String, String>();
+ simpleVariables.put("simple-var", "hello history");
+ simpleVariables.put("test-var", "good day");
+ simpleVariables.put("my-var", "cheers");
+
+ executionService!
.setVariables("var.one", simpleVariables, true);
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+
+ assertNotNull(variableNames);
+ assertEquals(3, variableNames.size());
+
+ String testVariableValue = (String) executionService.getVariable("var.one", "test-var");
+ assertEquals("good day", testVariableValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(3, historyVariables.size());
+
+ String value = (String) historyService.getVariable("var.one", "simple-var");
+ assertEquals("hello history", value);
+ }
+
+ public void testDeclaredVariablesWithHistory() {
+ deployJpdlXmlString(
+ "<process name='var'>" +
+ " <variable name='test' type='string' init-expr='test value' history='true'/>"+
+ " <variable name='real' type='string' init-expr='real value' history='true'/>"+
+ " <start name='a'>" +
+ " <transition to='b' />" +
+ !
" </start>" +
+ " <state name='b'/>" +
+ "</proces!
s>"
+
);
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+
+ assertNotNull(variableNames);
+ assertEquals(2, variableNames.size());
+
+ String testVariableValue = (String) executionService.getVariable("var.one", "test");
+ assertEquals("test value", testVariableValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(2, historyVariables.size());
+
+
+ String value = (String) historyService.getVariable("var.one", "real");
+ assertEquals("real value", value);
+
+ }
+
+ public void testDeclaredVariablesMixed() {
+ deployJpdlXmlString(
+ "<process name='var'>" +
+ " <variable name='test' type='string' init-expr='test value' history='true'/>"+
+ " <variable name='real' type='string' init-expr='real value' history='false'/>"+
+ " <start name='a'>" +
+ " <tran!
sition to='b' />" +
+ " </start>" +
+ " <state name='b'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+
+ assertNotNull(variableNames);
+ assertEquals(2, variableNames.size());
+
+ String testVariableValue = (String) executionService.getVariable("var.one", "test");
+ assertEquals("test value", testVariableValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+
+
+ String value = (String) historyService.getVariable("var.one", "test");
+ assertEquals("test value", value);
+
+ assertNull(historyService.getVariable("var.one", "real"));
+
+ }
+
+ public void testDeclaredELVariableWithHistory() {
+ deployJpdlXmlString(
+ "<process name='var'>" +
+ " <variable name='test' type='integer' i!
nit-expr='#{testV}' history='true'/>"+
+ " <start name='!
a'>" +
+
" <transition to='b' />" +
+ " </start>" +
+ " <state name='b'/>" +
+ "</process>"
+ );
+ HashMap<String, Integer> vars = new HashMap<String, Integer>();
+ vars.put("testV", 35);
+ executionService.startProcessInstanceByKey("var", vars, "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ Integer testVariableValue = (Integer) executionService.getVariable("var.one", "test");
+ assertNotNull(variableNames);
+ assertEquals(2, variableNames.size());
+ assertEquals("test", variableNames.iterator().next());
+ assertTrue(35 == testVariableValue);
+
+ Set<String> historyVariables = historyService.getVariableNames("var.one");
+ assertEquals(1, historyVariables.size());
+ assertEquals("test", historyVariables.iterator().next());
+
+
+ String value = (String) historyService.getVariable("var.one", "test");
+ assertEquals("35", value);
+
+ }
+
+ public void testDe!
claredSerializableVariableWithHistory() {
+ deployJpdlXmlString(
+ "<process name='var'>" +
+ " <variable name='test' type='serializable' history='true'>" +
+ " <object class='org.jbpm.test.variables.HistoryVariable' />" +
+ " </variable>"+
+ " <start name='a'>" +
+ " <transition to='b' />" +
+ " </start>" +
+ " <state name='b'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("var", "one");
+
+ Set<String> variableNames = executionService.getVariableNames("var.one");
+ HistoryVariable testVariableValue = (HistoryVariable) executionService.getVariable("var.one", "test");
+ assertNotNull(variableNames);
+ assertEquals(1, variableNames.size());
+ assertEquals("test", variableNames.iterator().next());
+ assertNotNull(testVariableValue);
+ assertEquals("Poul", testVariableValue.getName());
+
+ Set<String> historyVariables = historyService.getVariableNames("var.!
one");
+ assertEquals(1, historyVariables.size());
+ ass!
ertEqual
s("test", historyVariables.iterator().next());
+
+
+ String value = (String) historyService.getVariable("var.one", "test");
+ assertEquals("my name is Poul", value);
+
+ }
+}
+
+
13 years, 11 months