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

📄 flowdiagram.java

📁 OBPM是一个开源
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 */
	public void paint(Graphics g) {
		update(g);
	}

	/**
	 * @param e
	 * @roseuid 3E0A6E1B0079
	 */

	public void appendElement(Element e) {
		_elems.addElement(e);
	}

	public String toXML() {
		String rslt = "";
		try {

			Class cls = this.getClass();

			rslt = "<" + cls.getName() + ">\n";

			Field[] flds = cls.getFields();

			for (int i = 0; i < flds.length; i++) {
				Field field = flds[i];
				String fieldval = "";

				Class type = field.getType();

				if (field != null) {
					if (type.equals(Long.TYPE)) { // Long
						fieldval = field.getLong(this) + "";
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					} else if (type.equals(Integer.TYPE)) { // Int
						fieldval = field.getInt(this) + "";
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					} else if (type.equals(Short.TYPE)) { // Short
						fieldval = field.getShort(this) + "";
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					} else if (type.equals(Double.TYPE)) { // Double
						fieldval = field.getDouble(this) + "";
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					} else if (type.equals(Class.forName("java.lang.String"))) { // String
						fieldval = (String) field.get(this);
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					}

					else if (type.equals(Float.TYPE)) { // Float
						fieldval = field.getFloat(this) + "";
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					}

					else if (type.equals(Boolean.TYPE)) { // Boolean
						fieldval = field.getBoolean(this) + "";
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					}

					else if (type.equals(Class.forName("java.sql.Date"))) { // Date
						fieldval = field.get(this) + "";
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					}

					else if (type.equals(Class.forName("java.util.Date"))) { // java.util.Date
						fieldval = field.get(this) + "";
						rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
								+ flds[i].getName() + ">\n";
						continue;
					}
				}
			}
			// rslt += ">\n";

			// 递归调用SUBELEMENT的TOXML方法
			for (java.util.Enumeration em = this._elems.elements(); em
					.hasMoreElements();) {
				Element subelm = (Element) em.nextElement();
				rslt += subelm.toXML();
			}

			rslt += "</" + cls.getName() + ">\n";
		} catch (Exception e) {

		}

		return rslt;

	}

	/**
	 * @param e
	 * @roseuid 3E0A6E1B0097
	 */
	public void removeElement(Element emn) {
		if (emn != null) {
			if (emn instanceof Node) {
				Vector v = getAllElements();
				for (Enumeration e = v.elements(); e.hasMoreElements();) {
					Element elem = (Element) e.nextElement();
					if (elem instanceof Relation) {
						Relation r = (Relation) elem;
						if ((r.startnodeid != null && r.startnodeid
								.equals(emn.id))
								|| (r.endnodeid != null && r.endnodeid
										.equals(emn.id))) {
							_elems.removeElement(r);
						}
					}
				}
				_elems.removeElement(emn);
			} else {
				// Relation r = (Relation) emn;
				// r.getStartnode().removeSubElement(r.id);
				_elems.removeElement(emn);
			}
		}
	}

	/**
	 * @param id
	 * @roseuid 3E0A6E1B00AB
	 */
	public void removeElement(String id) {
		for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
			Element em = (Element) e.nextElement();

			if (em.id != null && em.id.equals(id)) {
				_elems.removeElement(em);
			}

		}
	}

	/**
	 * @param x
	 * @param y
	 * @return cn.myapps.core.workflow.Element
	 * @roseuid 3E0A6E1B00C9
	 */
	public PaintElement chkSelectedElement(int x, int y) {
		Vector v = getAllElements();
		for (Enumeration e = v.elements(); e.hasMoreElements();) {
			Object te = e.nextElement();
			if (te instanceof PaintElement) {
				PaintElement em = (PaintElement) te;
				if (em.isSelected(x, y)) {
					return em;
				}

			}
		}
		return null;
	}

	public int getFlowstatus() {
		return this.flowstatus;
	}

	/**
	 * 设置流程运转路径
	 * 
	 * @param
	 */
	public void setFlowpath(String path) {
		if (this.flowpath == null || this.flowpath.trim().length() <= 0) {
			this.flowpath = path;
		} else {
			this.flowpath = this.flowpath + ";" + path;
		}
	}

	/**
	 * 获取流程运转路径
	 * 
	 * @param
	 */
	public Collection getFlowpath() {
		Collection colls = new ArrayList();
		if (flowpath != null && flowpath.trim().length() > 0) {
			String[] path = CommonUtil.split(this.flowpath, ';');
			for (int i = 0; i < path.length; i++) {
				String[] t = CommonUtil.split(path[i], ',');
				colls.add(t);
			}
		}
		return colls;
	}

	/**
	 * 获取流程运转路径最后审核结点
	 * 
	 * @param
	 */
	public Node getFlowpathLastNode() {
		Collection colls = getFlowpath();
		Object[] obj = colls.toArray();
		String nodeid = "";
		Node node = null;
		if (obj.length >= 1) {
			String[] path = (String[]) obj[obj.length - 1];
			nodeid = path[0];
		}
		if (nodeid != null && nodeid.trim().length() > 0) {
			node = (Node) getElementByID(nodeid);
		}
		return node;
	}

	/**
	 * 设置流程状态
	 * 
	 * @param
	 */
	public void setFlowstatus(int status) throws Exception {
		// if (this.flowstatus == FLOWSTATUS_OPEN_NOSTART &&
		// ( (status & FLOWSTATUS_OPEN_START) > 0)) {
		// this.flowstatus = status;
		// Node n = getFirstNode(); //设起始点
		// setCurrentNode(n);
		// }
		// else
		if (this.flowstatus == FlowType.FLOWSTATUS_OPEN_NOSTART
				&& ((status & (FlowType.FLOWSTATUS_OPEN_RUN_RUNNING | FlowType.FLOWSTATUS_CLOSE_TERMINAT)) > 0)) {
			this.flowstatus = status;
		} else if (this.flowstatus == FlowType.FLOWSTATUS_OPEN_RUN_RUNNING
				&& ((status & (FlowType.FLOWSTATUS_OPEN_RUN_SUSPEND
						| FlowType.FLOWSTATUS_CLOSE_COMPLETE
						| FlowType.FLOWSTATUS_CLOSE_TERMINAT | FlowType.FLOWSTATUS_OPEN_RUN_RUNNING)) > 0)) {
			this.flowstatus = status;
		} else if (this.flowstatus == FlowType.FLOWSTATUS_OPEN_RUN_SUSPEND
				&& ((status & (FlowType.FLOWSTATUS_OPEN_RUN_RUNNING
						| FlowType.FLOWSTATUS_OPEN_RUN_SUSPEND | FlowType.FLOWSTATUS_CLOSE_ABORT)) > 0)) {
			this.flowstatus = status;
		} else {
			throw new Exception("Set flow status error");
		}
		// //保存流程流转路径
		// if (this.flowstatus == FLOWSTATUS_OPEN_START) {
		// setFlowpath(getCurrentNode().id + "," + START);
		// }else if (this.flowstatus == FLOWSTATUS_OPEN_RUN_RUNNING){
		// setFlowpath(getCurrentNode().id + "," + PASS);
		// }else if (this.flowstatus == FLOWSTATUS_OPEN_RUN_SUSPEND){
		// setFlowpath(getCurrentNode().id + "," + SUSPEND);
		// }else if (this.flowstatus == FLOWSTATUS_CLOSE_TERMINAT){
		// setFlowpath(getCurrentNode().id + "," + TERMINATE);
		// }else if (this.flowstatus == FLOWSTATUS_CLOSE_ABORT){
		// setFlowpath(getCurrentNode().id + "," + ABORT);
		// }else if (this.flowstatus == FLOWSTATUS_CLOSE_COMPLETE){
		// setFlowpath(getCurrentNode().id + "," + COMPLETE);
		// }
	}

	/**
	 * 获取当前结点
	 * 
	 * @param
	 */
	public Node getFirstCurrentNode() {
		Vector ems = getAllElements();
		Enumeration enum1 = ems.elements();
		while (enum1.hasMoreElements()) {
			Element item = (Element) enum1.nextElement();
			if (item instanceof Node) {
				Node nd = (Node) item;
				if (nd._iscurrent) {
					return nd;
				}
			}
		}

		return null;
	}

	/**
	 * 获取流程的第一个结点
	 * 
	 * @param
	 */
	public Node getFirstNode() {
		Vector ems = getAllElements();
		Enumeration enum1 = ems.elements();
		while (enum1.hasMoreElements()) {
			Element item = (Element) enum1.nextElement();
			if (item instanceof Node) {
				Node nd = (Node) item;
				if (nd instanceof StartNode) {
					return nd;
				}
			}
		}
		return null;
	}

	/**
	 * 获取所有开始节点
	 * 
	 * @return
	 */
	public Collection getStartNodeList() {
		Vector ems = getAllElements();
		Enumeration enum1 = ems.elements();
		Collection colls = new ArrayList();
		while (enum1.hasMoreElements()) {
			Element item = (Element) enum1.nextElement();
			if (item instanceof Node) {
				Node nd = (Node) item;
				if (nd instanceof StartNode) {
					colls.add(nd);
				}
			}
		}
		return colls;
	}

	/**
	 * 获取当前结点的所有下一个Relation即步骤
	 * 
	 * @param
	 */
	public Vector getNodeNextRelation(Node nd) {
		if (nd == null) {
			return null;
		}
		Vector rv = new Vector();
		Enumeration enum1 = this._elems.elements();
		while (enum1.hasMoreElements()) {
			Object item = (Object) enum1.nextElement();
			if (item instanceof Relation) {
				Relation r = (Relation) item;
				if (r.startnodeid != null && r.startnodeid.equals(nd.id)) {
					rv.addElement(item);
				}
			}

		}
		return rv;
	}

	/**
	 * 获取当前结点的所有上一个Relation即步骤
	 * 
	 * @param
	 */
	public Vector getNodeBeforeRelation(Node nd, boolean ispassed) {
		if (nd == null) {
			return null;
		}
		Vector rv = new Vector();
		for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
			Element em = (Element) e.nextElement();
			if (em._subelems != null) {
				for (Enumeration sube = em._subelems.elements(); sube
						.hasMoreElements();) {
					Element subem = (Element) sube.nextElement();
					if (subem instanceof Relation) {
						Relation relation = (Relation) subem;
						if (relation.id != null
								&& relation.endnodeid.equals(nd.id)) {
							if (ispassed) {
								if (relation.ispassed) {
									rv.addElement(relation);
								}
							} else {
								rv.addElement(relation);
							}

						}
					}

				}
			}

		}

		return rv;
	}

	/**
	 * 根据当前relation获取下一结点
	 * 
	 * @param
	 * @throws Exception
	 */
	public Node getNextNode(Relation r) {
		Node end = null;
		JavaScriptRunner runner = JavaScriptRunner.getInstance();
		Boolean flag = new Boolean(true);

		String condition = r.condition;
		condition = StringUtil.dencodeHTML(condition);
		try {
			if (!(condition).equals("") && (condition) != null) {
				condition.replaceAll("\n", " ");
				Object obj = runner.run(condition);
				if (obj instanceof Boolean) {
					flag = (Boolean) obj;
				}
			}
		} catch (Exception e) {
			// e.printStackTrace();
		}

		if (flag.booleanValue()) {
			end = r.getEndnode();
		}

		return end;
	}

	/**
	 * 获取当前任一relation中上一结点
	 * 
	 * @param
	 */
	public Node getStartNode(Relation r) {
		Node end = r.getStartnode();
		return end;
	}

	/**
	 * 将结点设为当前结点
	 * 
	 * @param
	 */
	public void setCurrentNode(Node current) {
		if (current == null) {
			return;
		}
		// Vector ems = getAllElements();
		// Enumeration enum = ems.elements();
		// while (enum.hasMoreElements()) {
		// Element item = (Element) enum.nextElement();
		// if (item instanceof Node) {
		// Node nd = (Node) item;
		// if (nd.iscurrent) {
		// nd.iscurrent = false;
		// }
		// if (nd.id != null && current.id !=null && nd.id.equals(current.id)) {
		// nd.iscurrent = true;
		// }
		// }
		// }
		current._iscurrent = true;
	}

	/**
	 * @return java.util.Vector
	 * @roseuid 3E0A6E1B00E7
	 */
	public Vector getAllElements() {
		Vector vct = new Vector();
		for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
			Element em = (Element) e.nextElement();
			vct.addElement(em);

			if (em._subelems != null) {
				for (Enumeration sube = em._subelems.elements(); sube
						.hasMoreElements();) {
					vct.addElement(sube.nextElement());
				}
			}

		}
		return vct;
	}

	/**
	 * 根据开始节点和结束接点获取关系
	 * 
	 * @return
	 */
	public Relation getRelation(String startnodeid, String endnodeid) {
		Collection colls = this.getAllElements();
		for (Iterator iter = colls.iterator(); iter.hasNext();) {
			Object element = iter.next();
			if (element instanceof Relation) {
				Relation relation = (Relation) element;
				if (startnodeid.equals(relation.startnodeid)
						&& endnodeid.equals(relation.endnodeid)) {
					return relation;
				}
			}
		}
		return null;
	}

	public Object validate(String startnodeid, String endnodeid) {
		Relation relation = this.getRelation(startnodeid, endnodeid);
		if (relation != null) {
			String script = relation.validateScript;
			if (script != null && !script.equals("")) {
				try {
					JavaScriptRunner runner = JavaScriptRunner.getInstance();
					Object rtn = runner.run(script);
					return rtn;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}

	public Object runAction(String startnodeid, String endnodeid) {
		Relation relation = this.getRelation(startnodeid, endnodeid);
		if (relation != null) {

			String action = relation.action;
			if (action != null && action.trim().length() > 0) {
				action = StringUtil.dencodeHTML(action);
				try {
					JavaScriptRunner runner = JavaScriptRunner.getInstance();
					// runner.initBSFManager();
					Object rtn = runner.run(action);
					return rtn;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}

	/**
	 * @param id
	 * @return cn.myapps.core.workflow.Element
	 * @roseuid 3E0A6E1B00F1
	 */
	public Element getElementByID(String id) {

		if (id == null || id.trim().length() == 0) {
			return null;
		}

		for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
			Element em = (Element) e.nextElement();
			if (em.id != null && em.id.equals(id)) {
				return em;
			}
			if (em._subelems != null) {
				for (Enumeration sube = em._subelems.elements(); sube
						.hasMoreElements();) {
					Element subem = (Element) sube.nextElement();

					if (subem.id != null && subem.id.equals(id)) {
						return subem;
					}
				}

⌨️ 快捷键说明

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