Skip to content

Commit 05a2b2d

Browse files
committed
Added general operations to EventOccurrence. (OMG Issue FUML13-25).
1 parent a91f45e commit 05a2b2d

5 files changed

Lines changed: 143 additions & 87 deletions

File tree

org.modeldriven.fuml/src/main/java/fUML/Semantics/Actions/CompleteActions/AcceptEventActionActivation.java

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Initial version copyright 2008 Lockheed Martin Corporation, except
44
* as stated in the file entitled Licensing-Information.
55
*
6-
* All modifications copyright 2009-2015 Data Access Technologies, Inc.
6+
* All modifications copyright 2009-2017 Data Access Technologies, Inc.
77
*
88
* Licensed under the Academic Free License version 3.0
99
* (http://www.opensource.org/licenses/afl-3.0.php), except as stated
@@ -13,25 +13,16 @@
1313
package fUML.Semantics.Actions.CompleteActions;
1414

1515
import fUML.Debug;
16-
import UMLPrimitiveTypes.*;
17-
18-
import java.util.Iterator;
19-
20-
import fUML.Syntax.*;
21-
import fUML.Syntax.Classes.Kernel.*;
22-
import fUML.Syntax.CommonBehaviors.BasicBehaviors.*;
2316
import fUML.Syntax.CommonBehaviors.Communications.*;
2417
import fUML.Syntax.Activities.IntermediateActivities.*;
2518
import fUML.Syntax.Actions.BasicActions.*;
26-
import fUML.Syntax.Actions.IntermediateActions.*;
2719
import fUML.Syntax.Actions.CompleteActions.*;
28-
import fUML.Semantics.*;
2920
import fUML.Semantics.Classes.Kernel.*;
30-
import fUML.Semantics.CommonBehaviors.BasicBehaviors.*;
21+
import fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValue;
22+
import fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValueList;
23+
import fUML.Semantics.CommonBehaviors.Communications.SignalEventOccurrence;
24+
import fUML.Semantics.CommonBehaviors.Communications.SignalInstance;
3125
import fUML.Semantics.Activities.IntermediateActivities.*;
32-
import fUML.Semantics.Actions.BasicActions.*;
33-
import fUML.Semantics.Actions.IntermediateActions.*;
34-
import fUML.Semantics.Loci.*;
3526

3627
public class AcceptEventActionActivation extends
3728
fUML.Semantics.Actions.BasicActions.ActionActivation {
@@ -93,12 +84,13 @@ public void doAction() {
9384
} // doAction
9485

9586
public void accept(
96-
fUML.Semantics.CommonBehaviors.Communications.SignalInstance signalInstance) {
97-
// Accept a signal occurance for the given signal instance.
98-
// If the action does not unmarshall, then place the signal instance on
99-
// the result pin, if any.
100-
// If the action does unmarshall, then get the feature values of the
101-
// signal instance, and place the values for each feature on the
87+
fUML.Semantics.CommonBehaviors.Communications.EventOccurrence eventOccurrence) {
88+
// Accept the given event occurrence.
89+
// If the action does not unmarshall, then, if the event occurrence is
90+
// a signal event occurrence, place the signal instance of the signal
91+
// event occurrence on the result pin, if any.
92+
// If the action does unmarshall, then get the parameter values of the
93+
// event occurrence, and place the values for each parameter on the
10294
// corresponding output pin.
10395
// Concurrently fire all output pins while offering a single control
10496
// token.
@@ -107,59 +99,50 @@ public void accept(
10799

108100
AcceptEventAction action = (AcceptEventAction) (this.node);
109101
OutputPinList resultPins = action.result;
110-
111-
Debug.println("[accept] action = " + action.name + ", signalinstance = " + signalInstance);
112-
102+
103+
Debug.println("[accept] action = " + action.name + ", eventOccurrence = " + eventOccurrence);
104+
113105
if (this.running) {
114106
if (!action.isUnmarshall) {
115-
ValueList result = new ValueList();
116-
result.addValue(signalInstance);
117-
if (resultPins.size() > 0) {
118-
this.putTokens(resultPins.getValue(0), result);
107+
if (eventOccurrence instanceof SignalEventOccurrence) {
108+
SignalInstance signalInstance = ((SignalEventOccurrence)eventOccurrence).signalInstance;
109+
Debug.println("[accept] isUnmarshall = true, signalInstance = " + signalInstance);
110+
ValueList result = new ValueList();
111+
result.addValue(signalInstance);
112+
if (resultPins.size() > 0) {
113+
this.putTokens(resultPins.getValue(0), result);
114+
}
119115
}
120116
} else {
121-
FeatureValueList featureValues = signalInstance.getMemberValues();
122-
for (int i = 0; i < featureValues.size(); i++) {
123-
FeatureValue featureValue = featureValues.getValue(i);
117+
ParameterValueList parameterValues = eventOccurrence.getParameterValues();
118+
for (int i = 0; i < parameterValues.size(); i++) {
119+
ParameterValue parameterValue = parameterValues.getValue(i);
124120
OutputPin resultPin = resultPins.getValue(i);
125-
this.putTokens(resultPin, featureValue.values);
121+
this.putTokens(resultPin, parameterValue.values);
126122
}
127123
}
128124

129125
this.sendOffers();
130126

131127
this.waiting = false;
132128

133-
Debug.println("[fire] Checking if " + this.node.name + " should fire again...");
129+
Debug.println("[accept] Checking if " + this.node.name + " should fire again...");
134130
this.receiveOffer();
135131

136-
this.resume();
132+
this.resume();
137133
}
138134

139135
} // accept
140136

141137
public boolean match(
142-
fUML.Semantics.CommonBehaviors.Communications.SignalInstance signalInstance) {
143-
// Return true if the given signal instance matches a trigger of the
144-
// accept action of this activation.
138+
fUML.Semantics.CommonBehaviors.Communications.EventOccurrence eventOccurrence) {
139+
// Return true if the given event occurrence matches a trigger of the
140+
// accept event action of this activation.
145141

146142
AcceptEventAction action = (AcceptEventAction) (this.node);
147143
TriggerList triggers = action.trigger;
148-
Signal signal = signalInstance.type;
149-
150-
boolean matches = false;
151-
int i = 1;
152-
while (!matches & i <= triggers.size()) {
153-
Signal triggerSignal = ((SignalEvent) (triggers.getValue(i - 1).event)).signal;
154-
if (triggerSignal == signal) {
155-
matches = true;
156-
} else {
157-
matches = this.checkAllParents(signal, triggerSignal);
158-
}
159-
i = i + 1;
160-
}
161-
162-
return matches;
144+
145+
return eventOccurrence.matchAny(triggers);
163146
} // match
164147

165148
public void terminate() {

org.modeldriven.fuml/src/main/java/fUML/Semantics/Actions/CompleteActions/AcceptEventActionEventAccepter.java

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Initial version copyright 2008 Lockheed Martin Corporation, except
44
* as stated in the file entitled Licensing-Information.
55
*
6-
* All modifications copyright 2009-2015 Data Access Technologies, Inc.
6+
* All modifications copyright 2009-2017 Data Access Technologies, Inc.
77
*
88
* Licensed under the Academic Free License version 3.0
99
* (http://www.opensource.org/licenses/afl-3.0.php), except as stated
@@ -12,50 +12,24 @@
1212

1313
package fUML.Semantics.Actions.CompleteActions;
1414

15-
import fUML.Debug;
16-
import UMLPrimitiveTypes.*;
17-
import fUML.Syntax.*;
18-
import fUML.Syntax.Classes.Kernel.*;
19-
import fUML.Syntax.CommonBehaviors.BasicBehaviors.*;
20-
import fUML.Syntax.CommonBehaviors.Communications.*;
21-
import fUML.Syntax.Activities.IntermediateActivities.*;
22-
import fUML.Syntax.Actions.BasicActions.*;
23-
import fUML.Syntax.Actions.IntermediateActions.*;
24-
import fUML.Syntax.Actions.CompleteActions.*;
25-
import fUML.Semantics.*;
26-
import fUML.Semantics.Classes.Kernel.*;
27-
import fUML.Semantics.CommonBehaviors.BasicBehaviors.*;
28-
import fUML.Semantics.CommonBehaviors.Communications.SignalEventOccurrence;
29-
import fUML.Semantics.Activities.IntermediateActivities.*;
30-
import fUML.Semantics.Actions.BasicActions.*;
31-
import fUML.Semantics.Actions.IntermediateActions.*;
32-
import fUML.Semantics.Loci.*;
33-
3415
public class AcceptEventActionEventAccepter extends
3516
fUML.Semantics.CommonBehaviors.Communications.EventAccepter {
3617

3718
public fUML.Semantics.Actions.CompleteActions.AcceptEventActionActivation actionActivation = null;
3819

3920
public void accept(
4021
fUML.Semantics.CommonBehaviors.Communications.EventOccurrence eventOccurrence) {
41-
// Accept a signal event occurrence. Forward the signal instance to the action activation.
22+
// Accept an event occurrence and forward it to the action activation.
4223

43-
if (eventOccurrence instanceof SignalEventOccurrence) {
44-
this.actionActivation.accept(((SignalEventOccurrence)eventOccurrence).signalInstance);
45-
}
24+
this.actionActivation.accept(eventOccurrence);
4625
} // accept
4726

4827
public boolean match(
4928
fUML.Semantics.CommonBehaviors.Communications.EventOccurrence eventOccurrence) {
50-
// Return true if the given event occurrence is a signal event occurrence and the
51-
// signal instance matches a trigger of the accept action of the action activation.
52-
53-
boolean matches = false;
54-
if (eventOccurrence instanceof SignalEventOccurrence) {
55-
matches = this.actionActivation.
56-
match(((SignalEventOccurrence)eventOccurrence).signalInstance);
57-
}
58-
return matches;
29+
// Return true if the given event occurrence matches a trigger of the accept event
30+
// action of the action activation.
31+
32+
return this.actionActivation.match(eventOccurrence);
5933
} // match
6034

6135
} // AcceptEventActionEventAccepter

org.modeldriven.fuml/src/main/java/fUML/Semantics/CommonBehaviors/Communications/EventOccurrence.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Data Access Technologies, Inc.
2+
* Copyright 2015-2017 Data Access Technologies, Inc.
33
*
44
* Licensed under the Academic Free License version 3.0
55
* (http://www.opensource.org/licenses/afl-3.0.php), except as stated
@@ -11,5 +11,25 @@
1111
import org.modeldriven.fuml.FumlObject;
1212

1313
public abstract class EventOccurrence extends FumlObject {
14+
15+
public abstract boolean match(fUML.Syntax.CommonBehaviors.Communications.Trigger trigger);
16+
17+
public boolean matchAny(fUML.Syntax.CommonBehaviors.Communications.TriggerList triggers) {
18+
// Check that at least one of the given triggers is matched by this
19+
// event occurrence.
20+
21+
boolean matches = false;
22+
int i = 1;
23+
while(!matches & i <= triggers.size()){
24+
if(this.match(triggers.get(i-1))){
25+
matches = true;
26+
}
27+
i = i + 1;
28+
}
29+
return matches;
30+
31+
}
32+
33+
public abstract fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValueList getParameterValues();
1434

1535
}

org.modeldriven.fuml/src/main/java/fUML/Semantics/CommonBehaviors/Communications/InvocationEventOccurrence.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Data Access Technologies, Inc.
2+
* Copyright 2015-2017 Data Access Technologies, Inc.
33
*
44
* Licensed under the Academic Free License version 3.0
55
* (http://www.opensource.org/licenses/afl-3.0.php), except as stated
@@ -9,9 +9,25 @@
99
package fUML.Semantics.CommonBehaviors.Communications;
1010

1111
import fUML.Semantics.CommonBehaviors.BasicBehaviors.Execution;
12+
import fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValueList;
13+
import fUML.Syntax.CommonBehaviors.Communications.Trigger;
1214

1315
public class InvocationEventOccurrence extends EventOccurrence {
1416

1517
public Execution execution;
18+
19+
@Override
20+
public boolean match(Trigger trigger) {
21+
// An invocation event occurrence does not match any triggers.
22+
23+
return false;
24+
}
25+
26+
@Override
27+
public ParameterValueList getParameterValues() {
28+
// An invocation event occurrence does not have any associated data.
29+
30+
return new ParameterValueList();
31+
}
1632

1733
}
Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Data Access Technologies, Inc.
2+
* Copyright 2015-2017 Data Access Technologies, Inc.
33
*
44
* Licensed under the Academic Free License version 3.0
55
* (http://www.opensource.org/licenses/afl-3.0.php), except as stated
@@ -8,8 +8,71 @@
88

99
package fUML.Semantics.CommonBehaviors.Communications;
1010

11+
import fUML.Semantics.Classes.Kernel.FeatureValue;
12+
import fUML.Semantics.Classes.Kernel.FeatureValueList;
13+
import fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValue;
14+
import fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValueList;
15+
import fUML.Syntax.Classes.Kernel.Classifier;
16+
import fUML.Syntax.Classes.Kernel.ClassifierList;
17+
import fUML.Syntax.CommonBehaviors.Communications.SignalEvent;
18+
1119
public class SignalEventOccurrence extends EventOccurrence {
1220

1321
public SignalInstance signalInstance;
1422

23+
@Override
24+
public boolean match(fUML.Syntax.CommonBehaviors.Communications.Trigger trigger) {
25+
// Match a trigger if it references a signal event whose signal is the type of the
26+
// signal instance or one of its supertypes.
27+
28+
boolean matches = false;
29+
if(trigger.event instanceof SignalEvent){
30+
SignalEvent event = (SignalEvent) trigger.event;
31+
if(event.signal == this.signalInstance.type) {
32+
matches = true;
33+
} else {
34+
matches = this.checkAllParents(this.signalInstance.type, event.signal);
35+
}
36+
}
37+
return matches;
38+
}
39+
40+
public boolean checkAllParents(fUML.Syntax.Classes.Kernel.Classifier type,
41+
fUML.Syntax.Classes.Kernel.Classifier classifier) {
42+
// Check if the given classifier matches any of the direct or indirect
43+
// ancestors of a given type.
44+
45+
ClassifierList directParents = type.general;
46+
boolean matched = false;
47+
int i = 1;
48+
while (!matched & i <= directParents.size()) {
49+
Classifier directParent = directParents.getValue(i - 1);
50+
if (directParent == classifier) {
51+
matched = true;
52+
} else {
53+
matched = this.checkAllParents(directParent, classifier);
54+
}
55+
i = i + 1;
56+
}
57+
58+
return matched;
59+
}
60+
61+
@Override
62+
public fUML.Semantics.CommonBehaviors.BasicBehaviors.ParameterValueList getParameterValues() {
63+
// Return parameter values for feature of the signal instance, in order.
64+
// These are intended to be treated as if they are the values of effective
65+
// parameters of direction "in".
66+
67+
ParameterValueList parameterValues = new ParameterValueList();
68+
FeatureValueList memberValues = this.signalInstance.getMemberValues();
69+
for(int i = 0; i < memberValues.size(); i++){
70+
FeatureValue feature = memberValues.getValue(i);
71+
ParameterValue parameterValue = new ParameterValue();
72+
parameterValue.values = feature.values;
73+
parameterValues.add(parameterValue);
74+
}
75+
return parameterValues;
76+
}
77+
1578
}

0 commit comments

Comments
 (0)