jBPM4.4开发(五)-----------custom节点

自定义节点custom

调用用户代码,实现一个自定义的活动行为。

Demo:
流程定义文件:custom.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>

<process name="custom" xmlns="http://jbpm.org/4.4/jpdl">
   <start name="start1" g="26,125,48,48">
      <transition name="to printDots" to="printDots" g="-35,-16"/>
   </start>
   <custom name="printDots" g="152,125,92,52" class="com.itstudio.jbpm.custom.demo.PrintDots">
      <transition name="to end1" to="end1" g="-16,-17"/>
   </custom>
   <end name="end1" g="308,128,48,48"/>
</process>

自定义行为类PrintDots.java
package com.itstudio.jbpm.custom.demo;

import java.util.Map;

import org.jbpm.api.activity.ActivityExecution;
import org.jbpm.api.activity.ExternalActivityBehaviour;

public class PrintDots implements ExternalActivityBehaviour{

	 private static final String NEWLINE = System.getProperty("line.separator");
	 
	public void signal(ActivityExecution execution, String signalName, Map<String, ?> parameters)
			throws Exception {
		 execution.take(signalName);
	}

	@Override
	public void execute(ActivityExecution execution) throws Exception {
		 String executionId = execution.getId();
		    
		    

		 String dots = 
		      "                              "+".::::.                    " + NEWLINE +
		      "     " +"                " +"       .:::::" +":::.                  " + 
		      NEWLINE + "                            :::::::::::                 " + NEWLINE +
		      "           " + "                 ':::::::::::..              " 
		      + NEWLINE +"                             ::::" +":::::::::::'           " + NEWLINE +"                              ':::::::::::.             " + NEWLINE +
		      "                                .::::::::" +"::::::'        " + NEWLINE +"                              " +".:::::::::::...           " + NEWLINE +
		      "                             ::::::::::::::''" + 
		      "           " + NEWLINE +"                 .:::.       '::::::::''::::            " + NEWLINE + 
		      "               .::::::::.  " +
		      "    ':::::'  '::::           " + NEWLINE +"              " 
		      +".::::':::::::.   " +" :::::    '::::.         " + NEWLINE +"            .:::::' '::::" 
		      +":::::. :::::      ':::.        " + NEWLINE +"          .:::::'     ':::::::::.:::::   " +"    '::.       " + 
		      NEWLINE +"        .::::''         '::::::::::::::       '::.      " + NEWLINE +"       .::''              ':::::" 
		      +":::::::         :::...  " + NEWLINE +"    ..::::                  ':::::::::'     " +
		      "   .:' '''' " + NEWLINE +" ..''''':'                    ':::::.'                  " + NEWLINE;
			System.out.println(dots);
		    
		    execution.waitForSignal();
	}

}


测试类:CustomTest.java
package com.itstudio.jbpm.custom.demo;

import org.jbpm.api.Configuration;
import org.jbpm.api.Execution;
import org.jbpm.api.ExecutionService;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.RepositoryService;
import org.jbpm.api.TaskService;



public class CustomTest {
	public  final Configuration configuration = new Configuration();
	public  final ProcessEngine processEngine=configuration.buildProcessEngine();
	public  final RepositoryService repositoryService= processEngine.getRepositoryService();
	public  final ExecutionService executionService=processEngine.getExecutionService();
	public  final TaskService taskService=processEngine.getTaskService();
	
	private void deploy() {
		repositoryService.createDeployment().
			addResourceFromClasspath("com/itstudio/jbpm/custom/demo/custom.jpdl.xml").deploy();
		System.out.println("发布成功");
	}
	private void test() {
		ProcessInstance processInstance = executionService
				.startProcessInstanceByKey("custom");
		System.out.println("当前节点:" + processInstance.findActiveActivityNames());
		Execution executionInPrintDots = processInstance
				.findActiveExecutionIn("printDots");
		String executionId = executionInPrintDots.getId();
		// 调用下行方法,应该是调用自定义节点的signal方法,从而调用take方法离开该活动,转到结束
		executionService.signalExecutionById(executionId, "to end1");
		// 但发现结果是流程未结束,当前激活的活动还是printDots
		System.out.println("进行到:" + processInstance.findActiveActivityNames());
		System.out.println("是否结束:" + processInstance.isEnded());
	
	}
	public static void main(String[] args) {
		CustomTest test = new CustomTest();
		test.deploy();
		test.test();
	}
}


By Mr.Z

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值