论坛首页 Java企业应用论坛

jBPM3.2.2源码分析---org.jbpm.taskmgmt*包&&org.jbpm.web*

浏览 2648 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-03-23  
org.jbpm.taskmgmt.def包:
-def
--AssignmentHandler.java
--Swimlane.hbm.xml
--Swimlane.java
--Task.hbm.xml
--Task.java
--TaskController.hbm.xml
--TaskController.java
--TaskControllerHandler.java
--TaskMgmtDefinition.hbm.xml
--TaskMgmtDefinition.java


AssignmentHandler一个接口,定义了assign()方法.

Swimlane.java、Swimlane.hbm.xml与jbpm数据库的JBPM_SWIMLANE相对应,起作用是把某任务分配到某个人上.泳道的代码很简单,找里不多介绍了.

Task.java、Task.hbm.xml与jbpm数据库的JBPM_TASK相对应
下面看一看Task的parePriority()方法,根据字符串比较,返回任务的优先级(Task分为5个优先级),任务事件类型数组有四个元素,分别是:
EVENTTYPE_TASK_CREATE,EVENTTYPE_TASK_ASSIGN,EVENTTYPE_TASK_START,EVENTTYPE_TASK_END.

TaskController.java、TaskController.hbm.xml与jbpm数据库的JBPM_TASKCONTROLLER相对应,TaskController是一个任务控制器.

TaskMgmtDefinition.java、TaskMgmtDefinition.hbm.xml与jbpm数据库的JBPM_TASKMGMTDEFINITION相对应,一个流程定义有一个TaskMgmtDefinition,
一个TaskMgmtDefinition对应多个swimlane,同时对应多个task;一个swimlane有多个task,可以从TaskMgmtDefinition中通过task的名称直接获取相应的task;



org.jbpm.taskmgmt.exe包:
-exe
--Assignable.java
--PooledActor.hbm.xml
--PooledActor.java
--SwimlaneInstance.hbm.xml
--SwimlaneInstance.java
--TaskInstance.hbm.xml
--TaskInstance.java
--TaskMgmtInstance.hbm.xml
--TaskMgmtInstance.java


Assignable接口定义了setActorId()和setPooledActors()两个方法.

PooledActor.java、PooledActor.hbm.xml与jbpm数据库的JBPM_POOLEDACTOR相对应.
来重点看一下PooledActor的createPool()方法:

public static Set createPool(String[] actorIds, SwimlaneInstance swimlaneInstance, TaskInstance taskInstance) {
    Set pooledActors = new HashSet();
    for (int i=0; i<actorIds.length; i++) {
    	//循环创建PooledActor
      PooledActor pooledActor = new PooledActor(actorIds[i]);
      if (swimlaneInstance!=null) {
      	//设置PooledActor的泳道实例
        pooledActor.setSwimlaneInstance(swimlaneInstance);
      }
      if (taskInstance!=null) {
        //为PooledActor添加任务实例
        pooledActor.addTaskInstance(taskInstance);
      }
      //把PooledActor添加到PooledActors Set中
      pooledActors.add(pooledActor);
    }
    return pooledActors;
  }

 
SwimlaneInstance.java、SwimlaneInstance.hbm.xml与jbpm数据库的JBPM_SWIMLANE想对应,泳道实例实现了Assignable借口。

TaskInstance.java、TaskInstance.hbm.xml与jbpm数据库的JBPM_TASKINSTANCE相对应


org.jbpm.web下有三个类:
CloseJbpmConfigurationServlet.java
JbpmContextFilter.java
ProcessUploadServlet.java

ProcessUploadServlet,这个servlet负责上传、部署流程定义文件,主要代码如下:
jbpm用Apache commons项目的commons fileupload实现上传文件的操作

try {
            DiskFileUpload fileUpload = new DiskFileUpload();
	    //从request中解析出FileItem实例的一个List
            List list = fileUpload.parseRequest(request);
            log.debug("Upload from GPD");
            Iterator iterator = list.iterator();
            if (!iterator.hasNext()) {
                log.debug("No process file in the request");
                return "No process file in the request";
            }
            FileItem fileItem = (FileItem) iterator.next();
            if (fileItem.getContentType().indexOf("application/x-zip-compressed") == -1) {
                log.debug("Not a process archive");
                return "Not a process archive";
            }
            try {
                log.debug("Deploying process archive " + fileItem.getName());
		//从FileItem中获得输入流,由此创建zip输入流
                ZipInputStream zipInputStream = new ZipInputStream(fileItem.getInputStream());
		//获取jbpm上下文
                JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
                log.debug("Preparing to parse process archive");
		//从zip输入流中解析流程定义
                ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream);
                log.debug("Created a processdefinition : " + processDefinition.getName());
		//部署流程定义到数据库中
                jbpmContext.deployProcessDefinition(processDefinition);
                zipInputStream.close();
                return "Deployed archive " + processDefinition.getName() + " successfully";
            } catch (IOException e) {
                return "IOException";
            }

jbpmContextFilter是jbpm的一个过滤器,部分代码如下:

//doFilter()方法:
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    String actorId = null;
    if (servletRequest instanceof HttpServletRequest) {
      HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
      Principal userPrincipal = httpServletRequest.getUserPrincipal();
      if (userPrincipal != null) {
        actorId = userPrincipal.getName();
      }
    }
    //根据初始化时得到的jbpmContextName创建JbpmContext
    JbpmContext jbpmContext = getJbpmConfiguration().createJbpmContext(jbpmContextName);
    try {
      if (isAuthenticationEnabled) {
         //设置actor
        jbpmContext.setActorId(actorId);
      }
      filterChain.doFilter(servletRequest, servletResponse);
    } finally {
      jbpmContext.close();
    }
  }


CloseJbpmConfigurationServlet很简单,init()、destroy()、getInitParameter()在三个方法。
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics