How to Use Dynamic Parameters for jbpm4 Java activities

Source: Internet
Author: User

When using Java activities in jbpm4, We need to input parameters from the outside. The example does not show how to implement them.

The following uses the built-in example of jbpm as an example:

First, modify the configuration file of the example:

 

Code

<? XML version = "1.0" encoding = "UTF-8" ?>

<ProcessName= "Java"Xmlns= "Http://jbpm.org/4.4/jpdl">

Start G =" 20, 20, 48, 48 " >
transition to =" Greet " />
Start >

<JavaName= "Greet"
Class
= "Org. jbpm. Examples. java. johndoe"
Method
= "Hello"
VaR
= "Answer"
G
= "96,16, 83,52">

< Field Name = "State" > < String Value = "Fine" /> </ Field >
< ARG >
< Ref Object = "MSG" />
</ ARG >
<! --  
<String value = "Hi, how are you? "/> </Arg>
-->
< Transition To = "Shake hand"   />
</ Java >

JAVA name =" shake hand "
expr
=" # {hand}"
method
=" Shake "
var
=" hand "
G
=" 215,17, 99,52 " >

Arg > Object expr =" # {joesmoe. handshakes. force} " /> Arg >
Arg > Object expr =" # {joesmoe. handshakes. duration} " /> Arg >

<TransitionTo= "Wait" />
</Java>

<StateName= "Wait"G= "352,17, 88,52"/>

</Process>

 

 

 

We modified the XML file and put <string value = "Hi, how are you? "/> </Arg>
Change <RefObject= "MSG"/>
JavaCodeTo:

 

Code

Package Org. jbpm. Examples. Java;

ImportJava. util. hashmap;
ImportJava. util. Map;

ImportOrg. jbpm. API. processinstance;
ImportOrg. jbpm. Test. jbpmtestcase;

/**
*
@ AuthorTom Baeyens
 
*/
Public ClassJavainstantiatetestExtendsJbpmtestcase {

String deploymentid;

Protected   Void Setup () Throws Exception {
Super . Setup ();

Deploymentid
= Repositoryservice. createdeployment ()
. Addresourcefromclasspath (
" Org/jbpm/examples/Java/process. jpdl. xml " )
. Deploy ();
}

Protected VoidTeardown ()ThrowsException {
Repositoryservice. deletedeploymentcascade (deploymentid );

Super. Teardown ();
}

Public   Void Testjavainstantiate (){
Map
< String, Object > Variables =   New Hashmap < String, Object > ();
Variables. Put (
" Hand " , New Hand ());
Variables. Put (
" Joesmoe " , New Joesmoe ());
Variables. Put (
" MSG " , " Hi, how are you? " );

Processinstance
= Executionservice. startprocessinstancebykey ( " Java " , Variables );
String PID
= Processinstance. GETID ();

String answer
= (String) executionservice. getvariable (PID, " Answer " );
Assertequals (
" I'm fine, thank you. " , Answer );

Hand hand=(Hand) executionservice. getvariable (PID,"Hand");
Asserttrue (hand. isshaken ());
}
}

 

we added variables to the Java code. put ( " MSG " , " hi, how are you? " ); MSG is passed in as a Java parameter.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.