阿木申 申楠

热衷编程技术 | 申楠 : qq:38371354 | msn:amushen2005@hotmail.com

导航

[原创]JBPM中的基本操作代码

Posted on 2007-07-02 13:09  阿木申  阅读(1184)  评论(0编辑  收藏  举报
最近研究了一下jBMP,将一些常用的方法记录下来:
public class BasicTest extends TestCase {
    
    
public void testSave(){
        JbpmContext jbpmContext
=null;
        
try //保存一个流程定义
        FileInputStream fis = new FileInputStream("src/main/jpdl/buy/processdefinition.xml");
        ProcessDefinition processDefinition 
= ProcessDefinition.parseXmlInputStream(fis);
        ProcessInstance instance 
= new ProcessInstance(processDefinition);
        jbpmContext 
= JbpmConfiguration.getInstance().createJbpmContext();
        
        jbpmContext.deployProcessDefinition(processDefinition);
        
        }
catch(Exception e){
        }
 finally {         
            jbpmContext.close();  
        }

    }

    
    
public void testCreateNewProcess(){
        JbpmContext jbpmContext 
= JbpmConfiguration.getInstance().createJbpmContext();
        
//ProcessInstance lastIns=jbpmContext.getProcessInstance(2);
        GraphSession graphSession = jbpmContext.getGraphSession();
        ProcessDefinition processDefinition1 
= graphSession.findLatestProcessDefinition("buy");
        ProcessInstance lastIns
=new ProcessInstance(processDefinition1);
        jbpmContext.save(lastIns);
        jbpmContext.close();        
    }

    
    
public void testSignal(){
        JbpmContext jbpmContext 
= JbpmConfiguration.getInstance().createJbpmContext();
        ProcessInstance ins
=jbpmContext.getProcessInstance(1);        
        System.out.println(
"root token:"+ins.getRootToken().getNode().getName());
        ins.signal();        
        System.out.println(
"root token:"+ins.getRootToken().getNode().getName());
        jbpmContext.save(ins);
        jbpmContext.close();
    }

    
    
public void _testManTask(){
        JbpmContext jbpmContext 
= JbpmConfiguration.getInstance().createJbpmContext();
                
        
//List list=jbpmContext.getTaskMgmtSession().findTaskInstances("shennan");
        List list=jbpmContext.getTaskMgmtSession().findPooledTaskInstances("shennan");
        
for(int i=0;i<list.size();i++){
            TaskInstance ti
=(TaskInstance)list.get(i);
            System.out.println(
"man task:"+ti.getName()+","+ti.getTaskMgmtInstance().getId());
            
            ti.end(
"to decision1");
        }

        
if(list.size()==0)System.out.println("no this man 's task!");
        jbpmContext.close();
    }

    
    
public void testSwimlane(){
        JbpmContext jbpmContext 
= JbpmConfiguration.getInstance().createJbpmContext();
                
        
//List list=jbpmContext.getTaskMgmtSession().findTaskInstances("shennan");
        List list=jbpmContext.getTaskMgmtSession().findPooledTaskInstances("shennan");
        
for(int i=0;i<list.size();i++){
            TaskInstance ti
=(TaskInstance)list.get(i);
            System.out.println(
"man task:"+ti.getName()+","+ti.getTaskMgmtInstance().getId());
            
            ti.end(
"to购买");
        }

        
if(list.size()==0)System.out.println("no this man 's task!");
        
        System.out.println(
"开始购买");
        List ll
=jbpmContext.getTaskList("shennan");
        
if(ll.size()>0){
            TaskInstance ti
=(TaskInstance)ll.get(0);
            ti.end(
"to 选择物品");
        }

        
        System.out.println(
"退回");
        
//list=jbpmContext.getTaskMgmtSession().findPooledTaskInstances("shennan");\
        list=jbpmContext.getTaskMgmtSession().findTaskInstances("limeng");
        
if(list.size()>0){
            System.out.println(
"重做");
            TaskInstance ti
=(TaskInstance)list.get(0);
            ti.end(
"to decision1");
            
        }

                
        jbpmContext.close();
    }

}