in jbpm/jbpm-bpmn2/src/main/java/org/jbpm/bpmn2/xml/StartEventHandler.java [86:227]
protected Node handleNode(final Node node, final Element element, final String uri,
final String localName, final Parser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
StartNode startNode = (StartNode) node;
// TODO: StartEventHandler.handleNode(): the parser doesn't discriminate between the schema default and the actual set value
// However, while the schema says the "isInterrupting" attr should default to true
// The spec says that Escalation start events should default to not interrupting..
startNode.setInterrupting(Boolean.parseBoolean(element.getAttribute("isInterrupting")));
startNode.setIoSpecification(readCatchSpecification(parser, element));
findTargetMappingVar(startNode.getIoSpecification().getDataOutputAssociation()).ifPresent(data -> {
startNode.getMetaData().put(TRIGGER_MAPPING, data.getLabel());
startNode.getMetaData().put(MAPPING_VARIABLE, data.getLabel());
});
findSourceMappingVar(startNode.getIoSpecification().getDataOutputAssociation()).ifPresent(data -> {
startNode.getMetaData().put(TRIGGER_MAPPING_INPUT, data.getLabel());
});
startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_NONE);
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("conditionalEventDefinition".equals(nodeName)) {
String constraint = null;
String language = null;
org.w3c.dom.Node subNode = xmlNode.getFirstChild();
while (subNode != null) {
String subnodeName = subNode.getNodeName();
if ("condition".equals(subnodeName)) {
constraint = subNode.getTextContent();
language = ((Element) subNode).getAttribute("language");
break;
}
subNode = subNode.getNextSibling();
}
ConstraintTrigger trigger = new ConstraintTrigger();
trigger.setConstraint(constraint);
startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_CONDITIONAL);
startNode.setMetaData(TRIGGER_REF, "Conditional");
startNode.setMetaData(TRIGGER_EXPRESSION, constraint);
startNode.setMetaData(TRIGGER_EXPRESSION_LANGUAGE, language);
startNode.addTrigger(trigger);
((RuleFlowProcess) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.CURRENT_PROCESS))
.setMetaData(Metadata.CONDITION, Boolean.TRUE);
break;
} else if ("signalEventDefinition".equals(nodeName)) {
String type = ((Element) xmlNode).getAttribute("signalRef");
type = checkSignalAndConvertToRealSignalNam(parser, type);
if (type != null && type.trim().length() > 0) {
addTriggerWithInMappings(startNode, type);
}
startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_SIGNAL);
startNode.setMetaData(MESSAGE_TYPE, type);
startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.Signal.name());
Signal signal = findSignalByName(parser, type);
if (signal != null) {
String eventType = signal.getStructureRef();
startNode.setMetaData(TRIGGER_REF, eventType);
} else {
startNode.setMetaData(TRIGGER_REF, type);
}
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new ProcessParsingValidationException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new ProcessParsingValidationException("Could not find message " + messageRef);
}
startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_MESSAGE);
startNode.setMetaData(MESSAGE_TYPE, message.getType());
startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.ConsumeMessage.name());
startNode.setMetaData(TRIGGER_REF, message.getName());
startNode.setMetaData(MESSAGE_REF, message.getId());
addTriggerWithInMappings(startNode, "Message-" + message.getName(), message.getId(), ((RuleFlowProcess) parser.getMetaData().get("CurrentProcessDefinition")).getCorrelationManager());
} else if ("timerEventDefinition".equals(nodeName)) {
startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_TIMER);
handleTimerNode(startNode, element, uri, localName, parser);
// following event definitions are only for event sub process and will be validated to not be included in top process definitions
} else if ("errorEventDefinition".equals(nodeName)) {
// BPMN2 spec (p.245-246, (2011-01-03)) implies that
// - a <startEvent> in an Event Sub-Process
// - *without* the 'isInterupting' attribute always interrupts (containing process)
startNode.setInterrupting(true);
startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_ERROR);
String errorRef = ((Element) xmlNode).getAttribute("errorRef");
if (errorRef != null && errorRef.trim().length() > 0) {
List<Error> errors = (List<Error>) ((ProcessBuildData) parser.getData()).getMetaData("Errors");
if (errors == null) {
throw new ProcessParsingValidationException("No errors found");
}
Error error = null;
for (Error listError : errors) {
if (errorRef.equals(listError.getId())) {
error = listError;
}
}
if (error == null) {
throw new ProcessParsingValidationException("Could not find error " + errorRef);
}
startNode.setMetaData(FAULT_CODE, error.getErrorCode());
startNode.setMetaData(MESSAGE_TYPE, error.getErrorCode());
startNode.setMetaData(TRIGGER_REF, error.getErrorCode());
startNode.setMetaData(TRIGGER_TYPE, TriggerMetaData.TriggerType.Signal.name());
addTriggerWithInMappings(startNode, "Error-" + error.getErrorCode());
}
} else if ("escalationEventDefinition".equals(nodeName)) {
startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_ESCALATION);
String escalationRef = ((Element) xmlNode).getAttribute("escalationRef");
if (escalationRef != null && escalationRef.trim().length() > 0) {
Map<String, Escalation> escalations = (Map<String, Escalation>) ((ProcessBuildData) parser.getData()).getMetaData(ProcessHandler.ESCALATIONS);
if (escalations == null) {
throw new ProcessParsingValidationException("No escalations found");
}
Escalation escalation = escalations.get(escalationRef);
if (escalation == null) {
throw new ProcessParsingValidationException("Could not find escalation " + escalationRef);
}
startNode.setMetaData(FAULT_CODE, escalation.getEscalationCode());
startNode.setMetaData(TRIGGER_REF, "Escalation-" + escalation.getEscalationCode());
addTriggerWithInMappings(startNode, "Escalation-" + escalation.getEscalationCode());
} else {
startNode.setMetaData(TRIGGER_REF, "Escalation-");
addTriggerWithInMappings(startNode, "Escalation-");
}
} else if ("compensateEventDefinition".equals(nodeName)) {
startNode.setMetaData(EVENT_TYPE, EVENT_TYPE_COMPENSATION);
handleCompensationNode(startNode, xmlNode);
}
xmlNode = xmlNode.getNextSibling();
}
if (startNode.getName() == null) {
startNode.setName("Start");
}
return startNode;
}