Search code examples
camunda

What is the common context base class used by Java code delegates?


What is the common base class used by Java code delegates so that common code can be used to get/set process variables etc?

For a service-task, the process engine context class is DelegateExecution and typically, to get a process variable, this context, passed as a parameter is used to access process variables.

...
public class CreatePurchaseOrderRequistionDelegate implements JavaDelegate
{
   public void execute( DelegateExecution execution ) throws Exception
   {
      LOGGER.info( getClass().getSimpleName() + ": starting" );

      String purchaseOrderRef = (String) execution.getVariable( "purchaseOrderReference" );
...

For a user-task event listener, the context class is DelegateTask.

I want to use the same code to get/set process variables so need a base class that has access to setVariable(), etc

I have looked at the Camunda Manual, Javadocs etc but both classes inherit from a number of other classes and it is difficult to trace the inheritance tree.


Solution

  • It should be: org.camunda.bpm.engine.delegate.VariableScope

    So something like:

       public static String getVariableS( VariableScope execution, String variableName, String defaultValue ) throws Exception
       {
          Object obj = execution.getVariable( variableName );      
          if( obj == null )
          {
             return defaultValue;
          }
          return (String) obj;
       }
    

    Hope this helps!