吐泡泡的龍

          我的Shark使用經驗(3)

          ????? 今天要介紹的是基于web的shark。不知道為什么字體都是斜體。索性不配圖了。本項目代碼部分源自Geeta Ramani的Struts in Shark。
          ????? 先來個How to:
          ????? 1.?在jbuilder 2006中新建一個web項目,包含struts最新版的庫。我起的名字叫TestingShark,路徑在
          D:\jproject\TestingShark。可別放中文目錄下,不然可能報錯。
          ????? 2.把你安裝好的shark打開,進入lib文件夾,找到里面所有shark開頭的jar文件,都復制到D:\jproject\TestingShark\TestingShark\WEB-INF\lib中。當然,你也可以把里面所有的jar文件都copy過去,里面好東西不少,commons,axis,xalan,jawe包應有盡有。不要考文件夾,只用考jar包。統計了
          一下shark開頭的有53項。不要忘記sqlserver的3個驅動文件。
          ??????3.開始寫代碼。Action~!
          ????? 按照昨天說的,shark要運行起來先要把package就是xpdl給load進來。如何在web上實現?
          先看看shark API中的org.enhydra.shark.api.client.wfservice 之Interface PackageAdministration。關于包的所有操作都有了。
          ???? StrustsinShark項目中建立了一個JSPAdminUtilities類,里面有一些封裝好的操作。
          package com.xxxx.shark.util.jsp;

          import java.io.File;
          import java.io.FileDescriptor;
          import java.io.FileNotFoundException;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.util.Iterator;
          import java.util.List;
          import java.util.Map;
          import java.util.Set;
          import java.util.Vector;

          import org.enhydra.shark.Shark;
          ......
          import org.enhydra.shark.api.client.wfservice.PackageAdministration;
          import org.enhydra.shark.api.client.wfservice.RepositoryMgr;
          ......
          方法 String??PackageLoad(String xpdlName)
          /**
          ? * 取得xpdl文件,xpdl文件必須在Shark服務端的Rs..external目錄下,不然就要輸入路徑。
          ? *
          ? * @param? xpdlName?????????? Description of the Parameter
          ? * @return??????????????????? Description of the Return Value
          ? * @exception? BaseException? Description of the Exception
          ? */
          ?public String packageLoad(String xpdlName) throws BaseException {
          //包實例化需要從shark.getInstance()進入,這步非常的重要。

          ??PackageAdministration pa = Shark.getInstance().getAdminInterface().getPackageAdministration();
          //為什么要用RepositoryMgr?因為要取得package?id 來驗證此包是否已經裝載過。
          ??RepositoryMgr rm = Shark.getInstance().getRepositoryManager();
          ??String pkgId = rm.getPackageId(xpdlName);
          //如果沒有裝載包,就下手吧。
          ??if (!pa.isPackageOpened(pkgId)) {
          ???try {
          ????pa.openPackage(xpdlName);
          ???}
          ???catch (Throwable e) {
          ????e.printStackTrace();
          ????throw new BaseException(e);
          ???}
          ??}
          ??return rm.getPackageId(xpdlName);
          ?}

          方法? boolean packageDownload(String pkgId, String completeFilePath)
          ?/**
          ???? * 從數據庫中下載XPDL文件到指定目錄(Table XPDLS and XPDLData)
          ???? * @param pkgId id of pkg you want to download
          ???? * @param completeFilePath where you want the file downloaded
          ???? * @throws BaseException, FileNotFoundException, IOException
          ???? */
          ?public boolean packageDownload(String pkgId, String completeFilePath) throws BaseException, FileNotFoundException, IOException {
          ??PackageAdministration pa = Shark.getInstance().getAdminInterface().getPackageAdministration();
          ???RepositoryMgr rm = Shark.getInstance().getRepositoryManager();
          ??//String pkgId = rm.getPackageId(xpdlName);
          ??//String pkgId = "WellnessDemo";
          ??String currVersion = pa.getCurrentPackageVersion(pkgId);
          ??byte[] contents = pa.getPackageContent(pkgId, currVersion);
          ??//FileOutputStream fos = new FileOutputStream("C:\\xpdls\\WellnessDemo.xpdl");
          ??FileOutputStream fos = new FileOutputStream(completeFilePath);
          ??fos.write(contents);
          ??//return "theXpdl";
          ??FileDescriptor theFd = fos.getFD();
          ??return true;
          ?}

          ???????????這段大家自己看看API理解吧。Shark的API是非常方便的。輸出使用FileOutputStream。這里
          在頁面上我是這樣寫的。把一些屬性放到map中然后做為request傳遞。早知道就用packageDownload了。
          ????????????? HashMap[] hm=(HashMap[])request.getAttribute("packages");
          ????????? for(int i=0;i<hm.length;i++)
          ?????????????????????????? {

          ?????????????????????? ??field_1=(String)hm[i].get("packageId");
          ??????????????????????? ?field_2=hm[i].get("isPackageOpened").toString();
          ??????????????????????????????????????? byte[] b= (byte[])hm[i].get("packageContent");
          ??????????????????????????????????????? FileOutputStream fs = new FileOutputStream("c:\\"+field_1+".xml");
          ??????????????????????????????????????? fs.write(b);
          ??????????????????????????????????????? fs.close();
          ????????????????????????????}
          ???????????? 做為xml保存,使用dom來修改,放棄jawe的swing界面,在頁面上修改流程。。。這是不得以而
          為之的辦法。
          ????? That's all for today~

          posted on 2006-09-20 21:16 泡泡龍龍 閱讀(1680) 評論(2)  編輯  收藏

          評論

          # re:有問題請指教 2006-10-09 14:15 菲cl

          我已經學習了在shark里面導入.xpdl文件,但是如何在jawe工具中生成.xpdl文件啊! 請幫幫忙.  回復  更多評論   

          # re: 我的Shark使用經驗(3)[未登錄] 2007-08-29 16:03 Eric

          hello, 我也是剛接觸工作流引擎shark的, 因為公司最近有個項目要用到這塊, 我里面有很多疑問和問題, 希望可以請教你有關的問題,我的qq:81598188
          MSN:zhyguyun0501@hotmail.com  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          導航

          統計

          常用鏈接

          留言簿(6)

          我參與的團隊

          隨筆檔案

          文章分類

          文章檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 印江| 且末县| 平利县| 芒康县| 察隅县| 卢氏县| 故城县| 建阳市| 贡觉县| 舒城县| 临桂县| 彭水| 武川县| 安阳市| 保靖县| 南宫市| 丰原市| 临安市| 农安县| 宁海县| 武平县| 大丰市| 麻阳| 雷波县| 当涂县| 尚志市| 乌鲁木齐县| 胶州市| 承德市| 桑植县| 柳江县| 崇文区| 八宿县| 绥滨县| 来宾市| 甘德县| 龙泉市| 浦北县| 卓尼县| 赤城县| 镇江市|