看了這么久jbpm還沒有一個頭緒,需要繼續分析。jbpm把流程部署到數據庫有好幾種方法,今晚終于調試通過了java直接部署 的子,僅為述于此,不做分析。
static JbpmConfiguration cfg=JbpmConfiguration.getInstance(); //jbpm一切一切的基礎
public void setUp(){
//cfg.createSchema(); //重建jbpm存儲層..
}
以下是一個部署的方法
public void testDeployProcessDefinition()throws Exception{
assertNotNull("JbpmConfiguration is null",cfg);
FileInputStream fis = new FileInputStream("src/proc1.xml");
ProcessDefinition pd=ProcessDefinition.parseXmlInputStream(fis);
assertNotNull("definition should not be null",pd);
JbpmContext jc=cfg.createJbpmContext();
try{
jc.deployProcessDefinition(pd);
}finally{
jc.close();
}
}
實例化并生成流程實例的方法
public void testLoadProcessAndInstance() throws Exception {
JbpmContext jbpmContext = cfg.createJbpmContext() ;
try {
GraphSession graphSession = jbpmContext.getGraphSession();
ProcessDefinition processDefinition =
graphSession.findLatestProcessDefinition("pro1");
ProcessInstance processInstance =
new ProcessInstance(processDefinition);
Token token = processInstance.getRootToken();
assertEquals("start", token.getNode().getName());
// Let's start the process execution
token.signal();
assertEquals("state1", token.getNode().getName());
jbpmContext.save(processInstance);
} finally {
// Tear down the pojo persistence context.
jbpmContext.close();
}
}
再執行上面生成的流程方法
public void testLoadInstanceAndDoActionAndEnd() throws Exception {
JbpmContext jbpmContext = cfg.createJbpmContext() ;
try {
GraphSession graphSession = jbpmContext.getGraphSession();
ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("pro1");
List processInstances = graphSession.findProcessInstances(processDefinition.getId());
ProcessInstance processInstance = (ProcessInstance) processInstances.get(0);
// this.assertEquals("message",(String)(processInstance.getContextInstance().getVariable("message")));
processInstance.signal();
assertTrue(processInstance.hasEnded());
jbpmContext.save(processInstance);
} finally {
jbpmContext.close();
}
}
實際上,上面的幾段代碼中寫來寫去就這幾句話吧。加載流程,生成實例,然后簽收執行。
明天繼續......
posted on 2007-04-09 23:27
有貓相伴的日子 閱讀(1516)
評論(0) 編輯 收藏 所屬分類:
workflow