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

📄 wfrunner.java

📁 OBPM是一个开源
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package cn.myapps.core.workflow.engine;

import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;

import org.apache.bsf.BSFManager;

import cn.myapps.core.workflow.element.Element;
import cn.myapps.core.workflow.element.FlowDiagram;
import cn.myapps.core.workflow.element.Node;
import cn.myapps.core.workflow.element.Relation;
import cn.myapps.core.workflow.utility.Factory;

public class WFRunner {
  private static BSFManager BSF_MANAGER = new BSFManager();
//  public static final int FLOWSTATUS_OPEN_NOSTART = 0x00000001;
//  public static final int FLOWSTATUS_OPEN_START = 0x00000010;
//  public static final int FLOWSTATUS_OPEN_RUN_RUNNING = 0x00000100;
//  public static final int FLOWSTATUS_OPEN_RUN_SUSPEND = 0x00001000;
//  public static final int FLOWSTATUS_CLOSE_ABORT = 0x00010000;
//  public static final int FLOWSTATUS_CLOSE_COMPLETE = 0x00100000;
//  public static final int FLOWSTATUS_CLOSE_TERMINAT = 0x01000000;
//  public static final int FLOWSTATUS_OPEN_RUN_BACK =  0x10000000;

//  public static final String START = "start";
//  public static final String PASS = "pass";
//  public static final String SUSPEND = "suspend";
//  public static final String ABORT = "abort";
//  public static final String COMPLETE = "complete";
//  public static final String TERMINATE = "terminate";
//  public static final String BACK = "back";

//  public static final String START2RUNNING     = "1";
//  public static final String START2TERMINATE   = "2";
//  public static final String SUSPEND2RUNNING   = "3";
//  public static final String RUNNING2SUSPEND   = "4";
//  public static final String SUSPEND2ABORT     = "5";
//  public static final String RUNNING2COMPLETE  = "6";
//  public static final String RUNNING2TERMIATE  = "7";
//  public static final String RUNNING2RUNNING_NEXT   = "80";
//  public static final String RUNNING2RUNNING_BACK   = "81";
//  public static final String RUNNING2RUNNING_SELF   = "82";
//  public static final String SUSPEND2SUSPEND   = "9";

  private FlowDiagram flowDiagram = null;

  public WFRunner(String xml) {
    this.flowDiagram = Factory.trnsXML2Dgrm(xml);
    
  }

  public WFRunner(File f) {
    this.flowDiagram = Factory.trnsXML2Dgrm(f);
  }

//  public void setFlowDiagram(String xml) {
//    fd = Factory.trnsXML2Dgrm(xml);
//  }
//  public void setFlowDiagram(File f) {
//    fd = Factory.trnsXML2Dgrm(f);
//  }
  /**
   * 设置流程状态
   *
   * @param
   */
  public void setFlowstatus(int status) throws Exception {
    flowDiagram.setFlowstatus(status);
  }

  public int getFlowstatus() throws Exception {
    return flowDiagram.getFlowstatus();
  }
  /**
   * 设置流程运转路径
   *
   * @param
   */
  public void setFlowpath(String path) {
    flowDiagram.setFlowpath(path) ;
  }

  /**
   * 获取流程运转路径
   *
   * @param
   */
  public Collection getFlowpath(){
    return flowDiagram.getFlowpath();
  }

  /**
   * 获取流程运转路径最后审核结点
   *
   * @param
   */
  public Node getFlowpathLastNode(){
      return flowDiagram.getFlowpathLastNode();
  }
  
  /**
   * 获取当前用户可处理的第一个当前结点
   */
  /*public Node getCurrentNode(WebUser webUser){
      return fd.getCurrentNode(webUser);
  }*/
  /**
   * 获取所有当前结点
   */
  /*public Vector getAllCurrentNode(){
      return fd.getAllCurrentNode();
  }*/

  /**
   * 获取所有当前结点的realnamelist
   */
  /*public String getAllCurrNdRealNameList(boolean onlyId){
      return fd.getAllCurrNdRealNameList(onlyId);
  }*/
  
  /**
   * 获取流程的第一个结点
   *
   * @param
   */
  public Node getFirstNode() {
	  return flowDiagram.getFirstNode();
  }
  
  /**
   * 获取当前结点的所有符合条件的下一个Node节点
   *
   * @param
   */
  public Vector getNextNodeByCndtn(Node nd) {
      Vector rs = new Vector();
      Vector all = getNodeNextRelation(nd);
      Iterator iter = all.iterator();
      while (iter.hasNext()) {
        Relation r = (Relation) iter.next();
        Node nextNode = getNextNode(r);
        if (nextNode != null && isCondition(r.condition)) {
            rs.add(nextNode);
        }
      }
      return rs;
  }
  /**
   * 获取当前结点的所有下一个Relation即步骤
   *
   * @param
   */
  public Vector getNodeNextRelation(Node nd) {
    return flowDiagram.getNodeNextRelation(nd);
  }

  /**
   * 根据当前relation获取下一结点
   *
   * @param
   */
  public Node getNextNode(Relation r) {
    return flowDiagram.getNextNode(r);
  }
  
  /**
   * 根据当前relation获取上一结点
   *
   * @param
   */
  /*public Node getBeforeNode(Node nd) {
      return fd.getBeforeNode(nd);
  }*/

  /**
   * 将结点设为当前结点
   *
   * @param
   */
  public void setCurrentNode(Node current) {
    flowDiagram.setCurrentNode(current);
  }
 
  public static void declareBean(String key, Object obj) {
    try {
      BSF_MANAGER.declareBean(key, obj, obj.getClass());
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    ;
  }

  public Element getElementByID(String id) {
    return flowDiagram.getElementByID(id);
  }
  /**
   * 获取流程流转Relation
   *
   * @param
   */
  public Element getElementByEndNodeID(String beginid, String endid) {
      return flowDiagram.getElementByBeginEndNodeID(beginid, endid);
  }
  public static void registerBean(String key, Object obj) {
    try {
      BSF_MANAGER.registerBean(key, obj);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    ;
  }

  public boolean isCondition(String js) {
    boolean istrue = true;
    Object result = null;
    if (js != null && js.trim().length() > 0) {
      try {
//        TestVO tv = new TestVO();
//        tv.setName("good morning!");
//
//        declareBean("$DOC", tv);
        System.out.println("js-->" + js);
        result = BSF_MANAGER.eval("javascript", "tt", 0, 0, js);
        if (result instanceof Boolean) {
          istrue = ( (Boolean) result).booleanValue();
        }
      }
      catch (Exception em) {
        em.printStackTrace();
        System.out.println("mgr eval javascript error!");
      }
    }
    return istrue;
  }

  public Object runJavascript(String js) {
    Object result = null;
    if (js != null && js.trim().length() > 0) {
      try {
        result = BSF_MANAGER.eval("javascript", "tt", 0, 0, js);
        System.out.println("result-->" + result);
      }
      catch (Exception em) {
        em.printStackTrace();
        System.out.println("mgr exec javascript error!");
      }
    }
    return result;
  }

  public Object runJavascript(Object util, String js) throws Exception{
    Object result = null;
    if (util != null && js != null && js.trim().length() > 0) {
      try {
        BSF_MANAGER.declareBean("$JSUTIL", util, util.getClass());
        result = BSF_MANAGER.eval("javascript", "tt", 0, 0, js);
        System.out.println("result-->" + result);
      }
      catch (Exception em) {
        em.printStackTrace();
        System.out.println("mgr exec javascript error!");
      }
    }
    return result;
  }

  public boolean isCondition(Object util, String js) throws Exception{
    boolean istrue = true;
    Object result = null;

⌨️ 快捷键说明

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