anchor.diff:  * *COMPATIBILITY*: in this mode, the behavior will be exactly as it was before version 5.21: field injection is possible when using delegate expressions and an exception will be thrown when the fields are not defined on the delegate class. This is of course the least safe mode with regards to thread-safety, but it can be needed for backwards compatibility or can be used safely when the delegate expression is used only on one task in a set of process definitions (and thus no concurrent race conditions can happen).
   * *MIXED*: Allows injection when using delegateExpressions but will not throw an exception when the fields are not defined on the delegate. This allows for mixed behaviors where some delegates have injection (for example because they are not singletons) and some don't.
   
  +* *The default mode for Activiti version 5.x is COMPATIBILITY.*
  +* *The default mode for Activiti version 6.x is MIXED.*
  +
   For example, suppose that we're using _MIXED_ mode and we're using the Spring integration. Suppose that we have following beans in the Spring configuration:
   
   [source,xml,linenums]
  
positive.code: 
  The class +ToUpperCaseFieldInjected+ has a field +text+ which is of type +org.activiti.engine.delegate.Expression+. When calling +text.getValue(execution)+, the configured string value +Hello World+ will be returned:
  
  [source,java, linenums]
  ----
  public class ToUpperCaseFieldInjected implements JavaDelegate {
  
  
negative.code: 
  The _INSTANCE_COUNT_ will always be _one_ here, as it is a singleton. In this delegate, there are no _Expression_ member fields. This is possible since we're running in _MIXED_ mode. In _COMPATIBILITY_ mode, this would throw an exception as it expects the member fields to be there. _DISABLED_ mode would also work for this bean, but it would disallow the use the prototype bean above that does use field injection.
  
  In this delegate code, the *org.activiti.engine.delegate.DelegateHelper* class is used, that has some useful utility methods to execute the same logic, but in a thread-safe way when the delegate is a singleton. Instead of injecting the _Expression_, it is fetched via the _getFieldExpression_ method. This means that when it comes to the service task xml, the fields are defined exactly the same as for the singleton bean. If you look at the xml snippet above, you can see they are equal in definition and only the implementation logic differs.
  
  (Technical note: the _getFieldExpression_ will introspect the BpmnModel and create the Expression on the fly when the method is executed, making it thread-safe)
  
  
  * For Activiti versions 5.x, the DelegateHelper cannot be used for an _ExecutionListener_ or _TaskListener_ (due to an architectural flaw). To make thread-safe instances of those listeners, use either an expression or make sure a new instance is created every time the delegate expression is resolved.
  * For Activiti version 6.x the DelegateHelper does work in _ExecutionListener_ and _TaskListener_ implementations. For example in version 6.x, the following code can be written, using the *DelegateHelper*:
  
  [source,xml,linenums]
  ----
  <extensionElements>
    <activiti:executionListener
        delegateExpression="${testExecutionListener}" event="start">
      <activiti:field name="input" expression="${startValue}" />
      <activiti:field name="resultVar" stringValue="processStartValue" />
    </activiti:executionListener>
  </extensionElements>
  ----
  
  Where _testExecutionListener_ resolves to an instance implementing the ExecutionListener interface:
  
  [source,java,linenums]
  ----
  @Component("testExecutionListener")
  public class TestExecutionListener implements ExecutionListener {
  
    @Override
    public void notify(DelegateExecution execution) {
      Expression inputExpression = DelegateHelper.getFieldExpression(execution, "input");
      Number input = (Number) inputExpression.getValue(execution);
  
      int result = input.intValue() * 100;
  
      Expression resultVarExpression = DelegateHelper.getFieldExpression(execution, "resultVar");
      execution.setVariable(resultVarExpression.getValue(execution).toString(), result);
    }
  
  }
  ----
  
  
  
  [[serviceTaskResultValue]]
  