protected static void applyFieldExtensions(List<FieldExtension> fieldExtensions, Object target, VariableContainer variableContainer, boolean throwExceptionOnMissingField) { if (fieldExtensions != null) { for (FieldExtension fieldExtension : fieldExtensions) { applyFieldExtension(fieldExtension, target, throwExceptionOnMissingField); } } }
@Override public void handleHttpRequest(VariableContainer execution, HttpRequest httpRequest, HttpClient client) { Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, execution, fieldExtensions); if (delegate instanceof HttpRequestHandler) { ((HttpRequestHandler) delegate).handleHttpRequest(execution, httpRequest, client); } else { throw new FlowableIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + HttpRequestHandler.class); } }
public static Object resolveDelegateExpression(Expression expression, VariableContainer variableContainer, List<FieldExtension> fieldExtensions) { // Note: we can't cache the result of the expression, because the // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}' Object delegate = expression.getValue(variableContainer); if (fieldExtensions != null && fieldExtensions.size() > 0) { DelegateExpressionFieldInjectionMode injectionMode = CommandContextUtil.getCmmnEngineConfiguration().getDelegateExpressionFieldInjectionMode(); if (injectionMode == DelegateExpressionFieldInjectionMode.COMPATIBILITY) { applyFieldExtensions(fieldExtensions, delegate, variableContainer, true); } else if (injectionMode == DelegateExpressionFieldInjectionMode.MIXED) { applyFieldExtensions(fieldExtensions, delegate, variableContainer, false); } } return delegate; }
@Override public void stateChanged(DelegatePlanItemInstance planItemInstance, String oldState, String newState) { try { DelegatePlanItemInstance delegatePlanItemInstance = (DelegatePlanItemInstance) planItemInstance; Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, (DelegatePlanItemInstance) planItemInstance, fieldExtensions); if (delegate instanceof PlanItemInstanceLifecycleListener) { try { PlanItemInstanceLifecycleListener listener = (PlanItemInstanceLifecycleListener) delegate; listener.stateChanged(delegatePlanItemInstance, oldState, newState); } catch (Exception e) { throw new FlowableException("Exception while invoking TaskListener: " + e.getMessage(), e); } } else { throw new FlowableIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + TaskListener.class); } } catch (Exception e) { throw new FlowableException(e.getMessage(), e); } }
@Override public void notify(DelegateTask delegateTask) { try { Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, delegateTask, fieldExtensions); if (delegate instanceof TaskListener) { try { TaskListener taskListener = (TaskListener) delegate; taskListener.notify(delegateTask); } catch (Exception e) { throw new FlowableException("Exception while invoking TaskListener: " + e.getMessage(), e); } } else { throw new FlowableIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + TaskListener.class); } } catch (Exception e) { throw new FlowableException(e.getMessage(), e); } }
@Override public void execute(CommandContext commandContext, PlanItemInstanceEntity planItemInstanceEntity) { try { Expression expressionObject = CommandContextUtil.getCmmnEngineConfiguration(commandContext).getExpressionManager().createExpression(expression); Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expressionObject, planItemInstanceEntity, fieldExtensions); if (delegate instanceof PlanItemActivityBehavior) { ((PlanItemActivityBehavior) delegate).execute(planItemInstanceEntity); } else if (delegate instanceof PlanItemJavaDelegate) { PlanItemJavaDelegateActivityBehavior behavior = new PlanItemJavaDelegateActivityBehavior((PlanItemJavaDelegate) delegate); behavior.execute(planItemInstanceEntity); } else { throw new FlowableIllegalArgumentException("Delegate expression " + expression + " did neither resolve to an implementation of " + PlanItemActivityBehavior.class + " nor " + PlanItemJavaDelegate.class); } } catch (Exception exc) { throw new FlowableException(exc.getMessage(), exc); } }