Search in sources :

Example 41 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method parseBoundaryEvents.

/**
 * Parses the boundary events of a certain 'level' (process, subprocess or
 * other scope).
 *
 * Note that the boundary events are not parsed during the parsing of the bpmn
 * activities, since the semantics are different (boundaryEvent needs to be
 * added as nested activity to the reference activity on PVM level).
 *
 * @param parentElement
 *          The 'parent' element that contains the activities (process,
 *          subprocess).
 * @param flowScope
 *          The {@link ScopeImpl} to which the activities must be added.
 */
public void parseBoundaryEvents(Element parentElement, ScopeImpl flowScope) {
    for (Element boundaryEventElement : parentElement.elements("boundaryEvent")) {
        // The boundary event is attached to an activity, reference by the
        // 'attachedToRef' attribute
        String attachedToRef = boundaryEventElement.attribute("attachedToRef");
        if (attachedToRef == null || attachedToRef.equals("")) {
            addError("AttachedToRef is required when using a timerEventDefinition", boundaryEventElement);
        }
        // Representation structure-wise is a nested activity in the activity to
        // which its attached
        String id = boundaryEventElement.attribute("id");
        LOG.parsingElement("boundary event", id);
        // Depending on the sub-element definition, the correct activityBehavior
        // parsing is selected
        Element timerEventDefinition = boundaryEventElement.element(TIMER_EVENT_DEFINITION);
        Element errorEventDefinition = boundaryEventElement.element(ERROR_EVENT_DEFINITION);
        Element signalEventDefinition = boundaryEventElement.element(SIGNAL_EVENT_DEFINITION);
        Element cancelEventDefinition = boundaryEventElement.element(CANCEL_EVENT_DEFINITION);
        Element compensateEventDefinition = boundaryEventElement.element(COMPENSATE_EVENT_DEFINITION);
        Element messageEventDefinition = boundaryEventElement.element(MESSAGE_EVENT_DEFINITION);
        Element escalationEventDefinition = boundaryEventElement.element(ESCALATION_EVENT_DEFINITION);
        Element conditionalEventDefinition = boundaryEventElement.element(CONDITIONAL_EVENT_DEFINITION);
        // create the boundary event activity
        ActivityImpl boundaryEventActivity = createActivityOnScope(boundaryEventElement, flowScope);
        parseAsynchronousContinuation(boundaryEventElement, boundaryEventActivity);
        ActivityImpl attachedActivity = flowScope.findActivityAtLevelOfSubprocess(attachedToRef);
        if (attachedActivity == null) {
            addError("Invalid reference in boundary event. Make sure that the referenced activity is defined in the same scope as the boundary event", boundaryEventElement);
        }
        // determine the correct event scope (the scope in which the boundary event catches events)
        if (compensateEventDefinition == null) {
            ActivityImpl multiInstanceScope = getMultiInstanceScope(attachedActivity);
            if (multiInstanceScope != null) {
                // if the boundary event is attached to a multi instance activity,
                // then the scope of the boundary event is the multi instance body.
                boundaryEventActivity.setEventScope(multiInstanceScope);
            } else {
                attachedActivity.setScope(true);
                boundaryEventActivity.setEventScope(attachedActivity);
            }
        } else {
            boundaryEventActivity.setEventScope(attachedActivity);
        }
        // except escalation, by default is assumed to abort the activity
        String cancelActivityAttr = boundaryEventElement.attribute("cancelActivity", TRUE);
        boolean isCancelActivity = Boolean.valueOf(cancelActivityAttr);
        // determine start behavior
        if (isCancelActivity) {
            boundaryEventActivity.setActivityStartBehavior(ActivityStartBehavior.CANCEL_EVENT_SCOPE);
        } else {
            boundaryEventActivity.setActivityStartBehavior(ActivityStartBehavior.CONCURRENT_IN_FLOW_SCOPE);
        }
        // Catch event behavior is the same for most types
        ActivityBehavior behavior = new BoundaryEventActivityBehavior();
        if (timerEventDefinition != null) {
            parseBoundaryTimerEventDefinition(timerEventDefinition, isCancelActivity, boundaryEventActivity);
        } else if (errorEventDefinition != null) {
            parseBoundaryErrorEventDefinition(errorEventDefinition, boundaryEventActivity);
        } else if (signalEventDefinition != null) {
            parseBoundarySignalEventDefinition(signalEventDefinition, isCancelActivity, boundaryEventActivity);
        } else if (cancelEventDefinition != null) {
            behavior = parseBoundaryCancelEventDefinition(cancelEventDefinition, boundaryEventActivity);
        } else if (compensateEventDefinition != null) {
            parseBoundaryCompensateEventDefinition(compensateEventDefinition, boundaryEventActivity);
        } else if (messageEventDefinition != null) {
            parseBoundaryMessageEventDefinition(messageEventDefinition, isCancelActivity, boundaryEventActivity);
        } else if (escalationEventDefinition != null) {
            if (attachedActivity.isSubProcessScope() || attachedActivity.getActivityBehavior() instanceof CallActivityBehavior) {
                parseBoundaryEscalationEventDefinition(escalationEventDefinition, isCancelActivity, boundaryEventActivity);
            } else {
                addError("An escalation boundary event should only be attached to a subprocess or a call activity", boundaryEventElement);
            }
        } else if (conditionalEventDefinition != null) {
            behavior = parseBoundaryConditionalEventDefinition(conditionalEventDefinition, isCancelActivity, boundaryEventActivity);
        } else {
            addError("Unsupported boundary event type", boundaryEventElement);
        }
        ensureNoIoMappingDefined(boundaryEventElement);
        for (BpmnParseListener parseListener : parseListeners) {
            parseListener.parseBoundaryEvent(boundaryEventElement, flowScope, boundaryEventActivity);
        }
        boundaryEventActivity.setActivityBehavior(behavior);
        parseExecutionListenersOnScope(boundaryEventElement, boundaryEventActivity);
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element) ActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)

Example 42 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method parseSequenceFlowConditionExpression.

/**
 * Parses a condition expression on a sequence flow.
 *
 * @param seqFlowElement
 *          The 'sequenceFlow' element that can contain a condition.
 * @param seqFlow
 *          The sequenceFlow object representation to which the condition must
 *          be added.
 */
public void parseSequenceFlowConditionExpression(Element seqFlowElement, TransitionImpl seqFlow) {
    Element conditionExprElement = seqFlowElement.element(CONDITION_EXPRESSION);
    if (conditionExprElement != null) {
        Condition condition = parseConditionExpression(conditionExprElement);
        seqFlow.setProperty(PROPERTYNAME_CONDITION_TEXT, conditionExprElement.getText().trim());
        seqFlow.setProperty(PROPERTYNAME_CONDITION, condition);
    }
}
Also used : ScriptCondition(org.camunda.bpm.engine.impl.scripting.ScriptCondition) Condition(org.camunda.bpm.engine.impl.Condition) Element(org.camunda.bpm.engine.impl.util.xml.Element)

Example 43 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method getStringValueFromAttributeOrElement.

protected String getStringValueFromAttributeOrElement(String attributeName, String elementName, Element element) {
    String value = null;
    String attributeValue = element.attribute(attributeName);
    Element childElement = element.elementNS(CAMUNDA_BPMN_EXTENSIONS_NS, elementName);
    String stringElementText = null;
    if (attributeValue != null && childElement != null) {
        addError("Can't use attribute '" + attributeName + "' and element '" + elementName + "' together, only use one", element);
    } else if (childElement != null) {
        stringElementText = childElement.getText();
        if (stringElementText == null || stringElementText.length() == 0) {
            addError("No valid value found in attribute '" + attributeName + "' nor element '" + elementName + "'", element);
        } else {
            // Use text of element
            value = stringElementText;
        }
    } else if (attributeValue != null && attributeValue.length() > 0) {
        // Using attribute
        value = attributeValue;
    }
    return value;
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element)

Example 44 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method parseTaskListener.

protected TaskListener parseTaskListener(Element taskListenerElement) {
    TaskListener taskListener = null;
    String className = taskListenerElement.attribute(PROPERTYNAME_CLASS);
    String expression = taskListenerElement.attribute(PROPERTYNAME_EXPRESSION);
    String delegateExpression = taskListenerElement.attribute(PROPERTYNAME_DELEGATE_EXPRESSION);
    Element scriptElement = taskListenerElement.elementNS(CAMUNDA_BPMN_EXTENSIONS_NS, "script");
    if (className != null) {
        taskListener = new ClassDelegateTaskListener(className, parseFieldDeclarations(taskListenerElement));
    } else if (expression != null) {
        taskListener = new ExpressionTaskListener(expressionManager.createExpression(expression));
    } else if (delegateExpression != null) {
        taskListener = new DelegateExpressionTaskListener(expressionManager.createExpression(delegateExpression), parseFieldDeclarations(taskListenerElement));
    } else if (scriptElement != null) {
        try {
            ExecutableScript executableScript = parseCamundaScript(scriptElement);
            if (executableScript != null) {
                taskListener = new ScriptTaskListener(executableScript);
            }
        } catch (BpmnParseException e) {
            addError(e);
        }
    } else {
        addError("Element 'class', 'expression', 'delegateExpression' or 'script' is mandatory on taskListener", taskListenerElement);
    }
    return taskListener;
}
Also used : DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) BpmnParseException(org.camunda.bpm.engine.BpmnParseException) Element(org.camunda.bpm.engine.impl.util.xml.Element) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener)

Example 45 with Element

use of org.camunda.bpm.engine.impl.util.xml.Element in project camunda-bpm-platform by camunda.

the class BpmnParse method parseAssociations.

protected void parseAssociations(Element scopeElement, ScopeImpl parentScope, Map<String, Element> compensationHandlers) {
    for (Element associationElement : scopeElement.elements("association")) {
        String sourceRef = associationElement.attribute("sourceRef");
        if (sourceRef == null) {
            addError("association element missing attribute 'sourceRef'", associationElement);
        }
        String targetRef = associationElement.attribute("targetRef");
        if (targetRef == null) {
            addError("association element missing attribute 'targetRef'", associationElement);
        }
        ActivityImpl sourceActivity = parentScope.findActivity(sourceRef);
        ActivityImpl targetActivity = parentScope.findActivity(targetRef);
        // However, we make sure they reference 'something':
        if (sourceActivity == null && !elementIds.contains(sourceRef)) {
            addError("Invalid reference sourceRef '" + sourceRef + "' of association element ", associationElement);
        } else if (targetActivity == null && !elementIds.contains(targetRef)) {
            addError("Invalid reference targetRef '" + targetRef + "' of association element ", associationElement);
        } else {
            if (sourceActivity != null && ActivityTypes.BOUNDARY_COMPENSATION.equals(sourceActivity.getProperty(BpmnProperties.TYPE.getName()))) {
                if (targetActivity == null && compensationHandlers.containsKey(targetRef)) {
                    targetActivity = parseCompensationHandlerForCompensationBoundaryEvent(parentScope, sourceActivity, targetRef, compensationHandlers);
                    compensationHandlers.remove(targetActivity.getId());
                }
                if (targetActivity != null) {
                    parseAssociationOfCompensationBoundaryEvent(associationElement, sourceActivity, targetActivity);
                }
            }
        }
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element)

Aggregations

Element (org.camunda.bpm.engine.impl.util.xml.Element)60 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 BpmnParseException (org.camunda.bpm.engine.BpmnParseException)4 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)4 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)3 ProcessEngineXml (org.camunda.bpm.container.impl.metadata.spi.ProcessEngineXml)2 TaskListener (org.camunda.bpm.engine.delegate.TaskListener)2 Condition (org.camunda.bpm.engine.impl.Condition)2 IoMapping (org.camunda.bpm.engine.impl.core.variable.mapping.IoMapping)2 ParameterValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.ParameterValueProvider)2 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)2 ScriptCondition (org.camunda.bpm.engine.impl.scripting.ScriptCondition)2 ClassDelegateTaskListener (org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener)2 DelegateExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)2 ExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener)2 ScriptTaskListener (org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener)2 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 ProcessArchiveXml (org.camunda.bpm.application.impl.metadata.spi.ProcessArchiveXml)1