org.activiti.engine.delegate.JavaDelegate Java Examples

The following examples show how to use org.activiti.engine.delegate.JavaDelegate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DelegateExpressionExecutionListener.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void notify(DelegateExecution execution) {
  // Note: we can't cache the result of the expression, because the
  // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
  Object delegate = expression.getValue(execution);
  ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate);
  
  if (delegate instanceof ExecutionListener) {
    Context.getProcessEngineConfiguration()
      .getDelegateInterceptor()
      .handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution));
  } else if (delegate instanceof JavaDelegate) {
    Context.getProcessEngineConfiguration()
      .getDelegateInterceptor()
      .handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
  } else {
    throw new ActivitiIllegalArgumentException("Delegate expression " + expression 
            + " did not resolve to an implementation of " + ExecutionListener.class 
            + " nor " + JavaDelegate.class);
  }
}
 
Example #2
Source File: ClassDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ExecutionListener getExecutionListenerInstance() {
  Object delegateInstance = instantiateDelegate(className, fieldDeclarations);
  if (delegateInstance instanceof ExecutionListener) {
    return (ExecutionListener) delegateInstance; 
  } else if (delegateInstance instanceof JavaDelegate) {
    return new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance);
  } else {
    throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName()+" doesn't implement "+ExecutionListener.class+" nor "+JavaDelegate.class);
  }
}
 
Example #3
Source File: ClassDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ActivityBehavior getActivityBehaviorInstance(ActivityExecution execution) {
  Object delegateInstance = instantiateDelegate(className, fieldDeclarations);
  
  if (delegateInstance instanceof ActivityBehavior) {
    return determineBehaviour((ActivityBehavior) delegateInstance, execution);
  } else if (delegateInstance instanceof JavaDelegate) {
    return determineBehaviour(new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance), execution);
  } else {
    throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName()+" doesn't implement "+JavaDelegate.class.getName()+" nor "+ActivityBehavior.class.getName());
  }
}
 
Example #4
Source File: ClassDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ExecutionListener getExecutionListenerInstance() {
  Object delegateInstance = instantiateDelegate(className, fieldDeclarations);
  if (delegateInstance instanceof ExecutionListener) {
    return (ExecutionListener) delegateInstance;
  } else if (delegateInstance instanceof JavaDelegate) {
    return new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance);
  } else {
    throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + ExecutionListener.class + " nor " + JavaDelegate.class);
  }
}
 
Example #5
Source File: ClassDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ActivityBehavior getActivityBehaviorInstance() {
  Object delegateInstance = instantiateDelegate(className, fieldDeclarations);

  if (delegateInstance instanceof ActivityBehavior) {
    return determineBehaviour((ActivityBehavior) delegateInstance);
  } else if (delegateInstance instanceof JavaDelegate) {
    return determineBehaviour(new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance));
  } else {
    throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + JavaDelegate.class.getName() + " nor " + ActivityBehavior.class.getName());
  }
}
 
Example #6
Source File: DelegateExpressionExecutionListener.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void notify(DelegateExecution execution) {
  Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, execution, fieldDeclarations); 
  if (delegate instanceof ExecutionListener) {
    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution));
  } else if (delegate instanceof JavaDelegate) {
    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
  } else {
    throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + ExecutionListener.class + " nor " + JavaDelegate.class);
  }
}
 
Example #7
Source File: BlueprintELResolver.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public void unbindService(JavaDelegate delegate, Map props) {
  String name = (String) props.get("osgi.service.blueprint.compname");
  if (delegateMap.containsKey(name)) {
    delegateMap.remove(name);
  }
  LOGGER.info("removed Activiti service from delegate cache {}", name);
}
 
Example #8
Source File: JavaDelegateInvocation.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public JavaDelegateInvocation(JavaDelegate delegateInstance, DelegateExecution execution) {
  this.delegateInstance = delegateInstance;
  this.execution = execution;
}
 
Example #9
Source File: ServiceTaskJavaDelegateActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ServiceTaskJavaDelegateActivityBehavior(JavaDelegate javaDelegate) {
  this.javaDelegate = javaDelegate;
}
 
Example #10
Source File: ServiceTaskDelegateExpressionActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
 ActivityExecution activityExecution = (ActivityExecution) execution;
  try {
    boolean isSkipExpressionEnabled = SkipExpressionUtil.isSkipExpressionEnabled(activityExecution, skipExpression); 
    if (!isSkipExpressionEnabled || 
            (isSkipExpressionEnabled && !SkipExpressionUtil.shouldSkipFlowElement(activityExecution, skipExpression))) {
      
      if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
        ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(serviceTaskId, execution.getProcessDefinitionId());
        if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SERVICE_TASK_DELEGATE_EXPRESSION)) {
          String overrideExpression = taskElementProperties.get(DynamicBpmnConstants.SERVICE_TASK_DELEGATE_EXPRESSION).asText();
          if (StringUtils.isNotEmpty(overrideExpression) && overrideExpression.equals(expression.getExpressionText()) == false) {
            expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(overrideExpression);
          }
        }
      }
      
      Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, execution, fieldDeclarations);

      if (delegate instanceof ActivityBehavior) {

        if(delegate instanceof AbstractBpmnActivityBehavior){
          ((AbstractBpmnActivityBehavior) delegate).setMultiInstanceActivityBehavior(getMultiInstanceActivityBehavior());
        }

        Context.getProcessEngineConfiguration().getDelegateInterceptor()
                .handleInvocation(new ActivityBehaviorInvocation((ActivityBehavior) delegate, activityExecution));

      } else if (delegate instanceof JavaDelegate) {
        Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
        leave(activityExecution);

      } else {
        throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did neither resolve to an implementation of "
                + ActivityBehavior.class + " nor " + JavaDelegate.class);
      }
    } else {
      leave(activityExecution);
    }
  } catch (Exception exc) {

    Throwable cause = exc;
    BpmnError error = null;
    while (cause != null) {
      if (cause instanceof BpmnError) {
        error = (BpmnError) cause;
        break;
      }
      cause = cause.getCause();
    }

    if (error != null) {
      ErrorPropagation.propagateError(error, activityExecution);
    } else {
      throw new ActivitiException(exc.getMessage(), exc);
    }

  }
}
 
Example #11
Source File: JavaDelegateInvocation.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public JavaDelegateInvocation(JavaDelegate delegateInstance, DelegateExecution execution) {
  this.delegateInstance = delegateInstance;
  this.execution = execution;
}
 
Example #12
Source File: ServiceTaskJavaDelegateActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ServiceTaskJavaDelegateActivityBehavior(JavaDelegate javaDelegate) {
  this.javaDelegate = javaDelegate;
}
 
Example #13
Source File: BpmnErrorBean.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public JavaDelegate getDelegate() {
  return new ThrowBpmnErrorDelegate();
}
 
Example #14
Source File: BlueprintELResolver.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public void bindService(JavaDelegate delegate, Map props) {
  String name = (String) props.get("osgi.service.blueprint.compname");
  delegateMap.put(name, delegate);
  LOGGER.info("added Activiti service to delegate cache {}", name);
}
 
Example #15
Source File: BpmnErrorBean.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public JavaDelegate getDelegate() {
  return new ThrowBpmnErrorDelegate();
}