file Creating Execution Occurrences in an Interaction

9 months 2 weeks ago - 9 months 2 weeks ago #4866 by Iorek
Hi everybody,

I'd like to create automatically (in a script) a fragment in a Sequence Diagram (e.g. the one corresponding to an asyncronous message from, say, Lifeline1 to Lifeline2).
Looking at the metamodel and the Semantic Model View, I think I have more or less understood what I need. But, when it comes to the code, I have the following problems:

1. I can't create from script an ExecutionOccurrenceSpecification, both from the createElement() method or from the createExecutionOccurrentSpecification(), that seems to be not accessible from Jython. On the other hand, I succeed in creating the ExecutionSpecification.

2. I can't find how to set the many-to-many relationship between the ExecutionOccurrence or ExecutionOccurrenceSpecification and the lifeline (covered/coveredBy)

3. I cannot create a message, namely my script has problems in accessing the MessageSort to be assigned through setSortOfMessage()

Does anyone have some example code, or even knows if what I'm trying to do is possible in a script?

Thanks in advance,
Francesco

Please Log in or Create an account to join the conversation.

9 months 2 weeks ago - 9 months 2 weeks ago #4869 by ebr
Dear Francesco,

Please find below the needed script for creating a message between two lifelines (lifeLine1 and lifeLine2) under an Interaction (interaction).
eos1 = session.getModel().createExecutionOccurenceSpecification()
eos2 = session.getModel().createExecutionOccurenceSpecification()

message = session.getModel().createMessage()
message.setSortOfMessage(MessageSort.ASYNCCALL);

eos1.getCovered().add(lifeLine1)
eos1.setEnclosingInteraction(interaction)
eos1.setLineNumber(100)
eos1.setSentMessage(message)

eos2.getCovered().add(lifeLine2)
eos2.setEnclosingInteraction(interaction)
eos2.setLineNumber(120)
eos2.setReceivedMessage(message)

Let us know if it helps you.
BTW the metaclass name is "ExecutionOccurenceSpecification" not "ExecutionOccurrenceSpecification" ;)

Cheers,
EBR
The following user(s) said Thank You: Iorek

Please Log in or Create an account to join the conversation.

9 months 1 week ago - 9 months 1 week ago #4870 by Iorek
Hi ebr, once again thank you, all right now.

The spelling of the call was OK in my code, but I was wrong in how I got the handle to the Model. Trivial cut and paste mistake, but I could have spent ages without noticing it...

The other point that I really did not realise is that the list returned by getCovered() is actually modifiable by add(), and the modification is reflected in the relation. Being a getter, I thought that the list returned was in some sort a "read only" one, in other words a copy of the "real" relation, so that the modifications would be lost on the real object's attribute.

Sorry for the silly question (quite new both to the metamodel and the language), but, am I authorised to generalise and understand that the approach to adding a relation to a one-to-many (from the -many side, of course) is to use the get<relation>() and list.add() couple of calls?

Thanks again,
Francesco

Please Log in or Create an account to join the conversation.

9 months 1 week ago #4871 by ebr
Hi Francesco,

You are right.
To add an element in an one-to-many relations(at the metamodel level), you should have a get$RelationRole() method which return a list.
Then you can use the list.add() method.

Good luck for the rest of your dev.
Cheers,
EBR

Please Log in or Create an account to join the conversation.

9 months 1 week ago #4872 by chm

Iorek wrote: The other point that I really did not realise is that the list returned by getCovered() is actually modifiable by add(), and the modification is reflected in the relation. Being a getter, I thought that the list returned was in some sort a "read only" one, in other words a copy of the "real" relation, so that the modifications would be lost on the real object's attribute.

Sorry for the silly question (quite new both to the metamodel and the language), but, am I authorised to generalise and understand that the approach to adding a relation to a one-to-many (from the -many side, of course) is to use the get<relation>() and list.add() couple of calls?


Hi lorek,

there is a documentation page in the wiki giving some details about this API: model services, multiple association

Hope this helps,


chm
The following user(s) said Thank You: Iorek

Please Log in or Create an account to join the conversation.

Moderators: chmcma
Time to create page: 0.046 seconds
^ Back to Top