}
@SuppressWarnings("unchecked")
public void handleMessageNode(final Node node, final Element element, final String uri,
final String localName, final ExtensibleXmlParser parser) throws SAXException {
EndNode endNode = (EndNode) node;
org.w3c.dom.Node xmlNode = element.getFirstChild();
while (xmlNode != null) {
String nodeName = xmlNode.getNodeName();
if ("dataInputAssociation".equals(nodeName)) {
readEndDataInputAssociation(xmlNode, endNode);
} 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 IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
String variable = (String) endNode.getMetaData("MappingVariable");
endNode.setMetaData("MessageType", message.getType());
List<DroolsAction> actions = new ArrayList<DroolsAction>();
actions.add(new DroolsConsequenceAction("java",
"org.drools.process.instance.impl.WorkItemImpl workItem = new org.drools.process.instance.impl.WorkItemImpl();" + EOL +
"workItem.setName(\"Send Task\");" + EOL +
"workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL +
(variable == null ? "" : "workItem.setParameter(\"Message\", " + variable + ");" + EOL) +
"((org.drools.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
}
xmlNode = xmlNode.getNextSibling();
}
}