提交 ceb67600 编写于 作者: M meyerd

ACT-1099 Parsing results in exception when using text annotation connected with association

上级 35af5f53
......@@ -152,6 +152,10 @@ public class BpmnParse extends Parse {
/** A map for storing sequence flow based on their id during parsing. */
protected Map<String, TransitionImpl> sequenceFlows;
/** A list of all element IDs. This allows us to parse only what we actually support but
* still validate the references among elements we do not support. */
protected List<String> elementIds = new ArrayList<String>();
/**
* Mapping containing values stored during the first phase of parsing since
* other elements can reference these messages.
......@@ -225,6 +229,7 @@ public class BpmnParse extends Parse {
* Parses the 'definitions' root element
*/
protected void parseRootElement() {
collectElementIds();
parseDefinitionsAttributes();
parseImports();
parseItemDefinitions();
......@@ -243,6 +248,10 @@ public class BpmnParse extends Parse {
}
}
protected void collectElementIds() {
rootElement.collectIds(elementIds);
}
protected void parseDefinitionsAttributes() {
String typeLanguage = rootElement.attribute("typeLanguage");
String expressionLanguage = rootElement.attribute("expressionLanguage");
......@@ -598,7 +607,14 @@ public class BpmnParse extends Parse {
ActivityImpl sourceActivity = parentScope.findActivity(sourceRef);
ActivityImpl targetActivity = parentScope.findActivity(targetRef);
if(sourceActivity != null && targetActivity != null) {
// an association may reference elements that are not parsed as activities (like for instance
// test annotations so do not throw an exception if source sourceActivity or targetActivity are null)
// However, we make sure they reference 'something':
if(sourceActivity == null && !elementIds.contains(sourceRef)) {
addError("Invalid reference sourceRef '"+sourceRef+"' of association element ", associationElement);
} else if(targetRef == null && !elementIds.contains(targetRef)) {
addError("Invalid reference targetRef '"+targetRef+"' of association element ", associationElement);
} else {
if(sourceActivity.getProperty("type").equals("compensationBoundaryCatch")) {
Object isForCompensation = targetActivity.getProperty(PROPERTYNAME_IS_FOR_COMPENSATION);
if(isForCompensation == null || !(Boolean) isForCompensation) {
......@@ -608,12 +624,7 @@ public class BpmnParse extends Parse {
compensatedActivity.setProperty(PROPERTYNAME_COMPENSATION_HANDLER_ID, targetActivity.getId());
}
}
}else if(sourceActivity == null) {
addError("invalid sourceRef '"+sourceRef+"' in association", associationElement);
}else if(targetActivity == null) {
addError("invalid targetRef '"+targetRef+"' in association", associationElement);
}
}
}
......@@ -2773,7 +2784,7 @@ public class BpmnParse extends Parse {
if (isExpanded != null) {
activity.setProperty(PROPERTYNAME_ISEXPANDED, parseBooleanAttribute(isExpanded));
}
} else {
} else if(!elementIds.contains(activityId)) { // it might not be an activity but it might still reference 'something'
addError("Invalid reference in 'bpmnElement' attribute, activity " + activityId + "not found", bpmnShapeElement);
}
} else {
......@@ -2797,7 +2808,7 @@ public class BpmnParse extends Parse {
} else {
addError("Minimum 2 waypoint elements must be definted for a 'BPMNEdge'", bpmnEdgeElement);
}
} else {
} else if(!elementIds.contains(sequenceFlowId)) { // it might not be a sequenceFlow but it might still reference 'something'
addError("Invalid reference in 'bpmnElement' attribute, sequenceFlow " + sequenceFlowId + "not found", bpmnEdgeElement);
}
} else {
......
......@@ -169,4 +169,14 @@ public class Element {
public String getText() {
return text.toString();
}
/**
* allows to recursively collect the ids of all elements in the tree.
*/
public void collectIds(List<String> ids) {
ids.add(attribute("id"));
for (Element child : elements) {
child.collectIds(ids);
}
}
}
......@@ -124,6 +124,11 @@ public class BpmnParseTest extends PluggableActivitiTestCase {
}
}
@Deployment
public void testParseDiagramInterchangeElementsForUnknownModelElements() {
}
protected void assertActivityBounds(ActivityImpl activity, int x, int y, int width, int height) {
assertEquals(x, activity.getX());
assertEquals(y, activity.getY());
......
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:signavio="http://www.signavio.com" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="sid-d4beb362-3c19-446a-81ac-34290495bd23" exporter="Signavio Process Editor, http://www.signavio.com" exporterVersion="5.2.1" targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL">
<process id="TestAnnotation" isExecutable="true">
<startEvent id="startEvent_1">
<outgoing>sequenceFlow_14</outgoing>
</startEvent>
<userTask id="Task_5" name="Task">
<incoming>sequenceFlow_14</incoming>
<outgoing>sequenceFlow_15</outgoing>
</userTask>
<endEvent id="endEvent_10">
<incoming>sequenceFlow_15</incoming>
</endEvent>
<sequenceFlow id="sequenceFlow_14" sourceRef="startEvent_1" targetRef="Task_5"/>
<sequenceFlow id="sequenceFlow_15" sourceRef="Task_5" targetRef="endEvent_10"/>
<association id="association_16" sourceRef="Task_5" targetRef="textAnnotation_17"/>
<textAnnotation id="textAnnotation_17">
<text>Some Text</text>
</textAnnotation>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_20">
<bpmndi:BPMNPlane id="BPMNPlane_20" bpmnElement="TestAnnotation">
<bpmndi:BPMNShape id="BPMNShape_20" bpmnElement="startEvent_1">
<omgdc:Bounds height="30.0" width="30.0" x="135.0" y="90.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_22" bpmnElement="Task_5">
<omgdc:Bounds height="80.0" width="100.0" x="210.0" y="65.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_24" bpmnElement="endEvent_10">
<omgdc:Bounds height="28.0" width="28.0" x="355.0" y="91.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_26" bpmnElement="textAnnotation_17">
<omgdc:Bounds height="50.0" width="100.0" x="285.0" y="195.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_28" bpmnElement="sequenceFlow_15" sourceElement="BPMNShape_22" targetElement="BPMNShape_24">
<omgdi:waypoint xsi:type="omgdc:Point" x="310.0" y="105.0"/>
<omgdi:waypoint xsi:type="omgdc:Point" x="355.0" y="105.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_31" bpmnElement="association_16" sourceElement="BPMNShape_22" targetElement="BPMNShape_26">
<omgdi:waypoint xsi:type="omgdc:Point" x="260.0" y="145.0"/>
<omgdi:waypoint xsi:type="omgdc:Point" x="335.0" y="195.0"/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_34" bpmnElement="sequenceFlow_14" sourceElement="BPMNShape_20" targetElement="BPMNShape_22">
<omgdi:waypoint xsi:type="omgdc:Point" x="165.0" y="105.0"/>
<omgdi:waypoint xsi:type="omgdc:Point" x="210.0" y="105.0"/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册