⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workflowengine.java

📁 一个工作流的原型
💻 JAVA
字号:
/* * WorkflowEngine.java * * Created on 2004年12月29日, 下午9:06 */package workflow.xwfbox.engine;import workflow.xwfbox.resource.*;import workflow.xwfbox.worklist.*;import workflow.xwfbox.instanceTable.*;import workflow.xwfbox.instance.*;import workflow.xwfbox.process.*;import java.util.Date;import java.util.Calendar;import java.util.Vector;import java.util.Iterator;/** * * @author  Administrator */public class WorkflowEngine {        String workItemId;    String processId;    String instanceId;    String packageLoc;    String instanceLoc;        /** Creates a new instance of WorkflowEngine */    public WorkflowEngine() {    }        public void informTaskFinish(String workItemId, String participantId, String participantType) {        this.workItemId = workItemId;        // Find participant worklist path        ResourceManager rm = new ResourceManager();        String worklistPath = rm.getWorkListPath(participantType);        // Get the participant worklist        WorkListManager wm = new WorkListManager(participantId, worklistPath);        Vector workItems = wm.getWorkItems();        WorkItem workItem = wm.getWorkItem(workItemId); //       String instanceId = workitem.getInstanceId();                // Submit the workitem, update workItem first        setFinishToWorkItem(wm, workItemId);        wm.update();        // Record the details of the task into the instance        // 在实例文件(Instance)中,标记任务        instanceId = workItem.getInstanceId();        InstanceTableManager itm = new InstanceTableManager();        processId = itm.getProcessId(instanceId);        packageLoc = itm.getPackageLocation(instanceId);        instanceLoc = itm.getInstanceLocation(instanceId);        InstanceManager im = new InstanceManager(instanceLoc);        setTaskFinish(im, workItem, participantId);                // Transform the state of the instance        // 取得当前活动得类型        TaskNode taskNode = im.getTaskNodeById(workItemId);        String taskNodeType = taskNode.getTaskType().getValue();        if (taskNodeType.equals("END")) {            // 过程实例结束处理                    } else {            // 任务处理            taskNode.setToken("2");            String activityId = taskNode.getActivityId();            Vector outActs = im.getOutgoingActivityIds(activityId);            if (outActs.size() == 1) {                // 线性路由处理                // 1.  标记Token状态		String toActId = (String)outActs.firstElement();                oneNextNodeProcess(im, taskNode, toActId, rm);                            } else {                workflow.xwfbox.instance.Split split = taskNode.getRestriction().getSplit();                if (split != null) {                    String splitType = split.getType();                    if (splitType.equals("XOR")) {                        String transitionId = getOneTransitionFromXOR(im, split);                        String toActId = im.getTransitionToId(transitionId);                        oneNextNodeProcess(im, taskNode, toActId, rm);                    } else if (splitType.equals("AND")) {                        Iterator it = outActs.iterator();                        while (it.hasNext()) {                            String toActId = (String) it.next();                            oneNextNodeProcess(im, taskNode, toActId, rm);                        }                    }                }            }        }        // push the following worklist for this instance        im.update();    }     private String getOneTransitionFromXOR(InstanceManager im, workflow.xwfbox.instance.Split split) {        String tranId = null;        String otherwise = null;        String noCond = null;        Vector refs = split.getTransitionRefs();        Iterator it = refs.iterator();        while (it.hasNext()) {            workflow.xwfbox.instance.TransitionRef ref = (workflow.xwfbox.instance.TransitionRef)it.next();            String transitionId = ref.getTransitionId();            String result = im.checkCondition(transitionId);            if (result.equals("TRUE")) {                tranId = transitionId; break;            } else if (result.equals("OTHERWISE")) {                otherwise = transitionId;            } else if (result.equals("NOCONDITION")) {                noCond = transitionId;            }        }        if (noCond != null) {            tranId = noCond;        } else if ((tranId == null)&&(otherwise != null)) {            tranId = otherwise;        } else {            // 目前没做考虑        }        return tranId;    }        private void setFinishToWorkItem(WorkListManager wm, String workItemId) {        wm.setWorkItemState(workItemId, "FINISH");        Calendar rightNow = Calendar.getInstance();        Date time = rightNow.getTime();        wm.setWorkItemFinishTime(workItemId, time);         //完成了对Worklist的标记    }        private void setTaskFinish(InstanceManager im, WorkItem workItem, String participantId) {        Task task = im.getTaskById(workItem.getTaskId());        task.setAssignee(participantId);        task.setCompleted(workItem.getFinished());        task.setStatus("FINISH");    }        private void oneNextNodeProcess(InstanceManager im,TaskNode taskNode, String toActId, ResourceManager rm) {        // 取得下一结点的JOIN类型        TaskNode toTaskNode = im.getTaskNodeByActivityId(toActId);        if (toTaskNode.getName().equals("End")) {            // 过程结束处理        } else {            String joinType = null;            Restriction rest =  toTaskNode.getRestriction();            if (rest != null) {                workflow.xwfbox.instance.Join join = rest.getJoin();                if (join != null) {                    joinType = join.getType();                }            }    //        joinType = toTaskNode.getRestriction().getJoin().getType();            boolean isProcessNext = true;            if ((joinType != null)&&(joinType.equals("AND"))) {                boolean bl = im.isFinishedForAllIncomingActivities(toTaskNode);                isProcessNext = bl;            }            if (!isProcessNext) {                toTaskNode.setToken("3");                im.update();            } else {                toTaskNode.setToken("1");                // 2. 记录下一任务                String toTaskId = toTaskNode.getId();        //                String toTaskName = toTaskNode.getName();                ProcessManager pm = new ProcessManager();                // 活动映象文件×××××××今后要有字典存放                String ActivityMapping = "file:///D:/xwfbox-v3/source/xml/mapping/ActivityMapping.xml";                pm.XMLMapping(ActivityMapping, packageLoc);                Activity toActivity = pm.getActivity(processId,toActId);                im.buildTask(toTaskId, toActivity);                im.update();                // 任务分配                String toParticipantId = (String)toActivity.getPerformer();                // 异常情况                if (toParticipantId == null) toParticipantId = "USER002";                // 1. 确定参与者Worklist文件                String type = rm.getParticipantType(toParticipantId);                String worklistPath = rm.getWorkListPath(type);                WorkListManager wm = new WorkListManager(toParticipantId, worklistPath);                wm.pushWorkItem(toTaskId, toActivity.getName(), instanceId);                wm.update();            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -