1.启动流程实例


[java] view plaincopy在CODE上查看代码片派生到我的代码片

  1. // 启动流程实例  

  2. @Test  

  3. public void startProcessInstance() {  

  4.     // 使用指定key的最新版本的流程定义启动流程实例  

  5.     ProcessInstance pi = processEngine.getExecutionService().startProcessInstanceByKey("test");  

  6.     System.out.println("processInstanceId=" + pi.getId());  

  7. }  



2.设置流程变量

a) 一个设置流程变量实例


[java] view plaincopy在CODE上查看代码片派生到我的代码片

  1. //设置流程变量  

  2. @Test  

  3. public void setVariable() {  

  4.     String executionId = "test.140001";  

  5.     String name = "请假天数";  

  6.     Integer value = 3;  

  7.   

  8.     //将name为"请假天数",value=3的流程变量设置到executionId为test.140001的执行对象上  

  9.     processEngine.getExecutionService().setVariable(executionId, name, value);  

  10. }  



b) 所有设置流程变量方法

用到变量的类型:


[java] view plaincopy在CODE上查看代码片派生到我的代码片

  1. Object value = "";  

  2. String executionId = "";  

  3. String taskId = "";  

  4. String name = "";  

  5. String processDefinitionKey = "";  

  6. String variableName = "";  

  7. Set<String> variableNames = new HashSet<String>();  

  8. Map<String, Object> variablesMap = new HashMap<String, Object>();  


具体方法:


[java] view plaincopy在CODE上查看代码片派生到我的代码片

  1. // 根据Execution设置一个流程变量  

  2. processEngine.getExecutionService().setVariable(executionId, name, value);  

  3. // 根据Execution设置多个流程变量(需要先把流程变量放到一个Map中)  

  4. processEngine.getExecutionService().setVariables(executionId, variablesMap);  

  5.   

  6. // 根据Task设置多个流程变量(需要先把流程变量放到一个Map中,通过Task方法,它会先找到它所属的Execution然后设置流程变量)  

  7. processEngine.getTaskService().setVariables(taskId, variablesMap);  

  8.   

  9. // 使用指定key的最新版本的流程定义启动流程实例,并设置一些流程变量  

  10. processEngine.getExecutionService().startProcessInstanceByKey(processDefinitionKey, variablesMap);  

  11. // 办理完指定的任务,并设置一些流程变量  

  12. processEngine.getTaskService().completeTask(taskId, variablesMap);  



3.获取流程变量

a) 一个获取流程变量实例


[java] view plaincopy在CODE上查看代码片派生到我的代码片

  1. //获取流程变量  

  2. @Test  

  3. public void getVariable() {  

  4.     String executionId = "test.140001";  

  5.     String variableName = "请假天数";  

  6.   

  7.     //从executionId为test.140001的执行对象上取出流程变量名为"请假天数"的流程变量的value  

  8.     Integer value = (Integer) processEngine.getExecutionService().getVariable(executionId, variableName);  

  9.     System.out.println(variableName + " = " + value);  

  10. }  



b) 所有获取流程变量方法

用到变量的类型:


[java] view plaincopy在CODE上查看代码片派生到我的代码片

  1. String executionId = "";  

  2. String taskId = "";  

  3. String variableName = "";  

  4. Set<String> variableNames = new HashSet<String>();  


具体方法:


[java] view plaincopy在CODE上查看代码片派生到我的代码片

  1. // 根据Execution获取指定名称的一个流程变量  

  2. processEngine.getExecutionService().getVariable(executionId, variableName);  

  3. // 根据Execution获取所有流程变量的名称  

  4. processEngine.getExecutionService().getVariableNames(executionId);  

  5. // 根据Execution获取指定名称的所有流程变量  

  6. processEngine.getExecutionService().getVariables(executionId, variableNames);  

  7.   

  8. // 根据Task获取指定名称的一个流程变量  

  9. processEngine.getTaskService().getVariable(taskId, variableName);  

  10. // 根据Task获取所有流程变量的名称  

  11. processEngine.getTaskService().getVariableNames(taskId);  

  12. // 根据Task获取指定名称的所有流程变量  

  13. processEngine.getTaskService().getVariables(taskId, variableNames);  



4.流程变量所支持的值的类型(jBPM User Guide,7.2. Variable types)

jBPM supports following Java types as process variables:


  • java.lang.String 

  • java.lang.Long 

  • java.lang.Double 

  • java.util.Date 

  • java.lang.Boolean 

  • java.lang.Character 

  • java.lang.Byte 

  • java.lang.Short 

  • java.lang.Integer 

  • java.lang.Float 

  • byte[] (byte array) 

  • char[] (char array) 

  • hibernate entity with a long id 

  • hibernate entity with a string id 

  • serializable