private static Map<Transition, String> TRANSION_TARGETS = new HashMap<Transition, String>();
@Override
public ProcessDefinition parseXML(Document document) {
TRANSION_TARGETS.clear();
ProcessDefinition definition = create(document.getDocumentElement(), null);
NodeList swimlanes = document.getElementsByTagName(SWIMLANE_NODE);
for (int i = 0; i < swimlanes.getLength(); i++) {
Node node = swimlanes.item(i);
create(node, definition);
}
NodeList startStates = document.getElementsByTagName(START_STATE_NODE);
if (startStates.getLength() == 1) {
Node node = startStates.item(0);
StartState startState = create(node, definition);
String swimlaneName = getAttribute(node, SWIMLANE_NODE);
Swimlane swimlane = definition.getSwimlaneByName(swimlaneName);
startState.setSwimlane(swimlane);
}
NodeList states = document.getElementsByTagName(STATE_NODE);
for (int i = 0; i < states.getLength(); i++) {
Node node = states.item(i);
NodeList nodeList = node.getChildNodes();
int transitionsCount = 0;
boolean hasTimeOutTransition = false;
for (int j = 0; j < nodeList.getLength(); j++) {
Node childNode = nodeList.item(j);
if (TRANSITION_NODE.equals(childNode.getNodeName())) {
String transitionName = getAttribute(childNode, NAME_ATTR);
if (PluginConstants.TIMER_TRANSITION_NAME.equals(transitionName)) {
hasTimeOutTransition = true;
}
transitionsCount++;
}
}
GraphElement state;
if (transitionsCount == 1 && hasTimeOutTransition) {
state = create(node, definition, "waitState");
} else {
state = create(node, definition);
}
for (int j = 0; j < nodeList.getLength(); j++) {
Node childNode = nodeList.item(j);
if (ASSIGNMENT_NODE.equals(childNode.getNodeName()) && state instanceof TimerState) {
String swimlaneName = getAttribute(childNode, SWIMLANE_NODE);
Swimlane swimlane = definition.getSwimlaneByName(swimlaneName);
((TimerState) state).setSwimlane(swimlane);
String assignmentType = getAttribute(childNode, ASSIGNMENT_NODE);
((TimerState) state).setReassignmentEnabled(assignmentType != null && "reassign".equals(assignmentType));
}
if (TIMER_NODE.equals(childNode.getNodeName())) {
((ITimed) state).setDueDate(getAttribute(childNode, DUEDATE_ATTR));
}
}
}
NodeList forks = document.getElementsByTagName(FORK_NODE);
for (int i = 0; i < forks.getLength(); i++) {
Node node = forks.item(i);
create(node, definition);
}
NodeList joins = document.getElementsByTagName(JOIN_NODE);
for (int i = 0; i < joins.getLength(); i++) {
Node node = joins.item(i);
create(node, definition);
}
NodeList decisions = document.getElementsByTagName(DECISION_NODE);
for (int i = 0; i < decisions.getLength(); i++) {
Node node = decisions.item(i);
create(node, definition);
}
NodeList processStates = document.getElementsByTagName(PROCESS_STATE_NODE);
for (int i = 0; i < processStates.getLength(); i++) {
Node node = processStates.item(i);
Subprocess subprocess = create(node, definition);
List<VariableMapping> variablesList = new ArrayList<VariableMapping>();
NodeList nodeList = node.getChildNodes();
for (int j = 0; j < nodeList.getLength(); j++) {
Node childNode = nodeList.item(j);
if (SUB_PROCESS_NODE.equals(childNode.getNodeName())) {
subprocess.setSubProcessName(getAttribute(childNode, NAME_ATTR));
}
if (VARIABLE_NODE.equals(childNode.getNodeName())) {
VariableMapping variable = new VariableMapping();
variable.setProcessVariable(getAttribute(childNode, NAME_ATTR));
variable.setSubprocessVariable(getAttribute(childNode, MAPPED_NAME_ATTR));
variable.setUsage(getAttribute(childNode, ACCESS_ATTR));
variablesList.add(variable);
}
}
subprocess.setVariablesList(variablesList);
}
NodeList endStates = document.getElementsByTagName(END_STATE_NODE);
for (int i = 0; i < endStates.getLength(); i++) {
Node node = endStates.item(i);
create(node, definition);
}
List<Transition> tmpTransitions = new ArrayList<Transition>(TRANSION_TARGETS.keySet());
for (Transition transition : tmpTransitions) {
String targetName = TRANSION_TARGETS.remove(transition);
org.jbpm.ui.common.model.Node target = definition.getNodeByNameNotNull(targetName);
transition.setTarget(target);
}
return definition;
}