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了!