动作节点

动作节点可以与一个实现了com.bstek.urule.model.flow.FlowAction接口并配置到Spring中的Bean绑定,这样在运行时,规则流执行到这个动作节点时就会执行与之绑定的FlowAction实现类,动作节点属性如下表所示:

属性名称 数据类型 描述
节点名称 String 设置当前节点名称
事件bean String 一实现了com.bstek.urule.model.flow.NodeEvent接口配置在Spring中bean的id,一旦配置在流程进入及离开该节点时会触发这个实现类
动作bean String 一个实现了com.bstek.urule.model.flow.FlowAction接口并配置到Spring中的Bean的ID。

FlowAction接口源码如下所示:

package com.bstek.urule.model.flow;
import com.bstek.urule.model.flow.ins.FlowContext;
import com.bstek.urule.model.flow.ins.FlowInstance;
/**
 * @author Jacky.gao
 * @since 2015年2月28日
 */
public interface FlowAction {
    /**
     * @param node 当前节点对象
     * @param context 规则流上下文件对象
     * @param instance 当前规则流实例对象
     */
    void execute(ActionNode node,FlowContext context,FlowInstance instance);
}

有了动作节点,那么在规则流中就可以执行具体的Java类中的方法,因为该Java类是配置在Spring上下文中的,所以类中可访问Spring环境所有信息,这样就可以做一些更为复杂的业务操作。

动作节点出入连接线如下表所示:

流入的连接线数量 流出的连接线数量
1~n 0~1

在代码中获取工作区中的变量或者参数数据

KnowledgeSession ks = (KnowledgeSession) flowContext.getWorkingMemory();
Map<String,Object> factMap = ks.getFactManager().getFactMap();
//取工作区中变量
User user = (User) factMap.get("com.bstek.urule.sample.pojo.User");
//如果变量不存在对应的java pojo类,用GeneralEntity
GeneralEntity cust = (GeneralEntity) factMap.get("com.bstek.urule.sample.pojo.Cust");
//取工作区中参数
double total = (double) ks.getParameter("total");

在代码中往工作区中添加变量或者参数数据

//如果需要往工作区中添加变量数据
GeneralEntity newUser = new GeneralEntity("com.bstek.urule.sample.pojo.User");
ks.getFactManager().getFactMap().put("com.bstek.urule.sample.pojo.User",newUser);
//如果需要往工作区中添加参数数据
ks.getParameters().put("totalScore", 100);

results matching ""

    No results matching ""