taskinstance.java.svn-base
来自「Fire-Workflow-Engine-All-In-One-20090208」· SVN-BASE 代码 · 共 535 行 · 第 1/2 页
SVN-BASE
535 行
package org.fireflow.engine.impl;
// Generated Feb 23, 2008 12:04:21 AM by Hibernate Tools 3.2.0.b9
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.fireflow.engine.EngineException;
import org.fireflow.engine.IProcessInstance;
import org.fireflow.engine.IRuntimeContextAware;
import org.fireflow.engine.ITaskInstance;
import org.fireflow.engine.RuntimeContext;
import org.fireflow.engine.ou.IAssignable;
import org.fireflow.engine.persistence.IPersistenceService;
import org.fireflow.engine.IWorkItem;
import org.fireflow.engine.IWorkflowSession;
import org.fireflow.engine.IWorkflowSessionAware;
import org.fireflow.engine.definition.WorkflowDefinition;
import org.fireflow.engine.event.ITaskInstanceEventListener;
import org.fireflow.engine.event.TaskInstanceEvent;
import org.fireflow.engine.taskinstance.IApplicationHandler;
import org.fireflow.kenel.IActivityInstance;
import org.fireflow.kenel.INetInstance;
import org.fireflow.kenel.IToken;
import org.fireflow.kenel.KenelException;
import org.fireflow.model.DataField;
import org.fireflow.model.EventListener;
import org.fireflow.model.Task;
import org.fireflow.model.WorkflowProcess;
import org.fireflow.model.net.Activity;
import org.fireflow.model.reference.SubWorkflowProcess;
/**
* TaskInstance generated by hbm2java
*/
public class TaskInstance implements ITaskInstance, IAssignable, IRuntimeContextAware,IWorkflowSessionAware, java.io.Serializable {
private String id = null;
private String taskId = null;
private String activityId = null;
private String name = null;
private String displayName = null;
private Integer state = null;
private Date createdTime = null;
private Date startedTime = null;
private Date expiredTime = null;
private Date endTime = null;
private String completionStrategy = null;
private IProcessInstance processInsatnce = null;
// private Set workItems = new HashSet(0);
private String taskType = null;
protected RuntimeContext rtCtx = null;
protected IWorkflowSession workflowSession = null;
public void setRuntimeContext(RuntimeContext ctx){
this.rtCtx = ctx;
}
public RuntimeContext getRuntimeContext(){
return this.rtCtx;
}
public String getTaskType() {
return taskType;
}
public void setTaskType(String taskType) {
this.taskType = taskType;
}
public TaskInstance() {
}
public TaskInstance(ProcessInstance workflowProcessInsatnce) {
this.processInsatnce = workflowProcessInsatnce;
}
// public TaskInstance(String taskId, String activityId, String name,
// String displayName, Integer state, Date createdTime, Date startedTime,
// Date expiredTime, Date endTime, Boolean asignToEveryone,
// ProcessInstance workflowProcessInsatnceId, Set workItems) {
// this.taskId = taskId;
// this.activityId = activityId;
// this.name = name;
// this.label = displayName;
// this.state = state;
// this.createdTime = createdTime;
// this.startedTime = startedTime;
// this.expiredTime = expiredTime;
// this.endTime = endTime;
// this.asignToEveryone = asignToEveryone;
// this.processInsatnce = workflowProcessInsatnceId;
// this.workItems = workItems;
// }
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getTaskId() {
return this.taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getActivityId() {
return this.activityId;
}
public void setActivityId(String activityId) {
this.activityId = activityId;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getDisplayName() {
return this.displayName;
}
public void setDisplayName(String label) {
this.displayName = label;
}
public Integer getState() {
return this.state;
}
public void setState(Integer state) {
this.state = state;
}
public Date getCreatedTime() {
return this.createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
public Date getStartedTime() {
return this.startedTime;
}
public void setStartedTime(Date startedTime) {
this.startedTime = startedTime;
}
public Date getExpiredTime() {
return this.expiredTime;
}
public void setExpiredTime(Date expiredTime) {
this.expiredTime = expiredTime;
}
public Date getEndTime() {
return this.endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public String getAssignmentStrategy() {
return completionStrategy;
}
public void setAssignmentStrategy(String completionStrategy) {
this.completionStrategy = completionStrategy;
}
public IProcessInstance getProcessInstance() {
if (this.processInsatnce!=null){
((IRuntimeContextAware)this.processInsatnce).setRuntimeContext(rtCtx);
}
return this.processInsatnce;
}
public void setProcessInstance(
IProcessInstance processInsatnce) {
this.processInsatnce = processInsatnce;
}
// public Set getWorkItems() {
// return this.workItems;
// }
//
// public void setWorkItems(Set workItems) {
// this.workItems = workItems;
// }
public void asignToActor(String id) throws EngineException,KenelException{
this.asignToActor(id, true);
}
public void asignToActors(List<String> ids) throws EngineException,KenelException{
//task应该有一个标志(asignToEveryone),表明asign的规则
for (int i = 0; ids != null && i < ids.size(); i++) {
createWorkItem(ids.get(i));
}
}
protected IWorkItem createWorkItem(String actorId) throws EngineException{
IPersistenceService persistenceService = rtCtx.getPersistenceService();
WorkItem wi = new WorkItem();
wi.setTaskInstance(this);
wi.setActorId(actorId);
wi.setState(IWorkItem.INITIALIZED);
wi.setCreatedTime(rtCtx.getCalendarService().getSysDate());
wi.setRuntimeContext(rtCtx);
persistenceService.saveOrUpdateWorkItem(wi);
return wi;
// this.getWorkItems().add(wi);
// wi.setAsignToEveryone(asignToEveryone);
//保存到数据库
}
public void complete()throws EngineException, KenelException {
complete(null);
}
public void complete(IActivityInstance targetActivityInstance) throws EngineException, KenelException {
IPersistenceService persistenceService = rtCtx.getPersistenceService();
//第一步,首先结束当前taskInstance
List<IWorkItem> workItemsList = persistenceService.findWorkItemsForTaskInstance(this.getId());
boolean taskInstanceCanBeCompleted = true;
for (int i = 0; workItemsList != null && i < workItemsList.size(); i++) {
IWorkItem wi = workItemsList.get(i);
if (wi.getState().intValue() == IWorkItem.INITIALIZED || wi.getState().intValue() == IWorkItem.STARTED) {
taskInstanceCanBeCompleted = false;
break;
}
}
if (!taskInstanceCanBeCompleted) {
return;
}
this.setState(ITaskInstance.COMPLETED);
this.setEndTime(rtCtx.getCalendarService().getSysDate());
persistenceService.saveOrUpdateTaskInstance(this);
//触发相应的事件
TaskInstanceEvent e = new TaskInstanceEvent();
e.setEventType(TaskInstanceEvent.AFTER_TASK_INSTANCE_COMPLETE);
this.fireTaskInstanceEvent(e);
//第二步,尝试结束对应的activityInstance
List<IToken> tokens = persistenceService.findTokensForProcessInstance(this.getProcessInstance().getId(), this.getActivityId());
System.out.println("====Inside TaskInstance.complete():: " + (tokens == null ? "tokens is null" : ("tokens size is " + tokens.size())));
if (tokens == null || tokens.size() == 0) {
return;//表明activityInstance已经结束了。
}
if (tokens.size() > 1) {
throw new EngineException("与activityId=" + this.getActivityId() + "对应的token数量(=" + tokens.size() + ")不正确,正确值能为1,因此无法完成complete操作");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?