}
Element miLoopCharacteristics = activityElement.element("multiInstanceLoopCharacteristics");
if (miLoopCharacteristics != null) {
MultiInstanceActivityBehavior miActivityBehavior = null;
boolean isSequential = parseBooleanAttribute(miLoopCharacteristics.attribute("isSequential"), false);
if (isSequential) {
miActivityBehavior = new SequentialMultiInstanceBehavior(activity, (AbstractBpmnActivityBehavior) activity.getActivityBehavior());
} else {
miActivityBehavior = new ParallelMultiInstanceBehavior(activity, (AbstractBpmnActivityBehavior) activity.getActivityBehavior());
}
activity.setScope(true);
activity.setProperty("multiInstance", isSequential ? "sequential" : "parallel");
activity.setActivityBehavior(miActivityBehavior);
// loopCardinality
Element loopCardinality = miLoopCharacteristics.element("loopCardinality");
if (loopCardinality != null) {
String loopCardinalityText = loopCardinality.getText();
if (loopCardinalityText == null || "".equals(loopCardinalityText)) {
addError("loopCardinality must be defined for a multiInstanceLoopCharacteristics definition ", miLoopCharacteristics);
}
miActivityBehavior.setLoopCardinalityExpression(expressionManager.createExpression(loopCardinalityText));
}
// completionCondition
Element completionCondition = miLoopCharacteristics.element("completionCondition");
if (completionCondition != null) {
String completionConditionText = completionCondition.getText();
miActivityBehavior.setCompletionConditionExpression(expressionManager.createExpression(completionConditionText));
}
// activiti:collection
String collection = miLoopCharacteristics.attributeNS(BpmnParser.ACTIVITI_BPMN_EXTENSIONS_NS, "collection");
if (collection != null) {
if (collection.contains("{")) {
miActivityBehavior.setCollectionExpression(expressionManager.createExpression(collection));
} else {
miActivityBehavior.setCollectionVariable(collection);
}
}
// loopDataInputRef
Element loopDataInputRef = miLoopCharacteristics.element("loopDataInputRef");
if (loopDataInputRef != null) {
String loopDataInputRefText = loopDataInputRef.getText();
if (loopDataInputRefText != null) {
if (loopDataInputRefText.contains("{")) {
miActivityBehavior.setCollectionExpression(expressionManager.createExpression(loopDataInputRefText));
} else {
miActivityBehavior.setCollectionVariable(loopDataInputRefText);
}
}
}
// activiti:elementVariable
String elementVariable = miLoopCharacteristics.attributeNS(BpmnParser.ACTIVITI_BPMN_EXTENSIONS_NS, "elementVariable");
if (elementVariable != null) {
miActivityBehavior.setCollectionElementVariable(elementVariable);
}
// dataInputItem
Element inputDataItem = miLoopCharacteristics.element("inputDataItem");
if (inputDataItem != null) {
String inputDataItemName = inputDataItem.attribute("name");
miActivityBehavior.setCollectionElementVariable(inputDataItemName);
}
// Validation
if (miActivityBehavior.getLoopCardinalityExpression() == null && miActivityBehavior.getCollectionExpression() == null
&& miActivityBehavior.getCollectionVariable() == null) {
addError("Either loopCardinality or loopDataInputRef/activiti:collection must been set", miLoopCharacteristics);
}
// Validation
if (miActivityBehavior.getCollectionExpression() == null && miActivityBehavior.getCollectionVariable() == null
&& miActivityBehavior.getCollectionElementVariable() != null) {
addError("LoopDataInputRef/activiti:collection must be set when using inputDataItem or activiti:elementVariable", miLoopCharacteristics);
}
for (BpmnParseListener parseListener : parseListeners) {
parseListener.parseMultiInstanceLoopCharacteristics(activityElement, miLoopCharacteristics, activity);