[jbpm-commits] JBoss JBPM SVN: r3432 - in jbpm4/trunk/modules: examples/src/test/java/org/jbpm/examples and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Dec 18 10:07:23 EST 2008
Author: tom.baeyens at jboss.com
Date: 2008-12-18 10:07:23 -0500 (Thu, 18 Dec 2008)
New Revision: 3432
Added:
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/Person.java
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/ScriptTextTest.java
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/script/
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/script/expression/
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/script/text/
jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/script/text/process.jpdl.xml
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptActivity.java
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptBinding.java
Modified:
jbpm4/trunk/modules/api/src/main/resources/jpdl.xsd
jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml
jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
Log:
added script
Modified: jbpm4/trunk/modules/api/src/main/resources/jpdl.xsd
===================================================================
--- jbpm4/trunk/modules/api/src/main/resources/jpdl.xsd 2008-12-18 14:37:05 UTC (rev 3431)
+++ jbpm4/trunk/modules/api/src/main/resources/jpdl.xsd 2008-12-18 15:07:23 UTC (rev 3432)
@@ -343,7 +343,7 @@
<complexType name="scriptType">
<sequence>
- <element name="script" type="string">
+ <element name="text" type="string">
<annotation><documentation>The content of this expression element
is the script text that will be evaluated. This is mutually
exclusive with the expression attribute.</documentation></annotation>
@@ -358,6 +358,10 @@
<annotation><documentation>Identification of the scripting language
to use.</documentation></annotation>
</attribute>
+ <attribute name="var" type="string">
+ <annotation><documentation>Name of the variable in which the result
+ of the script evaluation will be stored</documentation></annotation>
+ </attribute>
</complexType>
<attributeGroup name="nodeAttributes">
Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/Person.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/Person.java (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/Person.java 2008-12-18 15:07:23 UTC (rev 3432)
@@ -0,0 +1,44 @@
+/*
+ * 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.script.text;
+
+import java.io.Serializable;
+
+/**
+ * @author Tom Baeyens
+ */
+public class Person implements Serializable {
+
+ String address;
+
+ public Person(String address) {
+ this.address = address;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+}
Property changes on: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/ScriptTextTest.java
===================================================================
--- jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/ScriptTextTest.java (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/ScriptTextTest.java 2008-12-18 15:07:23 UTC (rev 3432)
@@ -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.examples.script.text;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.test.DbTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ScriptTextTest extends DbTestCase {
+
+ public void testScriptText() {
+ deployJpdlResource("org/jbpm/examples/script/text/process.jpdl.xml");
+
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("person", new Person("Honolulu"));
+
+ Execution execution = executionService.startExecutionByKey("ScriptText", variables);
+ String executionId = execution.getId();
+
+ String text = (String) executionService.getVariable(executionId, "text");
+ assertTextPresent("Send packet to Honolulu", text);
+ }
+
+}
Property changes on: jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/script/text/ScriptTextTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/script/text/process.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/script/text/process.jpdl.xml (rev 0)
+++ jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/script/text/process.jpdl.xml 2008-12-18 15:07:23 UTC (rev 3432)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process name="ScriptText" xmlns="http://jbpm.org/4/jpdl">
+
+ <start>
+ <flow to="invoke script" />
+ </start>
+
+ <script name="invoke script"
+ var="text">
+ <text>
+ Send packet to #{person.address}
+ </text>
+
+ <flow to="wait" />
+ </script>
+
+ <state name="wait" />
+
+</process>
Property changes on: jbpm4/trunk/modules/examples/src/test/resources/org/jbpm/examples/script/text/process.jpdl.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptActivity.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptActivity.java 2008-12-18 15:07:23 UTC (rev 3432)
@@ -0,0 +1,58 @@
+/*
+ * 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.activity;
+
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.script.ScriptManager;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ScriptActivity extends JpdlActivity {
+
+ private static final long serialVersionUID = 1L;
+
+ protected String script;
+ protected String language;
+ protected String variableName;
+
+ public void execute(ActivityExecution execution) {
+ ScriptManager scriptManager = Environment.getFromCurrent(ScriptManager.class);
+ Object returnValue = scriptManager.evaluateScript(script, execution, language);
+
+ if (variableName!=null) {
+ execution.setVariable(variableName, returnValue);
+ }
+ }
+
+ public void setScript(String script) {
+ this.script = script;
+ }
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+ public void setVariableName(String variableName) {
+ this.variableName = variableName;
+ }
+}
Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptActivity.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptBinding.java (rev 0)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptBinding.java 2008-12-18 15:07:23 UTC (rev 3432)
@@ -0,0 +1,70 @@
+/*
+ * 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.activity;
+
+import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.script.ScriptManager;
+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
+ */
+public class ScriptBinding extends JpdlActivityBinding {
+
+ private static final String TAG = "script";
+
+ public ScriptBinding() {
+ super(TAG);
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ String script = null;
+ String language = null;
+
+ String expr = XmlUtil.attribute(element, "expr");
+ Element textElement = XmlUtil.element(element, "text");
+ if(expr!=null) {
+ ScriptManager scriptManager = Environment.getFromCurrent(ScriptManager.class);
+ language = scriptManager.getDefaultExpressionLanguage();
+ if (textElement!=null) {
+ parse.addProblem("in <script ...> attribute expr can't be combined with a nexted text element");
+ }
+ } else {
+ language = XmlUtil.attribute(element, "lang");
+ script = XmlUtil.getContentText(textElement);
+ }
+
+ String variableName = XmlUtil.attribute(element, "var");
+
+ ScriptActivity scriptActivity = new ScriptActivity();
+ scriptActivity.setScript(script);
+ scriptActivity.setLanguage(language);
+ scriptActivity.setVariableName(variableName);
+
+ return scriptActivity;
+ }
+
+}
Property changes on: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/activity/ScriptBinding.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml 2008-12-18 14:37:05 UTC (rev 3431)
+++ jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.activities.xml 2008-12-18 15:07:23 UTC (rev 3432)
@@ -9,4 +9,5 @@
<activity binding="org.jbpm.jpdl.activity.HqlBinding" />
<activity binding="org.jbpm.jpdl.activity.SqlBinding" />
<activity binding="org.jbpm.jpdl.activity.JavaBinding" />
+ <activity binding="org.jbpm.jpdl.activity.ScriptBinding" />
</activities>
Modified: jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml 2008-12-18 14:37:05 UTC (rev 3431)
+++ jbpm4/trunk/modules/jpdl/src/main/resources/jbpm.jpdl.hbm.xml 2008-12-18 15:07:23 UTC (rev 3432)
@@ -67,6 +67,11 @@
foreign-key="FK_ACT_INVKOPER"
index="IDX_ACT_INVKOPER" />
</subclass>
+ <subclass name="org.jbpm.jpdl.activity.ScriptActivity" discriminator-value="script">
+ <property name="script" column="TEXT_" />
+ <property name="language" column="TEXT2_" />
+ <property name="variableName" column="TEXT3_" />
+ </subclass>
</class>
</hibernate-mapping>
\ No newline at end of file
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java 2008-12-18 14:37:05 UTC (rev 3431)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java 2008-12-18 15:07:23 UTC (rev 3432)
@@ -148,4 +148,11 @@
throw new JbpmException("script evaluation error: "+e.getMessage(), e);
}
}
+
+ public String getDefaultExpressionLanguage() {
+ return defaultExpressionLanguage;
+ }
+ public String getDefaultScriptLanguage() {
+ return defaultScriptLanguage;
+ }
}
More information about the jbpm-commits
mailing list