Skip to content

Commit 2a90d01

Browse files
author
Tobias Wiessner
committed
Fixed added relationship reader
1 parent 8ab1f14 commit 2a90d01

4 files changed

Lines changed: 67 additions & 16 deletions

File tree

de/uni_stuttgart/ils/reqif4j/reqif/ReqIFConst.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class ReqIFConst {
2020
public final static String SPEC_TYPES = "SPEC-TYPES";
2121
public final static String SPEC_OBJECTS = "SPEC-OBJECTS";
2222
public final static String SPEC_OBJECT = "SPEC-OBJECT";
23+
public final static String SPEC_RELATIONS = "SPEC-RELATIONS";
24+
public final static String SPEC_RELATION = "SPEC-RELATION";
25+
public final static String SOURCE = "SOURCE";
26+
public final static String TARGET = "TARGET";
2327
public final static String SPEC_HIERARCHY = "SPEC-HIERARCHY";
2428
public final static String CHILDREN = "CHILDREN";
2529
public final static String OBJECT = "OBJECT";
@@ -39,8 +43,9 @@ public class ReqIFConst {
3943
public final static String SPEC_OBJECT_TYPE = "SPEC-OBJECT-TYPE";
4044
public final static String SPEC_OBJECT_REF = "SPEC-OBJECT-REF";
4145
public final static String SPEC_RELATION_TYPE = "SPEC-RELATION-TYPE";
46+
public final static String SPEC_RELATION_TYPE_REF = "SPEC-RELATION-TYPE-REF";
4247
public final static String SPEC_OBJECT_TYPE_REF = "SPEC-OBJECT-TYPE-REF";
43-
public final static String SPECIFICATION_TYPE_REF = "SPECIFICATION-TYPE-REF";
48+
public final static String SPEC_TYPE_REF = "SPECIFICATION-TYPE-REF";
4449

4550
public final static String BOOLEAN = "BOOLEAN";
4651
public final static String INTEGER = "INTEGER";

de/uni_stuttgart/ils/reqif4j/reqif/ReqIFCoreContent.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@
66
import java.util.Map;
77

88
import de.uni_stuttgart.ils.reqif4j.datatypes.*;
9+
import de.uni_stuttgart.ils.reqif4j.specification.*;
910
import org.w3c.dom.Element;
1011
import org.w3c.dom.Node;
1112
import org.w3c.dom.NodeList;
1213

13-
import de.uni_stuttgart.ils.reqif4j.specification.SpecHierarchy;
14-
import de.uni_stuttgart.ils.reqif4j.specification.SpecObject;
15-
import de.uni_stuttgart.ils.reqif4j.specification.SpecObjectType;
16-
import de.uni_stuttgart.ils.reqif4j.specification.SpecRelationType;
17-
import de.uni_stuttgart.ils.reqif4j.specification.SpecType;
18-
import de.uni_stuttgart.ils.reqif4j.specification.Specification;
19-
import de.uni_stuttgart.ils.reqif4j.specification.SpecificationType;
20-
2114
public class ReqIFCoreContent {
2215

2316

2417
private Map<String, Datatype> dataTypes = new LinkedHashMap<String, Datatype>();
2518
private Map<String, SpecType> specTypes = new LinkedHashMap<String, SpecType>();
2619
private Map<String, SpecObject> specObjects = new LinkedHashMap<String, SpecObject>();
20+
private Map<String, SpecRelation> specRelation = new LinkedHashMap<>();
2721
private Map<String, Specification> specifications = new LinkedHashMap<String, Specification>();
2822

2923

@@ -52,6 +46,12 @@ public Map<String, SpecObject> getSpecObjects() {
5246
public SpecObject getSpecObject(String id) {
5347
return this.specObjects.get(id);
5448
}
49+
public Map<String, SpecRelation> getSpecRelation(){
50+
return this.specRelation;
51+
}
52+
public SpecRelation getSpecRelation(String id){
53+
return this.specRelation.get(id);
54+
}
5555

5656
public Map<String, Specification> getSpecifications() {
5757
return this.specifications;
@@ -176,7 +176,19 @@ public ReqIFCoreContent(Element coreContent) {
176176
}
177177
}
178178

179-
179+
180+
if(coreContent.getElementsByTagName(ReqIFConst.SPEC_RELATION).getLength() > 0){
181+
NodeList specRelations = coreContent.getElementsByTagName(ReqIFConst.SPEC_RELATION);
182+
for(int specrelation = 0; specrelation < specRelations.getLength(); specrelation++) {
183+
184+
Node specRelation = specRelations.item(specrelation);
185+
String specRelID = specRelation.getAttributes().getNamedItem(ReqIFConst.IDENTIFIER).getTextContent();
186+
String specRelTypeRef = ((Element)specRelation).getElementsByTagName(ReqIFConst.SPEC_RELATION_TYPE_REF).item(0).getTextContent();
187+
188+
189+
this.specRelation.put(specRelID, new SpecRelation(specRelation, this.specTypes.get(specRelTypeRef)));
190+
}
191+
}
180192

181193

182194
if(coreContent.getElementsByTagName(ReqIFConst.SPECIFICATION).getLength() > 0) {
@@ -186,7 +198,7 @@ public ReqIFCoreContent(Element coreContent) {
186198

187199
Node specification = specifications.item(spec);
188200
String specID = specification.getAttributes().getNamedItem(ReqIFConst.IDENTIFIER).getTextContent();
189-
String specTypeRef = ((Element)specification).getElementsByTagName(ReqIFConst.SPECIFICATION_TYPE_REF).item(0).getTextContent();
201+
String specTypeRef = ((Element)specification).getElementsByTagName(ReqIFConst.SPEC_TYPE_REF).item(0).getTextContent();
190202

191203
this.specifications.put(specID, new Specification(specification, this.specTypes.get(specTypeRef), this.specObjects));
192204
}

de/uni_stuttgart/ils/reqif4j/specification/SpecObject.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
public class SpecObject {
1414

1515

16-
private String id;
17-
private SpecType specType;
18-
private String type;
19-
private Map<String, AttributeValue> attributeValues = new HashMap<String, AttributeValue>();
16+
protected String id;
17+
protected SpecType specType;
18+
protected String type;
19+
protected Map<String, AttributeValue> attributeValues = new HashMap<String, AttributeValue>();
2020

2121

2222

@@ -104,7 +104,9 @@ public boolean isText() {
104104
}
105105

106106

107-
107+
public SpecObject(Node specObject){
108+
this.id = specObject.getAttributes().getNamedItem(ReqIFConst.IDENTIFIER).getTextContent();
109+
}
108110

109111
public SpecObject(Node specObject, SpecType specType) {
110112

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de.uni_stuttgart.ils.reqif4j.specification;
2+
3+
import de.uni_stuttgart.ils.reqif4j.reqif.ReqIFConst;
4+
import org.w3c.dom.Element;
5+
import org.w3c.dom.Node;
6+
7+
public class SpecRelation extends SpecObject{
8+
private String sourceObjID;
9+
private String targetObjID;
10+
11+
public SpecRelation(Node specRelation, SpecType specType) {
12+
super(specRelation);
13+
this.specType = specType;
14+
Element eSpecRelation = (Element)specRelation;
15+
// Get target and source node
16+
Element sourceNode = (Element) eSpecRelation.getElementsByTagName(ReqIFConst.SOURCE).item(0);
17+
Element targetNode = (Element) eSpecRelation.getElementsByTagName(ReqIFConst.TARGET).item(0);
18+
sourceObjID = sourceNode.getElementsByTagName(ReqIFConst.SPEC_OBJECT_REF).item(0).getTextContent();
19+
targetObjID = targetNode.getElementsByTagName(ReqIFConst.SPEC_OBJECT_REF).item(0).getTextContent();
20+
// Get relationship type
21+
Element typeNode = (Element) eSpecRelation.getElementsByTagName(ReqIFConst.TYPE).item(0);
22+
this.type = typeNode.getElementsByTagName(ReqIFConst.SPEC_RELATION_TYPE_REF).item(0).getTextContent();
23+
}
24+
25+
public String getSourceObjID() {
26+
return sourceObjID;
27+
}
28+
29+
public String getTargetObjID() {
30+
return targetObjID;
31+
}
32+
}

0 commit comments

Comments
 (0)