Author: camunda
Date: 2008-10-07 07:37:40 -0400 (Tue, 07 Oct 2008)
New Revision: 2497
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/def/Action.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/Decision.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/taskmgmt/def/TaskController.java
jbpm3/trunk/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java
Log:
JBPM-1448
set ContextClassLoader correctly to ProcessClassLoader wherever Delegation classes are
instantiated and used (
https://jira.jboss.org/jira/browse/JBPM-1448)
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/def/Action.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/def/Action.java 2008-10-07
11:09:44 UTC (rev 2496)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/def/Action.java 2008-10-07
11:37:40 UTC (rev 2497)
@@ -30,6 +30,7 @@
import org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator;
import org.jbpm.jpdl.xml.JpdlXmlReader;
import org.jbpm.jpdl.xml.Parsable;
+import org.jbpm.util.ClassLoaderUtil;
import org.jbpm.util.EqualsUtil;
public class Action implements ActionHandler, Parsable, Serializable {
@@ -111,15 +112,23 @@
}
public void execute(ExecutionContext executionContext) throws Exception {
- if (referencedAction!=null) {
- referencedAction.execute(executionContext);
+ ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ // set context class loader correctly for delegation class
(
https://jira.jboss.org/jira/browse/JBPM-1448)
+
Thread.currentThread().setContextClassLoader(ClassLoaderUtil.getProcessClassLoader(processDefinition));
- } else if (actionExpression!=null) {
- JbpmExpressionEvaluator.evaluate(actionExpression, executionContext);
+ if (referencedAction != null) {
+ referencedAction.execute(executionContext);
- } else if (actionDelegation!=null) {
- ActionHandler actionHandler = (ActionHandler)actionDelegation.getInstance();
- actionHandler.execute(executionContext);
+ } else if (actionExpression != null) {
+ JbpmExpressionEvaluator.evaluate(actionExpression, executionContext);
+
+ } else if (actionDelegation != null) {
+ ActionHandler actionHandler = (ActionHandler) actionDelegation.getInstance();
+ actionHandler.execute(executionContext);
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(surroundingClassLoader);
}
}
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/Decision.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/Decision.java 2008-10-07
11:09:44 UTC (rev 2496)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/graph/node/Decision.java 2008-10-07
11:37:40 UTC (rev 2497)
@@ -35,6 +35,7 @@
import org.jbpm.jpdl.el.impl.JbpmExpressionEvaluator;
import org.jbpm.jpdl.xml.JpdlXmlReader;
import org.jbpm.jpdl.xml.Parsable;
+import org.jbpm.util.ClassLoaderUtil;
/**
* decision node.
@@ -72,73 +73,84 @@
public void execute(ExecutionContext executionContext) {
Transition transition = null;
-
+ ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader();
try {
- if (decisionDelegation!=null) {
- DecisionHandler decisionHandler = (DecisionHandler)
decisionDelegation.instantiate();
- String transitionName = decisionHandler.decide(executionContext);
- transition = getLeavingTransition(transitionName);
- if (transition==null) {
- throw new JbpmException("decision '"+name+"' selected
non existing transition '"+transitionName+"'" );
- }
-
- } else if (decisionExpression!=null) {
- Object result = JbpmExpressionEvaluator.evaluate(decisionExpression,
executionContext);
- if (result==null) {
- throw new JbpmException("decision expression
'"+decisionExpression+"' returned null");
- }
- String transitionName = result.toString();
- transition = getLeavingTransition(transitionName);
- if (transition==null) {
- throw new JbpmException("decision '"+name+"' selected
non existing transition '"+transitionName+"'" );
- }
-
- } else if (decisionConditions!=null && !decisionConditions.isEmpty()) {
- // backwards compatible mode based on separate DecisionCondition's
- Iterator iter = decisionConditions.iterator();
- while (iter.hasNext() && (transition==null)) {
- DecisionCondition decisionCondition = (DecisionCondition) iter.next();
- Object result =
JbpmExpressionEvaluator.evaluate(decisionCondition.getExpression(), executionContext);
- if (Boolean.TRUE.equals(result)) {
- String transitionName = decisionCondition.getTransitionName();
- transition = getLeavingTransition(transitionName);
- if (transition!=null) {
- transition.removeConditionEnforcement();
- }
+ // set context class loader correctly for delegation class
(
https://jira.jboss.org/jira/browse/JBPM-1448)
+
Thread.currentThread().setContextClassLoader(ClassLoaderUtil.getProcessClassLoader(processDefinition));
+
+ try {
+ if (decisionDelegation != null) {
+ DecisionHandler decisionHandler = (DecisionHandler)
decisionDelegation.instantiate();
+ String transitionName = decisionHandler.decide(executionContext);
+ transition = getLeavingTransition(transitionName);
+ if (transition == null) {
+ throw new JbpmException("decision '" + name + "'
selected non existing transition '" + transitionName + "'");
}
- }
-
- } else {
- // new mode based on conditions in the transition itself
- Iterator iter = leavingTransitions.iterator();
- while (iter.hasNext() && (transition==null)) {
- Transition candidate = (Transition) iter.next();
-
- String conditionExpression = candidate.getCondition();
- if (conditionExpression!=null) {
- Object result = JbpmExpressionEvaluator.evaluate(conditionExpression,
executionContext);
+
+ } else if (decisionExpression != null) {
+ Object result = JbpmExpressionEvaluator.evaluate(decisionExpression,
executionContext);
+ if (result == null) {
+ throw new JbpmException("decision expression '" +
decisionExpression + "' returned null");
+ }
+ String transitionName = result.toString();
+ transition = getLeavingTransition(transitionName);
+ if (transition == null) {
+ throw new JbpmException("decision '" + name + "'
selected non existing transition '" + transitionName + "'");
+ }
+
+ } else if (decisionConditions != null && !decisionConditions.isEmpty())
{
+ // backwards compatible mode based on separate DecisionCondition's
+ Iterator iter = decisionConditions.iterator();
+ while (iter.hasNext() && (transition == null)) {
+ DecisionCondition decisionCondition = (DecisionCondition) iter.next();
+ Object result =
JbpmExpressionEvaluator.evaluate(decisionCondition.getExpression(), executionContext);
if (Boolean.TRUE.equals(result)) {
- transition = candidate;
+ String transitionName = decisionCondition.getTransitionName();
+ transition = getLeavingTransition(transitionName);
+ if (transition != null) {
+ transition.removeConditionEnforcement();
+ }
}
}
+
+ } else {
+ // new mode based on conditions in the transition itself
+ Iterator iter = leavingTransitions.iterator();
+ while (iter.hasNext() && (transition == null)) {
+ Transition candidate = (Transition) iter.next();
+
+ String conditionExpression = candidate.getCondition();
+ if (conditionExpression != null) {
+ Object result = JbpmExpressionEvaluator.evaluate(conditionExpression,
executionContext);
+ if (Boolean.TRUE.equals(result)) {
+ transition = candidate;
+ }
+ }
+ }
+
}
- }
+ if (transition == null) {
+ transition = getDefaultLeavingTransition();
+ log.debug("decision didn't select transition, taking default " +
transition);
+ }
- if (transition==null) {
- transition = getDefaultLeavingTransition();
- log.debug("decision didn't select transition, taking default
"+transition);
+ // since the decision node evaluates condition expressions, the
+ // condition of the
+ // taken transition will always be met. therefor we can safely turn off
+ // the
+ // standard condition enforcement in the transitions after a decision
+ // node.
+ transition.removeConditionEnforcement();
+
+ } catch (Exception exception) {
+ raiseException(exception, executionContext);
}
- // since the decision node evaluates condition expressions, the condition of the
- // taken transition will always be met. therefor we can safely turn off the
- // standard condition enforcement in the transitions after a decision node.
- transition.removeConditionEnforcement();
-
- } catch (Exception exception) {
- raiseException(exception, executionContext);
}
-
+ finally {
+ Thread.currentThread().setContextClassLoader(surroundingClassLoader);
+ }
log.debug("decision "+name+" is taking
'"+transition+"'");
executionContext.leaveNode(transition);
}
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/taskmgmt/def/TaskController.java
===================================================================
---
jbpm3/trunk/modules/core/src/main/java/org/jbpm/taskmgmt/def/TaskController.java 2008-10-07
11:09:44 UTC (rev 2496)
+++
jbpm3/trunk/modules/core/src/main/java/org/jbpm/taskmgmt/def/TaskController.java 2008-10-07
11:37:40 UTC (rev 2497)
@@ -34,6 +34,7 @@
import org.jbpm.instantiation.Delegation;
import org.jbpm.instantiation.UserCodeInterceptorConfig;
import org.jbpm.taskmgmt.exe.TaskInstance;
+import org.jbpm.util.ClassLoaderUtil;
import org.jbpm.util.EqualsUtil;
/**
@@ -70,101 +71,116 @@
* visible (that means that the user did not specify a special task instance scope).
*/
public void initializeVariables(TaskInstance taskInstance) {
- 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.executeTaskControllerInitialization(taskControllerHandler,
taskInstance, contextInstance, token);
+ ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ // set context class loader correctly for delegation class
(
https://jira.jboss.org/jira/browse/JBPM-1448)
+
Thread.currentThread().setContextClassLoader(ClassLoaderUtil.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.executeTaskControllerInitialization(taskControllerHandler,
taskInstance, contextInstance, token);
+ } else {
+ taskControllerHandler.initializeTaskVariables(taskInstance, contextInstance,
token);
+ }
+
} else {
- taskControllerHandler.initializeTaskVariables(taskInstance, contextInstance,
token);
- }
+ Token token = taskInstance.getToken();
+ ProcessInstance processInstance = token.getProcessInstance();
+ ContextInstance contextInstance = processInstance.getContextInstance();
- } else {
- Token token = taskInstance.getToken();
- ProcessInstance processInstance = token.getProcessInstance();
- ContextInstance contextInstance = processInstance.getContextInstance();
-
- if (variableAccesses!=null) {
- Iterator iter = variableAccesses.iterator();
- while (iter.hasNext()) {
- VariableAccess variableAccess = (VariableAccess) iter.next();
- String mappedName = variableAccess.getMappedName();
- if (variableAccess.isReadable()) {
- String variableName = variableAccess.getVariableName();
- Object value = contextInstance.getVariable(variableName, token);
- log.debug("creating task instance variable
'"+mappedName+"' from process variable
'"+variableName+"', value '"+value+"'");
- taskInstance.setVariableLocally(mappedName, value);
- } else {
- log.debug("creating task instance local variable
'"+mappedName+"'. initializing with null value.");
- taskInstance.setVariableLocally(mappedName, null);
+ if (variableAccesses != null) {
+ Iterator iter = variableAccesses.iterator();
+ while (iter.hasNext()) {
+ VariableAccess variableAccess = (VariableAccess) iter.next();
+ String mappedName = variableAccess.getMappedName();
+ if (variableAccess.isReadable()) {
+ String variableName = variableAccess.getVariableName();
+ Object value = contextInstance.getVariable(variableName, token);
+ log.debug("creating task instance variable '" + mappedName +
"' from process variable '" + variableName + "', value
'" + value + "'");
+ taskInstance.setVariableLocally(mappedName, value);
+ } else {
+ log.debug("creating task instance local variable '" +
mappedName + "'. initializing with null value.");
+ taskInstance.setVariableLocally(mappedName, null);
+ }
}
}
}
- }
+ } finally {
+ Thread.currentThread().setContextClassLoader(surroundingClassLoader);
+ }
}
/**
* update the process variables from the the task-instance variables.
*/
public void submitParameters(TaskInstance taskInstance) {
- if (taskControllerDelegation != null) {
- TaskControllerHandler taskControllerHandler = (TaskControllerHandler)
taskControllerDelegation.instantiate();
- ProcessInstance processInstance =
taskInstance.getTaskMgmtInstance().getProcessInstance();
- ContextInstance contextInstance = (processInstance!=null ?
processInstance.getContextInstance() : null);
- Token token = taskInstance.getToken();
+ ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ // set context class loader correctly for delegation class
(
https://jira.jboss.org/jira/browse/JBPM-1448)
+
Thread.currentThread().setContextClassLoader(ClassLoaderUtil.getProcessClassLoader(taskInstance.getTask().getProcessDefinition()));
- if (UserCodeInterceptorConfig.userCodeInterceptor!=null) {
-
UserCodeInterceptorConfig.userCodeInterceptor.executeTaskControllerSubmission(taskControllerHandler,
taskInstance, contextInstance, token);
+ 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 {
- taskControllerHandler.submitTaskVariables(taskInstance, contextInstance, token);
- }
- } else {
+ Token token = taskInstance.getToken();
+ ProcessInstance processInstance = token.getProcessInstance();
+ ContextInstance contextInstance = processInstance.getContextInstance();
- Token token = taskInstance.getToken();
- ProcessInstance processInstance = token.getProcessInstance();
- ContextInstance contextInstance = processInstance.getContextInstance();
-
- if (variableAccesses!=null) {
- String missingTaskVariables = null;
- Iterator iter = variableAccesses.iterator();
- while (iter.hasNext()) {
- VariableAccess variableAccess = (VariableAccess) iter.next();
- 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 (variableAccesses != null) {
+ String missingTaskVariables = null;
+ Iterator iter = variableAccesses.iterator();
+ while (iter.hasNext()) {
+ VariableAccess variableAccess = (VariableAccess) iter.next();
+ 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);
- }
+ // if there are missing, required parameters, throw an
+ // IllegalArgumentException
+ if (missingTaskVariables != null) {
+ throw new IllegalArgumentException("missing task variables: " +
missingTaskVariables);
+ }
- iter = variableAccesses.iterator();
- while (iter.hasNext()) {
- VariableAccess variableAccess = (VariableAccess) iter.next();
- 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);
+ iter = variableAccesses.iterator();
+ while (iter.hasNext()) {
+ VariableAccess variableAccess = (VariableAccess) iter.next();
+ 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);
+ }
}
}
}
}
+ } finally {
+ Thread.currentThread().setContextClassLoader(surroundingClassLoader);
}
}
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java
===================================================================
---
jbpm3/trunk/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java 2008-10-07
11:09:44 UTC (rev 2496)
+++
jbpm3/trunk/modules/core/src/main/java/org/jbpm/taskmgmt/exe/TaskMgmtInstance.java 2008-10-07
11:37:40 UTC (rev 2497)
@@ -54,6 +54,7 @@
import org.jbpm.taskmgmt.def.Task;
import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
import org.jbpm.taskmgmt.log.TaskCreateLog;
+import org.jbpm.util.ClassLoaderUtil;
import org.jbpm.util.Clock;
/**
@@ -264,14 +265,23 @@
}
void performAssignmentDelegation(Delegation assignmentDelegation, Assignable
assignable, ExecutionContext executionContext) throws Exception {
- // instantiate the assignment handler
- AssignmentHandler assignmentHandler = (AssignmentHandler)
assignmentDelegation.instantiate();
- // invoke the assignment handler
- if (UserCodeInterceptorConfig.userCodeInterceptor!=null) {
- UserCodeInterceptorConfig.userCodeInterceptor.executeAssignment(assignmentHandler,
assignable, executionContext);
- } else {
- assignmentHandler.assign(assignable, executionContext);
- }
+ ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ // set context class loader correctly for delegation class
(
https://jira.jboss.org/jira/browse/JBPM-1448)
+
Thread.currentThread().setContextClassLoader(ClassLoaderUtil.getProcessClassLoader(executionContext.getProcessDefinition()));
+
+ // instantiate the assignment handler
+ AssignmentHandler assignmentHandler = (AssignmentHandler)
assignmentDelegation.instantiate();
+ // invoke the assignment handler
+ if (UserCodeInterceptorConfig.userCodeInterceptor != null) {
+
UserCodeInterceptorConfig.userCodeInterceptor.executeAssignment(assignmentHandler,
assignable, executionContext);
+ } else {
+ assignmentHandler.assign(assignable, executionContext);
+ }
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(surroundingClassLoader);
+ }
}
void performAssignmentActorIdExpr(String actorIdExpression, Assignable assignable,
ExecutionContext executionContext) {