根据ProcessEngine取得RepositoryService加载资源文件;
String deployId = processEngine.getRepositoryService().createDeployment() .addResourceFromClasspath("resources/jbpm/Appropriation.jpdl.xml").deploy();
该方法的执行流程如下:
1、调用DeploymentImpl类的deploy方法;
public String deploy() { return commandService.execute(new DeployCmd(this)); }
public String execute(Environment environment) throws Exception { RepositorySession repositorySession = environment.get(RepositorySession.class); return repositorySession.deploy(deployment); }
由于new DeployCmd(this)可知,deployment为DeploymentImpl的对象;
public String deploy(NewDeployment deployment) { DeploymentImpl deploymentImpl = (DeploymentImpl) deployment; long dbid = DbidGenerator.getDbidGenerator().getNextId(); deploymentImpl.setDbid(dbid); deploymentImpl.initResourceLobDbids(); session.save(deploymentImpl); // will also save the attached resources deployerManager.deploy(deploymentImpl); return deploymentImpl.getId(); }
public class DeploymentImpl extends ProblemList implements NewDeployment { private static final long serialVersionUID = 1L; public static final String KEY_PROCESS_LANGUAGE_ID = "langid"; public static final String KEY_PROCESS_DEFINITION_ID = "pdid"; public static final String KEY_PROCESS_DEFINITION_KEY = "pdkey"; public static final String KEY_PROCESS_DEFINITION_VERSION = "pdversion"; protected long dbid; protected String name; protected long timestamp; protected String state = Deployment.STATE_ACTIVE; protected Map<String, Lob> resources; protected CommandService commandService; protected Map<String, Object> objects; protected Set<DeploymentProperty> objectProperties;
public NewDeployment addResourceFromClasspath(String resourceName) { addResourceFromStreamInput(resourceName, new ResourceStreamInput(resourceName)); return this; }
public NewDeployment addResourceFromStreamInput(String name, StreamInput streamInput) { if (resources == null) { resources = new HashMap<String, Lob>(); } InputStream inputStream = streamInput.openStream(); try { byte[] bytes = IoUtil.readBytes(inputStream); // Since this method is probably called outside an environment block, we // need to generate the dbid of the Lob later (during the actual deployment). Lob lob = new Lob(bytes, false); resources.put(name, lob); } catch (IOException e) { throw new JbpmException("couldn't read from " + name, e); } finally { IoUtil.close(inputStream); } return this; }
主要再看 protected Set<DeploymentProperty> objectProperties;这个属性;
这个类很简单;
public class DeploymentProperty implements Serializable { private static final long serialVersionUID = 1L; long dbid; protected DeploymentImpl deployment; protected String objectName; protected String key; protected String stringValue; protected Long longValue; ...
资源文件xml的开头内容为
<process name="appcardJbpmFlow2" xmlns="http://jbpm.org/4.4/jpdl">