浏览 4560 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (8) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-06-08
最后修改:2009-09-17
HelloWorldProcess.xml <process-definition name='helloProcess'> <event type="node-enter"> <script> System.out.println("this script is entering node "+node); </script> </event> <start-state > <transition to='start' /> </start-state> <state name='start'> <transition to='end' /> </state> <end-state name='end' /> </process-definition> TestHelloWorldProcess.java public class TestHelloWorldProcess { private static Log log = LogFactory.getLog(TestHelloWorldProcess.class); /** * pd's name. */ private static String pdName = "helloProcess"; /** * pd's definition xml's file path. */ private static String filePath = "HelloWorldProcess.xml"; /** * One JbpmConfiguration can have many JbpmContexts. */ private static JbpmConfiguration jbpmConfiguration = JbpmConfiguration .getInstance(); private static JbpmContext getJbpmContext() { JbpmContext context = jbpmConfiguration.getCurrentJbpmContext(); if (context == null) context = jbpmConfiguration.createJbpmContext(); return context; } /** * Deploy ProcessDefinition. */ private static long deployProcessDefinition() { JbpmContext jbpmContext = getJbpmContext(); try { // parse ProcessDefinition from .xml file. ProcessDefinition processDefinition = ProcessDefinition .parseXmlResource(filePath); // deploy ProcessDefinition to db. jbpmContext.deployProcessDefinition(processDefinition); return processDefinition.getId(); } finally { jbpmContext.close(); } } /** * Create new ProcessInstance. */ private static long createProcessInstance() { JbpmContext jbpmContext = getJbpmContext(); try { GraphSession gSession = jbpmContext.getGraphSession(); ProcessDefinition pd = gSession.findLatestProcessDefinition(pdName); ProcessInstance processInstance = new ProcessInstance(pd); jbpmContext.save(processInstance); return processInstance.getId(); } finally { jbpmContext.close(); } } private static void triggerProcess1(long piId) { JbpmContext jbpmContext = getJbpmContext(); try { ProcessInstance processInstance = jbpmContext .getProcessInstance(piId); // After construction, the process execution has one main path // of execution (=the root token). Token token = processInstance.getRootToken(); // Let's start the process execution, leaving the start-state // over its default transition. // The signal method will block until the process execution // enters a wait state. token.signal(); jbpmContext.save(token); jbpmContext.save(processInstance); } finally { jbpmContext.close(); } } private static void triggerProcess2(long piId) { JbpmContext jbpmContext = getJbpmContext(); try { ProcessInstance processInstance = jbpmContext .getProcessInstance(piId); Token token = processInstance.getRootToken(); token.signal(); jbpmContext.save(token); jbpmContext.save(processInstance); } finally { jbpmContext.close(); } } private static void deleteProcessDefinition(long pdId) { JbpmContext jbpmContext = getJbpmContext(); try { GraphSession gSession = jbpmContext.getGraphSession(); gSession.deleteProcessDefinition(pdId); } finally { jbpmContext.close(); } } public static void main(String[] args) { DOMConfigurator.configure("config\\LogConfig.xml"); long pdId = deployProcessDefinition(); long piId = createProcessInstance(); triggerProcess1(piId); triggerProcess2(piId); deleteProcessDefinition(pdId); } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-09-28
有没有源码.
|
|
返回顶楼 | |
发表时间:2009-09-28
elvishehai 写道 有没有源码.
有,但是没有办法上传。也没有办法发mail。 |
|
返回顶楼 | |