-
1. Re: Problems with usage python language in jpdl.xml
rebody Mar 29, 2010 3:40 AM (in response to chuiko.andrew)Now jBPM 4 could support JUEL, beanshell and groovy, If you want to use python in jpdl.xml, you should create a new ScriptEngineFactory, may be PythonScriptEngineFactory and put it into <script-manager>.
The default <script-manager> configuration is as following:
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<process-engine-context>
<script-manager default-expression-language="juel"
default-script-language="juel">
<script-language name="juel" factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
<script-language name="bsh" factory="org.jbpm.pvm.internal.script.BshScriptEngineFactory" />
<script-language name="groovy" factory="org.jbpm.pvm.internal.script.GroovyScriptEngineFactory" />
</script-manager>
</process-engine-context></jbpm-configuration>
-
2. Re: Problems with usage python language in jpdl.xml
chuiko.andrew Mar 29, 2010 3:48 PM (in response to rebody)Thahks, Huisheng Xu for your replay!! But I`ve included python factory into jbpm.default.scriptmanager.xml.
I`ve done it as this one - <script-language name="python" factory="org.python.jsr223.PyScriptEngineFactory" />.
And i checked it debuging code. So, in the class org.jbpm.pvm.internal.script.ScriptManager in the method evaluate(String script, String language)
I`ve got object ScriptEngine = org.python.jsr223.PyScriptEngine@6ca716
which have object interp = org.python.util.PythonInterpreter@17cd18d
and object factory = org.python.jsr223.PyScriptEngineFactory@f92541.
<script name="invoke script" var="text" lang="python" g="113,18,104,52">
<text>import sys;print "start test!";testvar1 = 2 * 2 + 90;print "testvar1=", testvar1</text>
<transition to="wait" />
</script>By this means that python is visible in jpdl.xml. But when evaluate(ScriptEngine scriptEngine, String script) is run then throw Exception
javax.script.ScriptException: NameError: name 'testvar1' is not defined in <script> at line number 1. For some reason variables can`t be remembered.
May be I try to use wrong factory org.python.jsr223.PyScriptEngineFactory???
If somebody hade met with this strangeness.
Thanks alot for replies!!! Andrew
-
3. Re: Problems with usage python language in jpdl.xml
rebody Mar 29, 2010 9:31 PM (in response to chuiko.andrew)Hi Andrey. If you set a process varaible named 'testvar1', then the script activity will run success. This is my test case:
public void testJava() {
this.deployJpdlClasspath("jpdl/x10script/X1003PythonTest.jpdl.xml");Map map = new HashMap();
map.put("testvar1", 10);ProcessInstance processInstance = executionService
.startProcessInstanceByKey("X1003PythonTest", map);
assertTrue(processInstance.isEnded());
}The content of jpdl.xml is as same as yours. But if I am not set a 'testvar1' variable, then the same Exception occured. I have checked the source of GroovyScriptEngineFactory, there were a lot of codes to evaluate the groovy snipts, I afraid that if you want to use local variable in script actviity, you should do it by yourself.
-
4. Re: Problems with usage python language in jpdl.xml
chuiko.andrew Mar 30, 2010 3:01 AM (in response to rebody)Thahks, Huisheng Xu for your replay!!!
I have told about locale variable.
So, script on groovy
<script name="invoke script" var="text" lang="groovy" g="113,18,104,52">
<text>
int xxx = 13 + 54*12
println "$xxx -HELLO!"
</text>
<transition to="wait" />
</script>Print following result 661 -HELLO!
And how we see int xxx = 13 + 54*12 remembered and printed !!!!!!!
But script on python language
<text>
yyy = 13 + 54*12
print yyy, "-HELLO!"
</text>throw org.jbpm.api.JbpmException: script evaluation error: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: yyy for class: Script1
It is strange!
Thanrs a lot Andrey.
-
5. Re: Problems with usage python language in jpdl.xml
chuiko.andrew Mar 30, 2010 5:20 AM (in response to chuiko.andrew)Hi !
I had localized this problem. The class org.jbpm.pvm.internal.script.EnvironmentBindings doesn`t store locale variables from script:
public Object put(String key, Object value) {
return null;
}Groovy engine ignores it and stores local variables in its own storage.
Jython engine obeys the limitations of Bindings, so it can`t store local variables if Bindings doesn`t allow it!!!!!
If is it desireable behaviour ?
Possible solution is adding local storage to EnvironmentBindings and to allow putting values in it.
Such as :
private HashMap<String, Object> locals = new HashMap<String, Object>();
public Object put(String key, Object value) {
return null;
}public Object get(Object key) {
if (locals.containsKey((String)key))
return locals.get((String)key);
else
return environment.get((String)key);
}What do you think about this?
Thanks a lot, Andrew