看了这么久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 
有猫相伴的日子 阅读(1530) 
评论(0)  编辑  收藏  所属分类: 
workflow