public static void linkBoundaryEvents(NodeContainer nodeContainer) { for (Node node : nodeContainer.getNodes()) { if (node instanceof EventNode) { String attachedTo = (String) node.getMetaData().get("AttachedTo"); if (attachedTo != null) { String type = ((EventTypeFilter) ((EventNode) node).getEventFilters().get(0)).getType(); Node attachedNode = null; try { // remove starting _ String attachedToString = attachedTo.substring(1); // remove ids of parent nodes attachedToString = attachedToString.substring(attachedToString.lastIndexOf("-") + 1); attachedNode = nodeContainer.getNode(new Integer(attachedToString)); } catch (NumberFormatException e) { // try looking for a node with same "UniqueId" (in metadata) for (Node subnode : nodeContainer.getNodes()) { if (attachedTo.equals(subnode.getMetaData().get("UniqueId"))) { attachedNode = subnode; break; } } if (attachedNode == null) { throw new IllegalArgumentException("Could not find node to attach to: " + attachedTo); } } if (type.startsWith("Escalation-")) { boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity"); CompositeContextNode compositeNode = (CompositeContextNode) attachedNode; ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE); if (exceptionScope == null) { exceptionScope = new ExceptionScope(); compositeNode.addContext(exceptionScope); compositeNode.setDefaultContext(exceptionScope); } String escalationCode = (String) node.getMetaData().get("EscalationEvent"); ActionExceptionHandler exceptionHandler = new ActionExceptionHandler(); exceptionHandler.setAction( new DroolsConsequenceAction( "java", (cancelActivity ? "((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();" : "") + "kcontext.getProcessInstance().signalEvent(\"Escalation-" + attachedTo + "-" + escalationCode + "\", null);")); exceptionScope.setExceptionHandler(escalationCode, exceptionHandler); } else if (type.startsWith("Error-")) { CompositeContextNode compositeNode = (CompositeContextNode) attachedNode; ExceptionScope exceptionScope = (ExceptionScope) compositeNode.getDefaultContext(ExceptionScope.EXCEPTION_SCOPE); if (exceptionScope == null) { exceptionScope = new ExceptionScope(); compositeNode.addContext(exceptionScope); compositeNode.setDefaultContext(exceptionScope); } String errorCode = (String) node.getMetaData().get("ErrorEvent"); ActionExceptionHandler exceptionHandler = new ActionExceptionHandler(); exceptionHandler.setAction( new DroolsConsequenceAction( "java", "((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();" + "kcontext.getProcessInstance().signalEvent(\"Error-" + attachedTo + "-" + errorCode + "\", null);")); exceptionScope.setExceptionHandler(errorCode, exceptionHandler); } else if (type.startsWith("Timer-")) { boolean cancelActivity = (Boolean) node.getMetaData().get("CancelActivity"); CompositeContextNode compositeNode = (CompositeContextNode) attachedNode; String timeCycle = (String) node.getMetaData().get("TimeCycle"); Timer timer = new Timer(); timer.setDelay(timeCycle); compositeNode.addTimer( timer, new DroolsConsequenceAction( "java", (cancelActivity ? "((org.drools.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();" : "") + "kcontext.getProcessInstance().signalEvent(\"Timer-" + attachedTo + "-" + timeCycle + "\", null);")); } else if (type.startsWith("Compensate-")) { String uniqueId = (String) node.getMetaData().get("UniqueId"); String eventType = "Compensate-" + uniqueId; ((EventTypeFilter) ((EventNode) node).getEventFilters().get(0)).setType(eventType); } } } } }