JBPM深入解析之變數設計

2021-05-26 17:42:32 字數 2618 閱讀 2548

jbpm深入解析之變數設計

在流程的流轉的過程中,很多時候我們需要根據不同的實際情況傳入一些初始化資料,以便完成我們個性化的業務需求;同時很多時候我們需要在不同的節點之間共享一些業務資料,特別是一些節點要以前一節點的輸出作為輸入等;變數對於流程引擎來說很重要,可以說沒有變數,那麼我們就不能執行時動態的設定和傳入一些資料,這將極大的限制流程的靈活性!

變數型別

全域性變數,所有的節點都可以獲取並設定該變數的值

區域性變數,只在該節點及其子節點可以獲取並設定該變數的值

變數的傳入

在流程定義中進行變數的定義

<?xml version="1.0" encoding="utf-8"?>

在啟動流程流程例項的時候傳入全域性變數

mapvariables = new hashmap();

variables.put("category", "big");

variables.put("dollars", 100000);

execution execution = executionservice.startprocessinstancebykey("taskvariables", variables);

在喚醒那些可外部喚醒型別的節點時候傳入區域性變數

variables = new hashmap();

variables.put("category", "small");

variables.put("lires", 923874893);

taskservice.completetask(taskid, variables)

在任務存在的情況下,可以在任務等待外部喚醒時進行區域性變數的設定

variables = new hashmap();

variables.put("category", "small");

variables.put("lires", 923874893);   

taskservice.setvariables(taskid, variables);

在任何時候都可以通過執行服務傳入設定全域性變數

variables = new hashmap();

variables.put("category", "small");

variables.put("lires", 923874893);   

executionservice.setvariable(execution.getid(),variables)

variables = new hashmap();

variables.put("category", "small");

variables.put("lires", 923874893);   

executionservice.signalexecutionbyid(execution.getid(),variables);

變數架構設計

package org.jbpm.pvm.internal.type;

/*** @author tom baeyens

*/public inte***ce typeset

defaulttypeset

typeset的初始化     在配置檔案中配置流程引擎中需要使用的變數的型別

jbpm.defaut.cfg.xml引入變數型別配置的檔案路徑

jbpm.variable.types.xml定義了變數的型別、使用的轉換器等資訊

typesbinding解析jbpm.variable.types.xml中的變數型別定義       

typedescriptor用於執行時生成defaulttypeset

matcher,遞迴查詢給定變數的型別以及所有的基類中是否有與該matcher對應的類的變數型別相同的。

public class classnamematcher implements matcher

public string tostring()

public boolean matches(string name, object value)

class> valueclass = value.getclass();

while (valueclass!=null) else

public object convert(object o, scopeinstanceimpl scopeinstance, variable variable)

} catch (ioexception e)

return bytes;

}public object revert(object o, scopeinstanceimpl scopeinstance, variable variable)

return object;

} catch (exception e) }}

variable,定義具體的變數以及一些持久化需要的屬性

public class stringvariable extends variable

public object getobject()

public void setobject(object value) else }}

JavaScript深入之變數物件

作用域鏈 scope chain this instanceof object console.log math.random console.log this.math.random 1 console.log this.a 1 console.log window.a this.window.b...

深入PHP使用技巧之變數

總所周知,php與其他指令碼語言一樣屬於弱變數型別的語言。同時php本身也是通過c語言來實現。本文主要介紹php內部是如何實現弱變數型別的,並且據此分析在php開發中的需要注意的一些使用技術。其中會重點分析php中的copy on write機制和引用相關方面的話題。本章節屬於深入 深入php使用技...

深入理解PHP原理之變數賦值

在前面的文章 深入理解php原理之變數結構 中我已經介紹了php變數的內部結構,下面我將會對變數賦值過程中,php內部對資料處理的原理進行闡述,不過在講述該原理前,需要先了解一下變數名和它的值是如何關聯起來的,這個對變數賦值內部原理的理解非常重要,例如 a 1 這個例子看起來非常簡單,但是你知道 變...