Skip to content

Commit 28a0b44

Browse files
committed
Issue FUML15-17 - Updated DestroyObjecActionActivation::destroyObject().
1 parent 26865ea commit 28a0b44

4 files changed

Lines changed: 3750 additions & 11629 deletions

File tree

org.modeldriven.fuml/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>fuml</artifactId>
66
<packaging>jar</packaging>
77
<name>FUML Reference Implementation</name>
8-
<version>1.4.0</version>
8+
<version>1.4.1-SNAPSHOT</version>
99
<description>This open source software is a reference implementation, consisting of software and related files, for the OMG specification called the Semantics of a Foundational Subset for Executable UML Models (fUML). The reference implementation is intended to implement the execution semantics of UML activity models, accepting an XMI file from a conformant UML model as its input and providing an execution trace of the selected activity model(s) as its output. The core execution engine, which is directly generated from the normative syntactic and semantic models for fUML, may also be used as a library implementation of fUML in other software.</description>
1010
<url>http:/fuml.modeldriven.org</url>
1111
<licenses>

org.modeldriven.fuml/src/main/java/fuml/semantics/actions/DestroyObjectActionActivation.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public class DestroyObjectActionActivation extends
3030

3131
public void doAction() {
3232
// Get the value on the target input pin.
33-
// If the value is not a reference, then the action has no effect.
33+
// If the value is not a reference, the action has no effect.
3434
// Otherwise, do the following.
3535
// If isDestroyLinks is true, destroy all links in which the referent
3636
// participates.
3737
// If isDestroyOwnedObjects is true, destroy all objects owned by the
38-
// referent via composition links.
38+
// referent via either composite attributes or composition links.
3939
// Destroy the referent object.
4040

4141
DestroyObjectAction action = (DestroyObjectAction) (this.node);
@@ -51,13 +51,11 @@ public void destroyObject(fuml.semantics.values.Value value,
5151
// If the given value is a reference, then destroy the referenced
5252
// object, per the given destroy action attribute values.
5353

54-
// Debug.println("[destroyObject] object = " + value.objectId());
55-
5654
if (value instanceof Reference) {
5755
Reference reference = (Reference) value;
56+
Debug.println("[destroyObject] object = " + reference.referent.identifier);
5857

5958
if (isDestroyLinks | isDestroyOwnedObjects) {
60-
Debug.println("[destroyObject] Destroying links...");
6159
ExtensionalValueList extensionalValues = this
6260
.getExecutionLocus().extensionalValues;
6361
for (int i = 0; i < extensionalValues.size(); i++) {
@@ -66,10 +64,16 @@ public void destroyObject(fuml.semantics.values.Value value,
6664
if (extensionalValue instanceof Link) {
6765
Link link = (Link) extensionalValue;
6866
if (this.valueParticipatesInLink(reference, link)) {
69-
if (isDestroyLinks
70-
| this.objectIsComposite(reference, link)) {
71-
// Debug.println("[destroyObject] Destroying link "
72-
// + link.objectId());
67+
if (isDestroyOwnedObjects) {
68+
Value compositeValue =
69+
this.getCompositeValue(reference, link);
70+
if (compositeValue != null) {
71+
Debug.println("[destroyObject] Destroying (linked) owned object ...");
72+
this.destroyObject(compositeValue, isDestroyLinks,
73+
isDestroyOwnedObjects);
74+
}
75+
}
76+
if (isDestroyLinks & !link.getTypes().isEmpty()) {
7377
link.destroy();
7478
}
7579
}
@@ -78,12 +82,12 @@ public void destroyObject(fuml.semantics.values.Value value,
7882
}
7983

8084
if (isDestroyOwnedObjects) {
81-
Debug.println("[destroyObject] Destroying owned objects...");
8285
FeatureValueList objectFeatureValues = reference
8386
.getFeatureValues();
8487
for (int i = 0; i < objectFeatureValues.size(); i++) {
8588
FeatureValue featureValue = objectFeatureValues.getValue(i);
8689
if (((Property) featureValue.feature).aggregation == AggregationKind.composite) {
90+
Debug.println("[destroyObject] Destroying owned objects...");
8791
ValueList values = featureValue.values;
8892
for (int j = 0; j < values.size(); j++) {
8993
Value ownedValue = values.getValue(j);
@@ -93,31 +97,32 @@ public void destroyObject(fuml.semantics.values.Value value,
9397
}
9498
}
9599
}
96-
100+
97101
reference.destroy();
98102
}
99103
} // destroyObject
100104

101-
public boolean objectIsComposite(
105+
public Value getCompositeValue(
102106
fuml.semantics.structuredclassifiers.Reference reference,
103107
fuml.semantics.structuredclassifiers.Link link) {
104-
// Test whether the given reference participates in the given link as a
105-
// composite.
108+
// If the given reference participates in the given link as a composite,
109+
// then return the opposite value. Otherwise return null.
106110

107111
FeatureValueList linkFeatureValues = link.getFeatureValues();
108112

109-
boolean isComposite = false;
113+
Value compositeValue = null;
110114
int i = 1;
111-
while (!isComposite & i <= linkFeatureValues.size()) {
115+
while (compositeValue == null & i <= linkFeatureValues.size()) {
112116
FeatureValue featureValue = linkFeatureValues.getValue(i - 1);
113-
if (!featureValue.values.getValue(0).equals(reference)
117+
Value value = featureValue.values.getValue(0);
118+
if (!value.equals(reference)
114119
& ((Property) featureValue.feature).aggregation == AggregationKind.composite) {
115-
isComposite = true;
120+
compositeValue = value;
116121
}
117122
i = i + 1;
118123
}
119124

120-
return isComposite;
125+
return compositeValue;
121126

122127
} // objectIsComposite
123128

org.modeldriven.fuml/src/test/java/org/modeldriven/fuml/test/model/ExecutionTestCase.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,29 @@ public void testTestClassObjectDestroyer() throws Exception {
154154
Value value = output.get(0).values.get(0);
155155
assertTrue("value.getTypes().isEmpty()", value.getTypes().isEmpty());
156156
}
157+
158+
public void testTestCompositeObjectDestroyer() throws Exception {
159+
ParameterValueList output = execute("TestCompositeObjectDestroyer");
160+
log.info("done");
161+
162+
assertEquals("output.size()", 4, output.size());
163+
164+
ValueList compositeOut = output.get(0).values;
165+
assertEquals("compositeOut.size()", 1, compositeOut.size());
166+
assertTrue("compositeOut.getTypes().isEmpty()", compositeOut.get(0).getTypes().isEmpty());
167+
168+
ValueList object1Out = output.get(1).values;
169+
assertEquals("object1Out.size()", 1, object1Out.size());
170+
assertTrue("object1Out.getTypes().isEmpty()", object1Out.get(0).getTypes().isEmpty());
171+
172+
ValueList object2Out = output.get(2).values;
173+
assertEquals("object2Out.size()", 1, object2Out.size());
174+
assertTrue("object2Out.getTypes().isEmpty()", object2Out.get(0).getTypes().isEmpty());
175+
176+
ValueList assocOut = output.get(3).values;
177+
assertEquals("assocOut.size()", 0, assocOut.size());
178+
}
179+
157180
public void testTestClassWriterReader() throws Exception {
158181
ParameterValueList output = execute("TestClassWriterReader");
159182
log.info("done");

0 commit comments

Comments
 (0)