01: package org.jbpm.graph.node;
02:
03: import org.dom4j.Element;
04: import org.jbpm.JbpmContext;
05: import org.jbpm.graph.def.ProcessDefinition;
06: import org.jbpm.jpdl.JpdlException;
07:
08: public class DbSubProcessResolver implements SubProcessResolver {
09:
10: private static final long serialVersionUID = 1L;
11:
12: public ProcessDefinition findSubProcess(Element subProcessElement) {
13: ProcessDefinition subProcessDefinition = null;
14:
15: String subProcessName = subProcessElement
16: .attributeValue("name");
17: String subProcessVersion = subProcessElement
18: .attributeValue("version");
19:
20: // if this parsing is done in the context of a process deployment, there is
21: // a database connection to look up the subprocess.
22: // when there is no jbpmSession, the definition will be left null... the
23: // testcase can set it as appropriate.
24: JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
25: if (jbpmContext != null) {
26:
27: // now, we must be able to find the sub-process
28: if (subProcessName != null) {
29:
30: // if the name and the version are specified
31: if (subProcessVersion != null) {
32:
33: try {
34: int version = Integer
35: .parseInt(subProcessVersion);
36: // select that exact process definition as the subprocess definition
37: subProcessDefinition = jbpmContext
38: .getGraphSession()
39: .findProcessDefinition(subProcessName,
40: version);
41:
42: } catch (NumberFormatException e) {
43: throw new JpdlException(
44: "version in process-state was not a number: "
45: + subProcessElement.asXML());
46: }
47:
48: } else { // if only the name is specified
49: // select the latest version of that process as the subprocess
50: // definition
51: subProcessDefinition = jbpmContext
52: .getGraphSession()
53: .findLatestProcessDefinition(subProcessName);
54: }
55: } else {
56: throw new JpdlException(
57: "no sub-process name specfied in process-state: "
58: + subProcessElement.asXML());
59: }
60: }
61:
62: return subProcessDefinition;
63: }
64: }
|