Home » Modeling » UML2 » Need pointers for an UML2 model containing Interaction
| | |
Re: Need pointers for an UML2 model containing Interaction [message #472975 is a reply to message #472927] |
Wed, 23 May 2007 12:58 |
Andrew Carton Messages: 104 Registered: July 2009 |
Senior Member |
|
|
Hey,
Ok this is what I have figured out so far. Assuming you have two classes
"Class class1, class2" that have been created previously in the same
package (myPackage).
Firstly create a collaboration:
Collaboration coll = UMLFactory.eINSTANCE.createCollaboration();
coll.setPackage(myPackage);
Then an interaction in the collaboration:
Interaction interaction = (Interaction) coll.createOwnedBehavior(null,
UMLPackage.eINSTANCE.getInteraction());
Create a lifeline for class you want to represent and a corresponding
property that refers to the class.
Lifeline life1 = interaction.createLifeline("");
Property refClass1 = interaction.createOwnedAttribute("", class1);
life1.setRepresents(refClass1);
Lifeline life2 = interaction.createLifeline("");
Property refClass1 = interaction.createOwnedAttribute("", class2);
life2.setRepresents(refClass2);
Now create a message "myMessage" that you want to send from life1 to life2:
Message myMessage = interaction.createMessage("");
Now you need a MOS at each lifeline to tell where the message occurs.
MessageOccurrenceSpecification mos1 = (MessageOccurrenceSpecification)
interaction.createFragment(null,
UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION);
mos1.getCovereds().add(life1);
mos1.setMessage(myMessage);
MessageOccurrenceSpecification mos2 = (MessageOccurrenceSpecification)
interaction.createFragment(null,
UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION);
mos2.getCovereds().add(life2);
mos2.setMessage(myMessage);
Now attach the message to these MOS. (An MOS is a messageEnd remember?)
myMessage.setReceiveEvent(mos1);
myMessage.setSendEvent(mos2);
Ok next we need MessageEvents. Assume "myOp" is an operation in
class2... "Operation myOp"
SendOperationEvent sendOperationEvent =
UMLFactory.eINSTANCE.createSendOperationEvent();
sendOperationEvent = (SendOperationEvent)
cross.createPackagedElement(null, sendOperationEvent.eClass());
sendOperationEvent.setOperation(myOp);
mos1.setEvent(sendOperationEvent);
ReceiveOperationEvent receiveEvent =
UMLFactory.eINSTANCE.createReceiveOperationEvent();
receiveEvent = (ReceiveOperationEvent) cross.createPackagedElement(null,
receiveEvent2.eClass());
receiveEvent.setOperation(myOp);
mos2.setEvent(receiveEvent);
and thats all it takes to send a message from one lifeline to another...
I hope that works, I couldn't find an application that would load the
diagram for me so I'm not 100% but I reversed engineered it from Magicdraw.
Regards,
Andrew.
James Bruck wrote:
> Hi Sri,
>
> You are off to a good start... some minor points...
>
> - MessageOccurrenceSpecification's are OccurrenceSpecifications that require
> an actual "Event" to be set. see "setEvent()" on OccurrenceSpecification.
>
> - Have a look at the migration document for some explanations of
> MessageOccurrenceSpecification etc.
> http://www.eclipse.org/modeling/mdt/uml2/docs/guides/UML2_2. 0_Migration_Guide/guide.html
>
> - EventOccurrence is the old metatype that no longer exists in the latest
> version of UML. Various subtypes of OccurrenceSpecifications replace
> EventOccurrence. I'm guessing you have an older version of MagicDraw or
> they did not upgrade to the latest version of opensource UML ( I don't use
> MagicDraw so I can't comment on that ).
>
> - You might want to scan the older newsgroup postings for examples and more
> information ( eclipse.tools.uml2 )
>
>
> Regards,
>
> - James.
>
>
> "Sri Raguraman" <srikrishnanr@yahoo.com> wrote in message
> news:f2rej9$urq$1@build.eclipse.org...
>> Sri Raguraman wrote:
>>> Hi,
>>> I am trying to figure out how to programmatically write an UML2 based
>>> model file containing an interaction (trace of method calls).
>>>
>>> I would greatly appreciate if anyone can point me to an example model
>>> file containing interactions that includes lifelines, and messages; or a
>>> code snippet for programmatically writing an UML2 interaction.
>>>
>>> I did look into UML2 specification from OMG regarding interactions
>>> (pages 472-479), but I didn't know if it is the only document we have
>>> for understanding/getting-started with interactions.
>>>
>>> Any advise/tips on understanding Eclipse UML2 interactions are greatly
>>> appreciated.
>>>
>>> Thanks
>>> Sri
>> Hi,
>> Ok, I looked at OMG UML2 specification (chapter 14 Interaction) and
>> Eclipse-UML2 javadoc and thought I would attempt to implement a simple
>> interaction between two classes using Eclipse-UML2 package.
>>
>> I would be grateful if someone could glance at the below code and let me
>> know if there is anything wrong or if there is a better way of
>> implementing the same. I would also appreciate if anyone could point me
>> to some sample code involving interactions. My google search doesn't
>> seem to really help me.
>>
>> This diagram is what I eventually need:
>> +---+ +---+
>> |:C1| |:C2|
>> +---+ +---+
>> | f |
>> +----------->|
>> | |
>>
>>
>> << code begin >>
>> Interaction i1 = UMLFactory.eINSTANCE.createInteraction();
>> i1.setName("SampleInteraction");
>>
>> Lifeline l1 = i1.createLifeline("class1");
>> Lifeline l2 = i1.createLifeline("class2");
>> l1.setInteraction(i1); l2.setInteraction(i1);
>>
>> Message m1 = UMLFactory.eINSTANCE.createMessage();
>> m1.setInteraction(i1);
>> m1.setName("f");
>>
>> MessageOccurrenceSpecification f1 =
>> UMLFactory.eINSTANCE.createMessageOccurrenceSpecification();
>> MessageOccurrenceSpecification f2 =
>> UMLFactory.eINSTANCE.createMessageOccurrenceSpecification();
>> f1.getCovereds().add(l1);
>> f2.getCovereds().add(l2);
>>
>> m1.setSendEvent(f1);
>> m1.setReceiveEvent(f2);
>>
>> f1.setEnclosingInteraction(i1); f2.setEnclosingInteraction(i1);
>> f1.setMessage(m1); f2.setMessage(m1);
>>
>> << code end >>
>>
>> It gave me this output:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <uml:Interaction xmi:version="2.1"
>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML"
>> xmi:id="_honrQAdhEdyLBZgVBW-5Iw" name="SampleInteraction">
>> <lifeline xmi:id="_hoxcQAdhEdyLBZgVBW-5Iw" name="class1"
>> coveredBy="_hoxcQgdhEdyLBZgVBW-5Iw"/>
>> <lifeline xmi:id="_hoxcQQdhEdyLBZgVBW-5Iw" name="class2"
>> coveredBy="_hoxcQwdhEdyLBZgVBW-5Iw"/>
>> <fragment xmi:type="uml:MessageOccurrenceSpecification"
>> xmi:id="_hoxcQgdhEdyLBZgVBW-5Iw" covered="_hoxcQAdhEdyLBZgVBW-5Iw"
>> message="_hoxcRAdhEdyLBZgVBW-5Iw"/>
>> <fragment xmi:type="uml:MessageOccurrenceSpecification"
>> xmi:id="_hoxcQwdhEdyLBZgVBW-5Iw" covered="_hoxcQQdhEdyLBZgVBW-5Iw"
>> message="_hoxcRAdhEdyLBZgVBW-5Iw"/>
>> <message xmi:id="_hoxcRAdhEdyLBZgVBW-5Iw" name="f"
>> receiveEvent="_hoxcQwdhEdyLBZgVBW-5Iw"
> sendEvent="_hoxcQgdhEdyLBZgVBW-5Iw"/>
>> </uml:Interaction>
>>
>>
>> 1. Am I going in the right direction?
>> 2. Should I be using MessageOccurrenceSpecification or something else.
>> 3. Drew the same diagram in MagicDraw CE and its output contained
>> uml:EventOccurrence. What is EventOccurrence - couldn't find it in UML2
>> spec.
>
>
|
|
| | |
Re: Need pointers for an UML2 model containing Interaction [message #617182 is a reply to message #472927] |
Wed, 23 May 2007 12:58 |
Andrew Carton Messages: 104 Registered: July 2009 |
Senior Member |
|
|
Hey,
Ok this is what I have figured out so far. Assuming you have two classes
"Class class1, class2" that have been created previously in the same
package (myPackage).
Firstly create a collaboration:
Collaboration coll = UMLFactory.eINSTANCE.createCollaboration();
coll.setPackage(myPackage);
Then an interaction in the collaboration:
Interaction interaction = (Interaction) coll.createOwnedBehavior(null,
UMLPackage.eINSTANCE.getInteraction());
Create a lifeline for class you want to represent and a corresponding
property that refers to the class.
Lifeline life1 = interaction.createLifeline("");
Property refClass1 = interaction.createOwnedAttribute("", class1);
life1.setRepresents(refClass1);
Lifeline life2 = interaction.createLifeline("");
Property refClass1 = interaction.createOwnedAttribute("", class2);
life2.setRepresents(refClass2);
Now create a message "myMessage" that you want to send from life1 to life2:
Message myMessage = interaction.createMessage("");
Now you need a MOS at each lifeline to tell where the message occurs.
MessageOccurrenceSpecification mos1 = (MessageOccurrenceSpecification)
interaction.createFragment(null,
UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION);
mos1.getCovereds().add(life1);
mos1.setMessage(myMessage);
MessageOccurrenceSpecification mos2 = (MessageOccurrenceSpecification)
interaction.createFragment(null,
UMLPackage.Literals.MESSAGE_OCCURRENCE_SPECIFICATION);
mos2.getCovereds().add(life2);
mos2.setMessage(myMessage);
Now attach the message to these MOS. (An MOS is a messageEnd remember?)
myMessage.setReceiveEvent(mos1);
myMessage.setSendEvent(mos2);
Ok next we need MessageEvents. Assume "myOp" is an operation in
class2... "Operation myOp"
SendOperationEvent sendOperationEvent =
UMLFactory.eINSTANCE.createSendOperationEvent();
sendOperationEvent = (SendOperationEvent)
cross.createPackagedElement(null, sendOperationEvent.eClass());
sendOperationEvent.setOperation(myOp);
mos1.setEvent(sendOperationEvent);
ReceiveOperationEvent receiveEvent =
UMLFactory.eINSTANCE.createReceiveOperationEvent();
receiveEvent = (ReceiveOperationEvent) cross.createPackagedElement(null,
receiveEvent2.eClass());
receiveEvent.setOperation(myOp);
mos2.setEvent(receiveEvent);
and thats all it takes to send a message from one lifeline to another...
I hope that works, I couldn't find an application that would load the
diagram for me so I'm not 100% but I reversed engineered it from Magicdraw.
Regards,
Andrew.
James Bruck wrote:
> Hi Sri,
>
> You are off to a good start... some minor points...
>
> - MessageOccurrenceSpecification's are OccurrenceSpecifications that require
> an actual "Event" to be set. see "setEvent()" on OccurrenceSpecification.
>
> - Have a look at the migration document for some explanations of
> MessageOccurrenceSpecification etc.
> http://www.eclipse.org/modeling/mdt/uml2/docs/guides/UML2_2. 0_Migration_Guide/guide.html
>
> - EventOccurrence is the old metatype that no longer exists in the latest
> version of UML. Various subtypes of OccurrenceSpecifications replace
> EventOccurrence. I'm guessing you have an older version of MagicDraw or
> they did not upgrade to the latest version of opensource UML ( I don't use
> MagicDraw so I can't comment on that ).
>
> - You might want to scan the older newsgroup postings for examples and more
> information ( eclipse.tools.uml2 )
>
>
> Regards,
>
> - James.
>
>
> "Sri Raguraman" <srikrishnanr@yahoo.com> wrote in message
> news:f2rej9$urq$1@build.eclipse.org...
>> Sri Raguraman wrote:
>>> Hi,
>>> I am trying to figure out how to programmatically write an UML2 based
>>> model file containing an interaction (trace of method calls).
>>>
>>> I would greatly appreciate if anyone can point me to an example model
>>> file containing interactions that includes lifelines, and messages; or a
>>> code snippet for programmatically writing an UML2 interaction.
>>>
>>> I did look into UML2 specification from OMG regarding interactions
>>> (pages 472-479), but I didn't know if it is the only document we have
>>> for understanding/getting-started with interactions.
>>>
>>> Any advise/tips on understanding Eclipse UML2 interactions are greatly
>>> appreciated.
>>>
>>> Thanks
>>> Sri
>> Hi,
>> Ok, I looked at OMG UML2 specification (chapter 14 Interaction) and
>> Eclipse-UML2 javadoc and thought I would attempt to implement a simple
>> interaction between two classes using Eclipse-UML2 package.
>>
>> I would be grateful if someone could glance at the below code and let me
>> know if there is anything wrong or if there is a better way of
>> implementing the same. I would also appreciate if anyone could point me
>> to some sample code involving interactions. My google search doesn't
>> seem to really help me.
>>
>> This diagram is what I eventually need:
>> +---+ +---+
>> |:C1| |:C2|
>> +---+ +---+
>> | f |
>> +----------->|
>> | |
>>
>>
>> << code begin >>
>> Interaction i1 = UMLFactory.eINSTANCE.createInteraction();
>> i1.setName("SampleInteraction");
>>
>> Lifeline l1 = i1.createLifeline("class1");
>> Lifeline l2 = i1.createLifeline("class2");
>> l1.setInteraction(i1); l2.setInteraction(i1);
>>
>> Message m1 = UMLFactory.eINSTANCE.createMessage();
>> m1.setInteraction(i1);
>> m1.setName("f");
>>
>> MessageOccurrenceSpecification f1 =
>> UMLFactory.eINSTANCE.createMessageOccurrenceSpecification();
>> MessageOccurrenceSpecification f2 =
>> UMLFactory.eINSTANCE.createMessageOccurrenceSpecification();
>> f1.getCovereds().add(l1);
>> f2.getCovereds().add(l2);
>>
>> m1.setSendEvent(f1);
>> m1.setReceiveEvent(f2);
>>
>> f1.setEnclosingInteraction(i1); f2.setEnclosingInteraction(i1);
>> f1.setMessage(m1); f2.setMessage(m1);
>>
>> << code end >>
>>
>> It gave me this output:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <uml:Interaction xmi:version="2.1"
>> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
>> xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML"
>> xmi:id="_honrQAdhEdyLBZgVBW-5Iw" name="SampleInteraction">
>> <lifeline xmi:id="_hoxcQAdhEdyLBZgVBW-5Iw" name="class1"
>> coveredBy="_hoxcQgdhEdyLBZgVBW-5Iw"/>
>> <lifeline xmi:id="_hoxcQQdhEdyLBZgVBW-5Iw" name="class2"
>> coveredBy="_hoxcQwdhEdyLBZgVBW-5Iw"/>
>> <fragment xmi:type="uml:MessageOccurrenceSpecification"
>> xmi:id="_hoxcQgdhEdyLBZgVBW-5Iw" covered="_hoxcQAdhEdyLBZgVBW-5Iw"
>> message="_hoxcRAdhEdyLBZgVBW-5Iw"/>
>> <fragment xmi:type="uml:MessageOccurrenceSpecification"
>> xmi:id="_hoxcQwdhEdyLBZgVBW-5Iw" covered="_hoxcQQdhEdyLBZgVBW-5Iw"
>> message="_hoxcRAdhEdyLBZgVBW-5Iw"/>
>> <message xmi:id="_hoxcRAdhEdyLBZgVBW-5Iw" name="f"
>> receiveEvent="_hoxcQwdhEdyLBZgVBW-5Iw"
> sendEvent="_hoxcQgdhEdyLBZgVBW-5Iw"/>
>> </uml:Interaction>
>>
>>
>> 1. Am I going in the right direction?
>> 2. Should I be using MessageOccurrenceSpecification or something else.
>> 3. Drew the same diagram in MagicDraw CE and its output contained
>> uml:EventOccurrence. What is EventOccurrence - couldn't find it in UML2
>> spec.
>
>
|
|
|
Goto Forum:
Current Time: Fri Mar 29 05:46:01 GMT 2024
Powered by FUDForum. Page generated in 0.03120 seconds
|