`

JBPM4根据JPDL字符串部署流程

    博客分类:
  • jbpm
阅读更多

JBPM4对流程定义的部署的所有方式如下:

package org.jbpm.api;

import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.zip.ZipInputStream;

/** extends a {@link Deployment} with method for creating a new 
 * deployment.
 * 
 * @see RepositoryService#createDeployment()
 * 
 * @author Tom Baeyens
 */
public interface NewDeployment extends Deployment {

  /** typically correspond to the file name or url or some other 
   * form of identifying the source archive file for this deployment. */
  NewDeployment setName(String name);
  
  /** the timestamp can optionally be given and represents the last updated timestamp 
   * of the archive file that is being deployed. 
   * JBoss deployer makes use of this to remember if a file is already deployed or not.*/
  NewDeployment setTimestamp(long timestamp);
  
  /** adds a resource as a string */
  NewDeployment addResourceFromString(String resourceName, String string);

  /** adds a resource as a string */
  NewDeployment addResourceFromInputStream(String resourceName, InputStream inputStream);
  
  /** adds a resource as a resource from the classpath */
  NewDeployment addResourceFromClasspath(String resourceName);
  
  /** adds a resource as a url */
  NewDeployment addResourceFromUrl(URL url);
  
  /** adds a resource as a zip stream */
  NewDeployment addResourcesFromZipInputStream(ZipInputStream zipInputStream);

  /** adds a resource from a file */
  NewDeployment addResourceFromFile(File file);
  
  /** after adding resources, this will perform the actual deployment.
   * @return the generated deploymentId identification for this deployment
   * in the {@link RepositoryService repository}. */
  String deploy();

}

 

 

       但我在使用NewDeployment addResourceFromString(String resourceName, String string);来部署时却在表jbpm4_deployprop中没有数据并且JBPM也不提示部署有错,经查看其源代码才明白是怎么回事。

       我部署的代码是这样写的:

repositoryService.createDeployment().addResourceFromString("process",getJpdlAsString().deploy()

   问题就出在参数resourceName:process上,JBPM部署时会判断resourceName是否以“.jpdl.xml“作为后缀,如果是,JBPM才会解析第二个参数为流程定义,否则不做处理。所以在jbpm4_deployprop就不会有数据了。JBPM相关源码在ProcessDeployer.java中如下:

  @SuppressWarnings("unchecked")
  public void deploy(DeploymentImpl deployment) {
    
    for (String resourceName: deployment.getResourceNames()) {
      
      if (resourceName.endsWith(extension)) {
        byte[] bytes = deployment.getBytes(resourceName);
        InputStream inputStream = new ByteArrayInputStream(bytes);
        Parse parse = parser.createParse();
        parse.contextMapPut(Parse.CONTEXT_KEY_DEPLOYMENT, deployment);
        parse.setProblems(deployment.getProblems());
        parse.setInputStream(inputStream);
        parse.execute();
        List<ProcessDefinitionImpl> processDefinitions = (List<ProcessDefinitionImpl>) parse.getDocumentObject();
        if (processDefinitions!=null) {
          for (ProcessDefinitionImpl processDefinition : processDefinitions) {
            if ((processDefinition != null) && (processDefinition.getName() != null)) {
              String processDefinitionName = processDefinition.getName();

              processDefinition.setSuspended(deployment.isSuspended());

              String imageResourceName = resourceName.substring(0, resourceName.lastIndexOf(extension)) + ".png";
              if (deployment.getResourceNames().contains(imageResourceName)) {
                processDefinition.setImageResourceName(imageResourceName);
              }

              processDefinition.setDeploymentDbid(deployment.getDbid());

              if (deployment.hasObjectProperties(processDefinitionName)) {
                String key = deployment.getProcessDefinitionKey(processDefinitionName);
                String id = deployment.getProcessDefinitionId(processDefinitionName);
                Long version = deployment.getProcessDefinitionVersion(processDefinitionName);
                processDefinition.setId(id);
                processDefinition.setKey(key);
                processDefinition.setVersion(version.intValue());
            
              } else {
                checkKey(processDefinition, deployment);
                checkVersion(processDefinition, deployment);
                checkId(processDefinition, deployment);

                deployment.setProcessDefinitionId(processDefinitionName, processDefinition.getId());
                deployment.setProcessDefinitionKey(processDefinitionName, processDefinition.getKey());
                deployment.setProcessDefinitionVersion(processDefinitionName, new Long(processDefinition.getVersion()));
                
                //execute migration
                Map<ProcessDefinition, MigrationDescriptor> migrations = (Map<ProcessDefinition, MigrationDescriptor>)parse.contextMapGet(Parse.CONTEXT_KEY_MIGRATIONS);
                if (migrations != null) {
                  MigrationDescriptor migrationDescriptor = migrations.get(processDefinition);
                  if (migrationDescriptor != null) {
                    InstanceMigrator.migrateAll(processDefinition, migrationDescriptor);
                  }
                }
                
              }

              deployment.addObject(processDefinitionName, processDefinition);
            }
          }
        }
      }
    }
  }
  

    所以我最终把 "process"改为"process.jpdl.xml"就OK了!

分享到:
评论

相关推荐

    jbpm-jpdl-suite-3.2.3安装配置.doc

    4. **jbpm-jpdl-suite-3.2.3部署**: - 在MySQL中执行修改后的jbpm.jpdl.mysql.sql脚本,初始化jbpm所需的表结构。 - 配置jbpm的数据库连接信息,通常是在jbpm的配置文件中(如jbpm-config.xml或相关的JNDI配置)...

    J2EE OA 框架JBPM开发步骤

    JBPM提供了完整的业务流程管理功能,支持图形化的设计工具、流程定义语言JPDL(JBPM Process Definition Language),以及灵活的任务管理和流程实例执行等功能。本文将详细介绍JBPM的开发步骤,包括环境搭建、流程...

    JBPM web 设计器

    3. **多格式日期解析**:工具支持自动解析不同格式的日期字符串,增强了对数据处理的灵活性。 4. **属性配置**:用户可以方便地为每个节点和流程转换配置属性,并实时看到这些更改在图形表示上的反映。 5. **XML...

    jBPM4.3简略深入 了解(一)

    - `addResourceFromString(String resourceName, String string)`:通过字符串添加资源。 - `addResourceFromInputStream(String resourceName, InputStream inputStream)`:通过输入流添加资源。 - `...

    JBMP在MyEclipse中应用(1)

    //仓库服务中创建部署,添加xml格式字符串部署资源,部署该资源 super.getRepositoryService().createDeployment() .addResourceFromString("process.jpdl.xml", xml).deploy(); this.process(request,...

Global site tag (gtag.js) - Google Analytics