吐泡泡的龙

我的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 泡泡龙龙 阅读(1659) 评论(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年10月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(6)

我参与的团队

随笔档案

文章分类

文章档案

相册

搜索

最新评论

阅读排行榜

评论排行榜