windchill 中根據持久化對象獲取相關聯的流程_不包含子流程版

public static WfProcess getRelatedProcess(Persistable obj)
			throws RemoteException, InvocationTargetException, WTException {
		if (!RemoteMethodServer.ServerFlag) {
			String method = "getRelatedProcess";
			Class[] types = { Persistable.class };
			Object[] vals = { obj };
			return (WfProcess) RemoteMethodServer.getDefault().invoke(method, CLASSNAME, null, types, vals);
		}
		WfProcess process = null;
		QueryResult qrProcs = null;
		qrProcs = WfEngineHelper.service.getAssociatedProcesses(obj, null, null);
		// 按時間排序,取最新一個流程實例
		CollationKeyFactory timeKeyFact = new CollationKeyFactory() {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");

			public String getCollationString(Object o) {
				if (!(o instanceof Persistable) || !PersistenceHelper.isPersistent(o))
					return "";
				return sdf.format(PersistenceHelper.getModifyStamp((Persistable) o));
			}
		};
		Enumeration enProcs = new SortedEnumeration(qrProcs, timeKeyFact, SortedEnumeration.DESCENDING);
		while (enProcs.hasMoreElements()) {
			process = (WfProcess) enProcs.nextElement();
			// 最新的非子進程(子進程的名稱帶有$符號
			if (process.getName().indexOf("$") == -1) {
				logger.debug(" getRelatedProcess process=" + process.getName() + "  oid=" + process);
				break;
			}
		}
		return process;
	}
	//這裏順便提一下QueryResult
	//推薦用法:
	QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);
	
	//過時API:
	QueryResult qr = PersistenceHelper.manager.find(qs);
	
	//區別:自行研究,哈哈
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章