Thread.currentThread().setContextClassLoader(JbpmConfiguration.getProcessClassLoader(taskInstance.getTask().getProcessDefinition()));
if (taskControllerDelegation != null) {
TaskControllerHandler taskControllerHandler = (TaskControllerHandler) taskControllerDelegation.instantiate();
ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance();
ContextInstance contextInstance = (processInstance != null ? processInstance.getContextInstance() : null);
Token token = taskInstance.getToken();
if (UserCodeInterceptorConfig.userCodeInterceptor != null) {
UserCodeInterceptorConfig.userCodeInterceptor.executeTaskControllerSubmission(taskControllerHandler, taskInstance, contextInstance, token);
} else {
taskControllerHandler.submitTaskVariables(taskInstance, contextInstance, token);
}
} else {
Token token = taskInstance.getToken();
ProcessInstance processInstance = token.getProcessInstance();
ContextInstance contextInstance = processInstance.getContextInstance();
if (variableAccesses != null) {
String missingTaskVariables = null;
for (VariableAccess variableAccess : variableAccesses) {
String mappedName = variableAccess.getMappedName();
// first check if the required variableInstances are present
if ((variableAccess.isRequired()) && (!taskInstance.hasVariableLocally(mappedName))) {
if (missingTaskVariables == null) {
missingTaskVariables = mappedName;
} else {
missingTaskVariables += ", " + mappedName;
}
}
}
// if there are missing, required parameters, throw an
// IllegalArgumentException
if (missingTaskVariables != null) {
throw new IllegalArgumentException("missing task variables: " + missingTaskVariables);
}
for (VariableAccess variableAccess : variableAccesses) {
String mappedName = variableAccess.getMappedName();
String variableName = variableAccess.getVariableName();
if (variableAccess.isWritable()) {
Object value = taskInstance.getVariable(mappedName);
if (value != null) {
log.debug("submitting task variable '" + mappedName + "' to process variable '" + variableName + "', value '" + value + "'");
contextInstance.setVariable(variableName, value, token);
}
}
}
}
}