[jbpm-commits] JBoss JBPM SVN: r4931 - in jbpm4/trunk/modules: jpdl/src/main/resources and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu May 28 07:55:10 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-05-28 07:55:10 -0400 (Thu, 28 May 2009)
New Revision: 4931
Added:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomBinding.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SystemVariablesTest.java
Modified:
jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
Log:
JBPM-2231 introducing system variables
Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomActivity.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomActivity.java 2009-05-28 11:55:10 UTC (rev 4931)
@@ -0,0 +1,61 @@
+/*
+ * 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.Map;
+
+import org.jbpm.api.activity.ActivityBehaviour;
+import org.jbpm.api.activity.ActivityExecution;
+import org.jbpm.api.activity.ExternalActivityBehaviour;
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.pvm.internal.wire.Descriptor;
+import org.jbpm.pvm.internal.wire.WireContext;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class CustomActivity extends JpdlExternalActivity {
+
+ private static final long serialVersionUID = 1L;
+
+ protected Descriptor descriptor;
+
+ public void signal(ActivityExecution execution, String signalName, Map<String, ? > parameters) throws Exception {
+ ExternalActivityBehaviour activityBehaviour = (ExternalActivityBehaviour) WireContext.create(descriptor);
+ activityBehaviour.signal(execution, signalName, parameters);
+ }
+
+ public void execute(ActivityExecution execution) throws Exception {
+ ActivityBehaviour activityBehaviour = (ActivityBehaviour) WireContext.create(descriptor);
+ activityBehaviour.execute(execution);
+ }
+
+
+ public Descriptor getDescriptor() {
+ return descriptor;
+ }
+ public void setDescriptor(Descriptor descriptor) {
+ this.descriptor = descriptor;
+ }
+}
Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomActivity.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomBinding.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomBinding.java 2009-05-28 11:55:10 UTC (rev 4931)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.jpdl.internal.activity;
+
+import org.jbpm.pvm.internal.wire.binding.ObjectBinding;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class CustomBinding extends JpdlBinding {
+
+ static ObjectBinding objectBinding = new ObjectBinding();
+
+ public CustomBinding() {
+ super("custom");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ CustomActivity customActivity = new CustomActivity();
+ ObjectDescriptor descriptor = (ObjectDescriptor)
+ objectBinding.parse(element, parse, wireParser);
+ customActivity.setDescriptor(descriptor);
+ return customActivity;
+ }
+}
Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/CustomBinding.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml 2009-05-28 11:52:12 UTC (rev 4930)
+++ jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml 2009-05-28 11:55:10 UTC (rev 4931)
@@ -16,4 +16,5 @@
<activity binding="org.jbpm.jpdl.internal.activity.SubProcessBinding" />
<activity binding="org.jbpm.jpdl.internal.activity.MailBinding" />
<activity binding="org.jbpm.jpdl.internal.activity.GroupBinding" />
+ <activity binding="org.jbpm.jpdl.internal.activity.CustomBinding" />
</activities>
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2009-05-28 11:52:12 UTC (rev 4930)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2009-05-28 11:55:10 UTC (rev 4931)
@@ -67,6 +67,7 @@
import org.jbpm.pvm.internal.model.op.AtomicOperation;
import org.jbpm.pvm.internal.model.op.MoveToChildActivity;
import org.jbpm.pvm.internal.model.op.Signal;
+import org.jbpm.pvm.internal.type.Variable;
import org.jbpm.pvm.internal.util.EqualsUtil;
import org.jbpm.pvm.internal.util.Priority;
@@ -120,6 +121,8 @@
protected int priority = Priority.NORMAL;
+ protected Map<String, Variable> systemVariables;
+
// persistent indicators of the current position ////////////////////////////
/** persistent process definition reference */
@@ -803,7 +806,48 @@
return null;
}
+
+ // system variables /////////////////////////////////////////////////////////
+
+ public void createSystemVariable(String key, Object value) {
+ createSystemVariable(key, value, null);
+ }
+ public void createSystemVariable(String key, Object value, String typeName) {
+ Variable variable = createVariableObject(key, value, typeName);
+
+ if (systemVariables==null) {
+ systemVariables = new HashMap<String, Variable>();
+ }
+ systemVariables.put(variable.getKey(), variable);
+ }
+
+ public void setSystemVariable(String key, Object value) {
+ Variable variable = (systemVariables!=null ? (Variable) systemVariables.get(key) : null);
+ if (variable!=null) {
+ log.debug("setting system variable '"+key+"' in '"+this+"' to value '"+value+"'");
+ variable.setValue(value);
+ } else {
+ log.debug("creating system variable '"+key+"' in '"+this+"' to value '"+value+"'");
+ createSystemVariable(key, value, null);
+ }
+ }
+
+ public Object getSystemVariable(String key) {
+ Variable variable = (systemVariables!=null ? (Variable) systemVariables.get(key) : null);
+ if (variable!=null) {
+ return variable.getValue();
+ }
+ return null;
+ }
+
+ public boolean removeSystemVariable(String key) {
+ if (systemVariables!=null) {
+ return (systemVariables.remove(key)!=null);
+ }
+ return false;
+ }
+
// sub process creation /////////////////////////////////////////////////////
public ClientProcessInstance createSubProcessInstance(ClientProcessDefinition processDefinition) {
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 2009-05-28 11:52:12 UTC (rev 4930)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2009-05-28 11:55:10 UTC (rev 4931)
@@ -83,6 +83,18 @@
}
public void createVariable(String key, Object value, String typeName) {
+ Variable variable = createVariableObject(key, value, typeName);
+
+ if (variables==null) {
+ variables = new HashMap<String, Variable>();
+ }
+ variables.put(variable.getKey(), variable);
+ hasVariables = true;
+
+ // TODO add create-variable-log
+ }
+
+ protected Variable createVariableObject(String key, Object value, String typeName) {
log.debug("create variable '"+key+"' in '"+this+"' with value '"+value+"'");
Type type = null;
@@ -125,14 +137,8 @@
variable.setKey(key);
variable.setValue(value);
variable.setProcessInstance(getProcessInstance());
-
- if (variables==null) {
- variables = new HashMap<String, Variable>();
- }
- variables.put(variable.getKey(), variable);
- hasVariables = true;
- // TODO add create-variable-log
+ return variable;
}
public void setVariable(String key, Object value) {
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2009-05-28 11:52:12 UTC (rev 4930)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2009-05-28 11:55:10 UTC (rev 4931)
@@ -40,7 +40,16 @@
<map-key type="string" column="KEY_" />
<one-to-many class="org.jbpm.pvm.internal.type.Variable" />
</map>
+ <map name="systemVariables"
+ cascade="all-delete-orphan">
+ <key foreign-key="FK_VAR_EXESYS">
+ <column name="EXESYS_" index="IDX_VAR_EXESYS"/>
+ </key>
+ <map-key type="string" column="KEY_" />
+ <one-to-many class="org.jbpm.pvm.internal.type.Variable" />
+ </map>
+
<property name="name" column="NAME_" />
<property name="key" column="KEY_" />
<property name="id" column="ID_" unique="true" />
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SystemVariablesTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SystemVariablesTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SystemVariablesTest.java 2009-05-28 11:55:10 UTC (rev 4931)
@@ -0,0 +1,77 @@
+/*
+ * 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.execution;
+
+import java.util.Map;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.activity.ActivityExecution;
+import org.jbpm.api.activity.ExternalActivityBehaviour;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class SystemVariablesTest extends JbpmTestCase {
+
+ public static class Systematic implements ExternalActivityBehaviour {
+
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ActivityExecution execution) throws Exception {
+ ExecutionImpl executionImpl = (ExecutionImpl) execution;
+ executionImpl.setSystemVariable("secret", "jbpm rocks");
+ execution.waitForSignal();
+ }
+
+ public void signal(ActivityExecution execution, String signalName, Map<String, ? > parameters) throws Exception {
+ ExecutionImpl executionImpl = (ExecutionImpl) execution;
+ assertEquals("jbpm rocks", executionImpl.getSystemVariable("secret"));
+
+ assertTrue(execution.getVariableKeys().isEmpty());
+ }
+ }
+
+ public void testSystemVariables() {
+ deployJpdlXmlString(
+ "<process name='SystemVariables'>" +
+ " <start>" +
+ " <transition to='c' />" +
+ " </start>" +
+ " <custom name='c' class='"+Systematic.class.getName()+"'>" +
+ " <transition to='end' />" +
+ " </custom>" +
+ " <end name='end' />" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("SystemVariables");
+ String pid = processInstance.getId();
+
+ assertTrue(executionService.getVariableNames(pid).isEmpty());
+
+ executionService.signalExecutionById(pid);
+ }
+}
Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/execution/SystemVariablesTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the jbpm-commits
mailing list