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.jbpm.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.jbpm.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 timeDuration = (String) node.getMetaData().get("TimeDuration");
String timeCycle = (String) node.getMetaData().get("TimeCycle");
Timer timer = new Timer();
if (timeDuration != null) {
timer.setDelay(timeDuration);
compositeNode.addTimer(timer, new DroolsConsequenceAction("java",
(cancelActivity ? "((org.jbpm.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();" : "") +
"kcontext.getProcessInstance().signalEvent(\"Timer-" + attachedTo + "-" + timeDuration + "\", null);"));
} else if (timeCycle != null) {
int index = timeCycle.indexOf("###");
if (index != -1) {
String period = timeCycle.substring(index + 3);
timeCycle = timeCycle.substring(0, index);
timer.setPeriod(period);
}
timer.setDelay(timeCycle);
compositeNode.addTimer(timer, new DroolsConsequenceAction("java",
(cancelActivity ? "((org.jbpm.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();" : "") +
"kcontext.getProcessInstance().signalEvent(\"Timer-" + attachedTo + "-" + timeCycle + (timer.getPeriod() == null ? "" : "###" + timer.getPeriod()) + "\", null);"));
}
} else if (type.startsWith("Compensate-")) {
String uniqueId = (String) node.getMetaData().get("UniqueId");