Java源码示例:org.activiti.engine.delegate.JavaDelegate

示例1
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);
  }
}
 
示例2
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);
  }
}
 
示例3
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());
  }
}
 
示例4
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);
  }
}
 
示例5
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());
  }
}
 
示例6
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);
  }
}
 
示例7
@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);
}
 
示例8
public JavaDelegateInvocation(JavaDelegate delegateInstance, DelegateExecution execution) {
  this.delegateInstance = delegateInstance;
  this.execution = execution;
}
 
示例9
public ServiceTaskJavaDelegateActivityBehavior(JavaDelegate javaDelegate) {
  this.javaDelegate = javaDelegate;
}
 
示例10
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);
    }

  }
}
 
示例11
public JavaDelegateInvocation(JavaDelegate delegateInstance, DelegateExecution execution) {
  this.delegateInstance = delegateInstance;
  this.execution = execution;
}
 
示例12
public ServiceTaskJavaDelegateActivityBehavior(JavaDelegate javaDelegate) {
  this.javaDelegate = javaDelegate;
}
 
示例13
public JavaDelegate getDelegate() {
  return new ThrowBpmnErrorDelegate();
}
 
示例14
@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);
}
 
示例15
public JavaDelegate getDelegate() {
  return new ThrowBpmnErrorDelegate();
}