All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.activiti.engine.impl.bpmn.parser.handler.ServiceTaskParseHandler Maven / Gradle / Ivy

The newest version!
/* Licensed under the Apache License, Version 2.0 (the "License");
 * 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.activiti.engine.impl.bpmn.parser.handler;

import org.activiti.bpmn.constants.BpmnXMLConstants;
import org.activiti.bpmn.model.BaseElement;
import org.activiti.bpmn.model.DataAssociation;
import org.activiti.bpmn.model.ImplementationType;
import org.activiti.bpmn.model.ServiceTask;
import org.activiti.engine.impl.bpmn.behavior.WebServiceActivityBehavior;
import org.activiti.engine.impl.bpmn.data.AbstractDataAssociation;
import org.activiti.engine.impl.bpmn.data.IOSpecification;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.apache.commons.lang.StringUtils;


/**
 * @author Joram Barrez
 */
public class ServiceTaskParseHandler extends AbstractExternalInvocationBpmnParseHandler {
  
  public Class< ? extends BaseElement> getHandledType() {
    return ServiceTask.class;
  }
  
  protected void executeParse(BpmnParse bpmnParse, ServiceTask serviceTask) {
    
      ActivityImpl activity = createActivityOnCurrentScope(bpmnParse, serviceTask, BpmnXMLConstants.ELEMENT_TASK_SERVICE);
      activity.setAsync(serviceTask.isAsynchronous());
      activity.setExclusive(!serviceTask.isNotExclusive());

      // Email, Mule and Shell service tasks
      if (StringUtils.isNotEmpty(serviceTask.getType())) {
        
        if (serviceTask.getType().equalsIgnoreCase("mail")) {
          validateFieldDeclarationsForEmail(bpmnParse, serviceTask, serviceTask.getFieldExtensions());
          activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createMailActivityBehavior(serviceTask));
          
        } else if (serviceTask.getType().equalsIgnoreCase("mule")) {
          activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createMuleActivityBehavior(serviceTask, bpmnParse.getBpmnModel()));
          
        } else if (serviceTask.getType().equalsIgnoreCase("camel")) {
          activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createCamelActivityBehavior(serviceTask, bpmnParse.getBpmnModel()));
          
        } else if (serviceTask.getType().equalsIgnoreCase("shell")) {
          validateFieldDeclarationsForShell(bpmnParse, serviceTask, serviceTask.getFieldExtensions());
          activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createShellActivityBehavior(serviceTask));
          
        } else {
          bpmnParse.getBpmnModel().addProblem("Invalid usage of type attribute: '" + serviceTask.getType() + "'.", serviceTask);
        }

      // activiti:class
      } else if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equalsIgnoreCase(serviceTask.getImplementationType())) {
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createClassDelegateServiceTask(serviceTask));
        
      // activiti:delegateExpression
      } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equalsIgnoreCase(serviceTask.getImplementationType())) {
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createServiceTaskDelegateExpressionActivityBehavior(serviceTask));

      // activiti:expression      
      } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equalsIgnoreCase(serviceTask.getImplementationType())) {
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createServiceTaskExpressionActivityBehavior(serviceTask));

      // Webservice   
      } else if (ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE.equalsIgnoreCase(serviceTask.getImplementationType()) && 
          StringUtils.isNotEmpty(serviceTask.getOperationRef())) {
        
        if (!bpmnParse.getOperations().containsKey(serviceTask.getOperationRef())) {
          bpmnParse.getBpmnModel().addProblem(serviceTask.getOperationRef() + " does not exist", serviceTask);
        } else {
          
          WebServiceActivityBehavior webServiceActivityBehavior = bpmnParse.getActivityBehaviorFactory().createWebServiceActivityBehavior(serviceTask);
          webServiceActivityBehavior.setOperation(bpmnParse.getOperations().get(serviceTask.getOperationRef()));

          if (serviceTask.getIoSpecification() != null) {
            IOSpecification ioSpecification = createIOSpecification(bpmnParse, serviceTask.getIoSpecification());
            webServiceActivityBehavior.setIoSpecification(ioSpecification);
          }

          for (DataAssociation dataAssociationElement : serviceTask.getDataInputAssociations()) {
            AbstractDataAssociation dataAssociation = createDataInputAssociation(bpmnParse, dataAssociationElement);
            webServiceActivityBehavior.addDataInputAssociation(dataAssociation);
          }

          for (DataAssociation dataAssociationElement : serviceTask.getDataOutputAssociations()) {
            AbstractDataAssociation dataAssociation = createDataOutputAssociation(bpmnParse, dataAssociationElement);
            webServiceActivityBehavior.addDataOutputAssociation(dataAssociation);
          }

          activity.setActivityBehavior(webServiceActivityBehavior);
        }
      } else {
        bpmnParse.getBpmnModel().addProblem("One of the attributes 'class', 'delegateExpression', 'type', 'operation', or 'expression' is mandatory on serviceTask.", serviceTask);
      }

    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy