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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
}
}
}
Aggregations