Method:
1) specify someone directly and write in. jpdl. xml: assignee = "James"
2) use the process variable and write it in. jpdl. xml: assignee = "# {manager }"
3), use the class (at this time, you do not need to set the attribute xuancheng none), write in. jpdl. xml:
<Assignment-handler class = "com. njupt. task. assignmenthandlerimpl"/>
4), processengine. gettaskservice (). assigntask (taskid, userid); // re-specify the Handler
The following points are described:
1. For 2), the source code is as follows:
Package COM. njupt. task; import Java. io. inputstream; import Java. util. hashmap; import Java. util. map; import Org. jbpm. API. configuration; import Org. jbpm. API. processengine; import Org. jbpm. API. processinstance; import Org. jbpm. API. task. task; import Org. JUnit. test; public class processtest {private processengine = configuration. getprocessengine (); @ testpublic void test () throws exception {// 1. the deployment process defines inputstream in = getclass (). getresourceasstream ("test. jpdl. XML "); processengine. getrepositoryservice ()//. createdeployment ()//. addresourcefrominputstream ("test. jpdl. XML ", in )//. deploy (); // 2. Start the process instance Map <string, Object> variables = new hashmap <string, Object> (); variables. put ("manager", "Manager Li"); // This corresponds to the # {manager} processinstance Pi = processengine. getexecutionservice (). startprocessinstancebykey ("test", variables );}}
2. For 3), 4) the source code is as follows:
1> first, write the handler's processing class
Package COM. njupt. task; import Org. jbpm. API. model. openexecution; import Org. jbpm. API. task. assignable; import Org. jbpm. API. task. assignmenthandler; public class assignmenthandlerimpl implements assignmenthandler {// calculates and specifies the task handler @ overridepublic void assign (assignable, openexecution execution) throws exception {system. out. println ("---> assignmenthandlerimpl. assign () "); // computing handler string userid =" Zhao manager ++ "; // specify handler assignable. setassignee (userid); // assignable. addcandidateuser ("Manager AA"); // assignable. addcandidateuser ("Manager BB"); // assignable. addcandidateuser ("Manager cc ");}}
2> writing test classes for Process Design
Package COM. njupt. task; import Java. io. inputstream; import Org. jbpm. API. configuration; import Org. jbpm. API. processengine; import Org. jbpm. API. processinstance; import Org. JUnit. test; public class processtest {private processengine = configuration. getprocessengine (); @ testpublic void test () throws exception {// 1. the deployment process defines inputstream in = getclass (). getresourceasstream ("test. jpdl. XML "); processengine. getrepositoryservice ()//. createdeployment ()//. addresourcefrominputstream ("test. jpdl. XML ", in )//. deploy (); // 2, START process instance processinstance Pi = processengine. getexecutionservice (). startprocessinstancebykey ("test");} // re-allocate the task (re-specify the handler) @ testpublic void testassigntask () throws exception {string taskid = "270009 "; string userid = "Manager Zhao ++"; processengine. gettaskservice (). assigntask (taskid, userid );}}