org.camunda.bpm.engine.impl.bpmn.behavior.CallableElementActivityBehavior Maven / Gradle / Ivy
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.engine.impl.bpmn.behavior;
import java.util.concurrent.Callable;
import org.camunda.bpm.application.InvocationContext;
import org.camunda.bpm.application.ProcessApplicationReference;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.DelegateVariableMapping;
import org.camunda.bpm.engine.delegate.Expression;
import org.camunda.bpm.engine.delegate.VariableScope;
import static org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.NUMBER_OF_ACTIVE_INSTANCES;
import static org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.NUMBER_OF_COMPLETED_INSTANCES;
import static org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.NUMBER_OF_INSTANCES;
import org.camunda.bpm.engine.impl.context.Context;
import org.camunda.bpm.engine.impl.context.ProcessApplicationContextUtil;
import org.camunda.bpm.engine.impl.core.model.BaseCallableElement.CallableElementBinding;
import org.camunda.bpm.engine.impl.core.model.CallableElement;
import org.camunda.bpm.engine.impl.delegate.DelegateInvocation;
import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity;
import org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution;
import org.camunda.bpm.engine.impl.pvm.delegate.SubProcessActivityBehavior;
import org.camunda.bpm.engine.impl.util.ClassDelegateUtil;
import org.camunda.bpm.engine.variable.VariableMap;
/**
* @author Roman Smirnov
*
*/
public abstract class CallableElementActivityBehavior extends AbstractBpmnActivityBehavior implements SubProcessActivityBehavior {
protected String[] variablesFilter = { NUMBER_OF_INSTANCES, NUMBER_OF_ACTIVE_INSTANCES, NUMBER_OF_COMPLETED_INSTANCES };
protected CallableElement callableElement;
/**
* The expression which identifies the delegation for the variable mapping.
*/
protected Expression expression;
/**
* The class name of the delegated variable mapping, which should be used.
*/
protected String className;
public CallableElementActivityBehavior() {
}
public CallableElementActivityBehavior(String className) {
this.className = className;
}
public CallableElementActivityBehavior(Expression expression) {
this.expression = expression;
}
protected DelegateVariableMapping getDelegateVariableMapping(Object instance) {
if (instance instanceof DelegateVariableMapping) {
return (DelegateVariableMapping) instance;
} else {
throw LOG.missingDelegateVariableMappingParentClassException(
instance.getClass().getName(),
DelegateVariableMapping.class.getName());
}
}
protected DelegateVariableMapping resolveDelegation(ActivityExecution execution) {
Object delegate = resolveDelegateClass(execution);
return delegate != null ? getDelegateVariableMapping(delegate) : null;
}
public Object resolveDelegateClass(final ActivityExecution execution) {
ProcessApplicationReference targetProcessApplication
= ProcessApplicationContextUtil.getTargetProcessApplication((ExecutionEntity) execution);
if (ProcessApplicationContextUtil.requiresContextSwitch(targetProcessApplication)) {
return Context.executeWithinProcessApplication(new Callable