jbpm4 java活动如何使用动态参数

在jbpm4中使用java活动的时候我们需要从外部传入参数,在例子中没有说明如何实现。

下面以jbpm的自带的例子为例:

首先我们修改例子的配置文件:

 

ExpandedBlockStart.gif 代码
<? xml version="1.0" encoding="UTF-8" ?>

< process  name ="Java"  xmlns ="http://jbpm.org/4.4/jpdl" >

  
< start  g ="20,20,48,48" >
    
< transition  to ="greet"   />
  
</ start >

  
< java  name ="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 >

    
< transition  to ="wait"   />
  
</ java >

  
< state  name ="wait"  g ="352,17,88,52" />

</ process >

 

 

 

我们修改了xml文件,在arg把 <string value="Hi, how are you?"/></arg>
 修改为 <ref object="msg"/>
java代码修改为:

 

ExpandedBlockStart.gif 代码
package  org.jbpm.examples.java;

import  java.util.HashMap;
import  java.util.Map;

import  org.jbpm.api.ProcessInstance;
import  org.jbpm.test.JbpmTestCase;


/**
 * 
@author  Tom Baeyens
 
*/
public   class  JavaInstantiateTest  extends  JbpmTestCase {

  String deploymentId;
  
  
protected   void  setUp()  throws  Exception {
    
super .setUp();
    
    deploymentId 
=  repositoryService.createDeployment()
        .addResourceFromClasspath(
" org/jbpm/examples/java/process.jpdl.xml " )
        .deploy();
  }

  
protected   void  tearDown()  throws  Exception {
    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 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());
  }
}

 

我们在java代码中加入了 variables.put("msg""Hi, how are you?"); 其中msg作为java的参数传入。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值