}
public Object parseDocumentElement(Element documentElement, Parse parse) {
List<ProcessDefinitionImpl> processDefinitions = new ArrayList<ProcessDefinitionImpl>();
JpdlProcessDefinition processDefinition = instantiateNewJpdlProcessDefinition();
processDefinitions.add(processDefinition);
parse.contextStackPush(processDefinition);
try {
// process attribues
String name = XmlUtil.attribute(documentElement, "name", true, parse);
processDefinition.setName(name);
// make the process language version available for bindings
// to allow for specific parsing behaviour per version
// first check if the langid is available as a deployment property
DeploymentImpl deployment = (DeploymentImpl) parse.contextMapGet(Parse.CONTEXT_KEY_DEPLOYMENT);
if (deployment!=null) {
String processLanguageId = deployment.getProcessLanguageId(name);
if (processLanguageId==null) {
// if it is not available as a deployment property, check if the
// jpdlparser attribute specifies a specific jpdl version.
// this is the case for certain compatibility tests in our test suite
String jpdlParser = XmlUtil.attribute(documentElement, "jpdlparser");
if (jpdlParser!=null) {
processLanguageId = "jpdl-"+jpdlParser;
} else {
// if none of the above, check if this is a parser test run for a specific verion
// specify the jpdltestversion with "mvn -Djpdlparser=jpdl-4.3 clean install"
// that way, the whole test suite will be use the specified parser
jpdlParser = System.getProperty("jpdlparser");
if (jpdlParser!=null) {
processLanguageId = "jpdl-"+jpdlParser;
} else {
// if this process has a namespace, then use the namespace
// to see what jpdl parser version should be used
String namespaceUri = documentElement.getNamespaceURI();
if (namespaceUri!=null) {
processLanguageId = "jpdl-"+namespaceUri.substring(16, 19);
} else {
// if none of the above, just deploy it as the current library version
processLanguageId = CURRENT_VERSION_PROCESS_LANGUAGE_ID;
}
}
}
// saving the process language will make sure that
// the right parser version is used after an upgrade of jbpm
// as the old format xml will still be in the db
deployment.setProcessLanguageId(name, processLanguageId);
}
parse.contextMapPut(Parse.CONTEXT_KEY_PROCESS_LANGUAGE_ID, processLanguageId);
}
String packageName = XmlUtil.attribute(documentElement, "package");
processDefinition.setPackageName(packageName);
Integer version = XmlUtil.attributeInteger(documentElement, "version", false, parse);
if (version!=null) {
processDefinition.setVersion(version);
}
String key = XmlUtil.attribute(documentElement, "key", false, parse);
if (key!=null) {
processDefinition.setKey(key);
}
Element descriptionElement = XmlUtil.element(documentElement, "description");
if (descriptionElement!=null) {
String description = XmlUtil.getContentText(descriptionElement);
processDefinition.setDescription(description);
}
UnresolvedTransitions unresolvedTransitions = new UnresolvedTransitions();
parse.contextStackPush(unresolvedTransitions);
// swimlanes
List<Element> swimlaneElements = XmlUtil.elements(documentElement, "swimlane");
for (Element swimlaneElement: swimlaneElements) {
String swimlaneName = XmlUtil.attribute(swimlaneElement, "name", true, parse);
if (swimlaneName!=null) {
SwimlaneDefinitionImpl swimlaneDefinition =
processDefinition.createSwimlaneDefinition(swimlaneName);
parseAssignmentAttributes(swimlaneElement, swimlaneDefinition, parse);
}
}
// on events
parseOnEvents(documentElement, parse, processDefinition);
// activities
parseActivities(documentElement, parse, processDefinition);
// bind activities to their destinations
resolveTransitionDestinations(parse, processDefinition, unresolvedTransitions);
// process migration information
Element migrationElement = XmlUtil.element(documentElement, "migrate-instances");
if (migrationElement != null) {
MigrationHelper.parseMigrationDescriptor(migrationElement, parse, processDefinition);
}
} finally {
parse.contextStackPop();
}
if (processDefinition.getInitial()==null) {
parse.addProblem("no start activity in process", documentElement);
}
return processDefinitions;
}