Skip to content

Commit 551c1eb

Browse files
committed
FUML15-13 Fixed unmarshalling logic for instances of signal subtypes.
- Updated fUML-Tests.mdxml with a test for this case.
1 parent 5438616 commit 551c1eb

9 files changed

Lines changed: 1854 additions & 2285 deletions

File tree

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import fuml.Debug;
1616
import fuml.semantics.activities.ActivityNodeActivationGroup;
17+
import fuml.semantics.activities.TokenList;
18+
import fuml.semantics.commonbehavior.EventOccurrence;
1719
import fuml.semantics.commonbehavior.ParameterValue;
1820
import fuml.semantics.commonbehavior.ParameterValueList;
1921
import fuml.semantics.commonbehavior.SignalEventOccurrence;
@@ -25,10 +27,9 @@
2527
import fuml.syntax.activities.ActivityNode;
2628
import fuml.syntax.commonbehavior.TriggerList;
2729

28-
public class AcceptEventActionActivation extends
29-
fuml.semantics.actions.ActionActivation {
30+
public class AcceptEventActionActivation extends ActionActivation {
3031

31-
public fuml.semantics.actions.AcceptEventActionEventAccepter eventAccepter = null;
32+
public AcceptEventActionEventAccepter eventAccepter = null;
3233
public Boolean waiting = false;
3334

3435
public void initialize(ActivityNode node, ActivityNodeActivationGroup group) {
@@ -49,8 +50,7 @@ public void run() {
4950
this.waiting = false;
5051
} // run
5152

52-
public void fire(
53-
fuml.semantics.activities.TokenList incomingTokens) {
53+
public void fire(TokenList incomingTokens) {
5454
// Register the event accepter for this accept event action activation
5555
// with the context object of the enclosing activity execution
5656
// and wait for an event to be accepted.
@@ -84,8 +84,7 @@ public void doAction() {
8484
return;
8585
} // doAction
8686

87-
public void accept(
88-
fuml.semantics.commonbehavior.EventOccurrence eventOccurrence) {
87+
public void accept(EventOccurrence eventOccurrence) {
8988
// Accept the given event occurrence.
9089
// If the action does not unmarshall, then, if the event occurrence is
9190
// a signal event occurrence, place the signal instance of the signal
@@ -115,7 +114,8 @@ public void accept(
115114
}
116115
}
117116
} else {
118-
ParameterValueList parameterValues = eventOccurrence.getParameterValues();
117+
ParameterValueList parameterValues =
118+
eventOccurrence.getParameterValues(action.trigger.get(0).event);
119119
for (int i = 0; i < parameterValues.size(); i++) {
120120
ParameterValue parameterValue = parameterValues.getValue(i);
121121
OutputPin resultPin = resultPins.getValue(i);
@@ -135,8 +135,7 @@ public void accept(
135135

136136
} // accept
137137

138-
public boolean match(
139-
fuml.semantics.commonbehavior.EventOccurrence eventOccurrence) {
138+
public boolean match(EventOccurrence eventOccurrence) {
140139
// Return true if the given event occurrence matches a trigger of the
141140
// accept event action of this activation.
142141

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
import fuml.syntax.actions.OutputPin;
1616
import fuml.syntax.actions.OutputPinList;
1717
import fuml.syntax.actions.UnmarshallAction;
18+
import fuml.syntax.classification.Classifier;
1819

1920
public class UnmarshallActionActivation extends ActionActivation {
2021

2122
@Override
2223
public void doAction() {
2324
UnmarshallAction action = (UnmarshallAction) this.node;
25+
Classifier unmarshallType = action.unmarshallType;
2426
OutputPinList resultPins = action.result;
2527

2628
Value value = this.takeTokens(action.object).getValue(0);
2729

2830
if (value instanceof StructuredValue) {
29-
FeatureValueList featureValues = ((StructuredValue)value).getFeatureValues();
31+
FeatureValueList featureValues = ((StructuredValue)value).getMemberValues(unmarshallType);
3032
for (int i=0; i < featureValues.size(); i++) {
3133
FeatureValue featureValue = featureValues.getValue(i);
3234
OutputPin resultPin = resultPins.getValue(i);

org.modeldriven.fuml/src/main/java/fuml/semantics/commonbehavior/CallEventOccurrence.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import fuml.syntax.classification.Operation;
1313
import fuml.syntax.commonbehavior.CallEvent;
14+
import fuml.syntax.commonbehavior.Event;
1415
import fuml.syntax.commonbehavior.Trigger;
1516

1617
public class CallEventOccurrence extends EventOccurrence {
@@ -37,7 +38,7 @@ public boolean match(Trigger trigger) {
3738
}
3839

3940
@Override
40-
public ParameterValueList getParameterValues() {
41+
public ParameterValueList getParameterValues(Event event) {
4142
// Return the input parameter values from the call event execution for
4243
// this call event occurrence, which correspond to the values of the
4344
// operation input parameters for the call.

org.modeldriven.fuml/src/main/java/fuml/semantics/commonbehavior/EventOccurrence.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.modeldriven.fuml.FumlObject;
1212

1313
import fuml.semantics.structuredclassifiers.Reference;
14+
import fuml.syntax.commonbehavior.Event;
1415

1516
public abstract class EventOccurrence extends FumlObject {
1617

@@ -48,7 +49,7 @@ public boolean matchAny(fuml.syntax.commonbehavior.TriggerList triggers) {
4849

4950
}
5051

51-
public abstract fuml.semantics.commonbehavior.ParameterValueList getParameterValues();
52+
public abstract fuml.semantics.commonbehavior.ParameterValueList getParameterValues(Event event);
5253

5354
private EventOccurrence_SendingBehaviorExecution behavior = new EventOccurrence_SendingBehaviorExecution(this);
5455

org.modeldriven.fuml/src/main/java/fuml/semantics/commonbehavior/InvocationEventOccurrence.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package fuml.semantics.commonbehavior;
1010

11+
import fuml.syntax.commonbehavior.Event;
1112
import fuml.syntax.commonbehavior.Trigger;
1213

1314
public class InvocationEventOccurrence extends EventOccurrence {
@@ -22,7 +23,7 @@ public boolean match(Trigger trigger) {
2223
}
2324

2425
@Override
25-
public ParameterValueList getParameterValues() {
26+
public ParameterValueList getParameterValues(Event event) {
2627
// An invocation event occurrence does not have any associated data.
2728

2829
return new ParameterValueList();

org.modeldriven.fuml/src/main/java/fuml/semantics/commonbehavior/SignalEventOccurrence.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import fuml.semantics.simpleclassifiers.FeatureValue;
1212
import fuml.semantics.simpleclassifiers.FeatureValueList;
1313
import fuml.semantics.simpleclassifiers.SignalInstance;
14+
import fuml.syntax.commonbehavior.Event;
1415
import fuml.syntax.commonbehavior.SignalEvent;
1516

1617
public class SignalEventOccurrence extends EventOccurrence {
@@ -31,18 +32,25 @@ public boolean match(fuml.syntax.commonbehavior.Trigger trigger) {
3132
}
3233

3334
@Override
34-
public fuml.semantics.commonbehavior.ParameterValueList getParameterValues() {
35-
// Return parameter values for feature of the signal instance, in order.
35+
public fuml.semantics.commonbehavior.ParameterValueList getParameterValues(Event event) {
36+
// Return parameter values for the features of the signal instance, in order,
37+
// corresponding to the attributes of the declared signal of the given event.
3638
// These are intended to be treated as if they are the values of effective
3739
// parameters of direction "in".
38-
39-
ParameterValueList parameterValues = new ParameterValueList();
40-
FeatureValueList memberValues = this.signalInstance.getMemberValues();
41-
for(int i = 0; i < memberValues.size(); i++){
42-
FeatureValue feature = memberValues.getValue(i);
43-
ParameterValue parameterValue = new ParameterValue();
44-
parameterValue.values = feature.values;
45-
parameterValues.add(parameterValue);
40+
// (Note that the given event must be a signal event, and the signal instance
41+
// of this signal event occurrence must be a direct or indirect instance of
42+
// the event signal.)
43+
44+
ParameterValueList parameterValues = new ParameterValueList();
45+
if (event instanceof SignalEvent) {
46+
FeatureValueList memberValues =
47+
this.signalInstance.getMemberValues(((SignalEvent)event).signal);
48+
for(int i = 0; i < memberValues.size(); i++){
49+
FeatureValue feature = memberValues.getValue(i);
50+
ParameterValue parameterValue = new ParameterValue();
51+
parameterValue.values = feature.values;
52+
parameterValues.add(parameterValue);
53+
}
4654
}
4755
return parameterValues;
4856
}

org.modeldriven.fuml/src/main/java/fuml/semantics/simpleclassifiers/StructuredValue.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,29 @@ public abstract void setFeatureValue(
7373

7474
public abstract fuml.semantics.simpleclassifiers.FeatureValueList getFeatureValues();
7575

76-
public fuml.semantics.simpleclassifiers.FeatureValueList getMemberValues() {
76+
public fuml.semantics.simpleclassifiers.FeatureValueList getMemberValues(Classifier type) {
7777
// Return the feature values for this structured value that are for structural
78-
// features that are members of one of the types of the structured value.
79-
// (That is, they are owned are inherited, excluding private features of
80-
// supertypes that are not inherited.)
78+
// features that are members of the given type. (That is, they are owned or
79+
// inherited by the given type, excluding private features of supertypes that
80+
// are not inherited.)
8181

8282
FeatureValueList featureValues = this.getFeatureValues();
8383
FeatureValueList memberValues = new FeatureValueList();
8484

85-
ClassifierList types = this.getTypes();
86-
for (int i = 0; i < featureValues.size(); i++) {
87-
FeatureValue featureValue = featureValues.getValue(i);
88-
Boolean isMember = false;
89-
int j = 1;
90-
while (j <= types.size() & !isMember) {
91-
Classifier type = types.getValue(j-1);
92-
NamedElementList members = type.member;
85+
if (type != null) {
86+
NamedElementList members = type.member;
87+
for (int i = 0; i < featureValues.size(); i++) {
88+
FeatureValue featureValue = featureValues.getValue(i);
89+
Boolean isMember = false;
9390
int k = 1;
9491
while (k <= members.size() & !isMember) {
9592
NamedElement member = members.getValue(k-1);
9693
isMember = featureValue.feature == member;
9794
k = k + 1;
9895
}
99-
j = j + 1;
100-
}
101-
if (isMember) {
102-
memberValues.addValue(featureValue);
96+
if (isMember) {
97+
memberValues.addValue(featureValue);
98+
}
10399
}
104100
}
105101

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,16 @@ public void testTestDataStore() throws Exception {
348348
assertEqualValues("output", output.get(0), 1, 2);
349349
}
350350

351+
public void testTestClassUnmarshaller() throws Exception {
352+
ParameterValueList output = execute("TestClassUnmarshaller");
353+
log.info("done");
354+
355+
assertNotNull(output);
356+
assertEquals("output.size()", 2, output.size());
357+
assertEqualValues("x", output.get(0), 0);
358+
assertEqualValues("y", output.get(1), 1, 2);
359+
}
360+
351361
private ParameterValueList execute(String activityName)
352362
{
353363
Behavior behavior = environment.findBehavior(activityName);

0 commit comments

Comments
 (0)