0

I have Actor and Sequences as life lines in my sequence diagram in Enterprise Architect.

Sequence Diagram with Fragment.

This diagram has a fragment also in it. I tried to fetch the diagram object through java API.

I'm able to get all the Actor, Sequence and Fragment information from the API. But I am unable to differentiate which among these are life lines.

Is there any way to differentiate Lifelines and other elements through API or through EA Database?

Little more hint about how to approach this problem would be more appreciated.

Code snippet that i'm using as follows . .

 Diagram sequenceDiagram = rep.GetDiagramByGuid(seqdiagGuid);
 Collection<DiagramObject> diagObjs = sequenceDiagram.GetDiagramObjects();
 for (DiagramObject obj : diagObjs) {
   Element el = rep.GetElementByID(obj.GetElementID());
   // How to differenciate whether this el is a lifeline?
 }

Edited with few more information and screen shots to give some more clarity

I have dropped a class from toolbox. While copying i selected the option as "Lifeline". For this newly added class, I am expecting el.type would give value as "LifeLine" but unfortunately it is giving "Object" only. Now my question is how this object can be identified as Lifeline of type Class?

Class from toolbox

Selection of Lifeline

Added as Object rather than a Lifeline

Hope this gives more clarity.

Geert Bellekens
  • 12,788
  • 2
  • 23
  • 50
Raj kumar
  • 1
  • 2
  • 1
    Can you post the code you have already? That would be useful in answering the question. – Geert Bellekens Jun 18 '21 at 12:38
  • 1
    Looks like you are using a link (which EA sadly still allows). That would be wrong. You need to use instances. In your browser they woud appear either as object or lifeline icon (EA is a strange tool). – qwerty_so Jun 18 '21 at 13:58
  • @GeertBellekens, I have updated my question with a code snippet. There i am unable to differentiate what kind of it is. type and metaType information of the element object is not helping here. – Raj kumar Jun 21 '21 at 05:33
  • 1
    If you model your sequence diagrams correctly (not with links, but with real lifelines) you can use `el.Type` to differentiate between the different types of elements. – Geert Bellekens Jun 21 '21 at 05:57
  • Can you please confirm what kind of element you are actually using? If it's a link to an actor rather than an instance you won't be able (and that's what you get from bad models). – qwerty_so Jun 22 '21 at 10:10
  • @GeertBellekens, Thank you for the updates. I had selected Lifeline rather than Link. Even for this also I am not getting this information ( Lifeline of type Class) from API. For more clarification, i have edited my question with few more screen shots. – Raj kumar Jun 22 '21 at 11:36
  • I quickly tested this and lifelines from the toolbox have type "Sequence", whereas classes dropped as lifeline have type "Object". You can check the Classifier type by selecting the element based on the ClassifierID in the object/lifeline – Geert Bellekens Jun 22 '21 at 11:47

1 Answers1

1

If you drop a class onto a sequence diagram as a lifeline you will effectively get an element of type Object, that is an instance of your class.

Using the ClassifierID you can then get the Classifier element

So starting from you sample

 Diagram sequenceDiagram = rep.GetDiagramByGuid(seqdiagGuid);
 Collection<DiagramObject> diagObjs = sequenceDiagram.GetDiagramObjects();
 for (DiagramObject obj : diagObjs) {
   Element el = rep.GetElementByID(obj.GetElementID());
   // How to differenciate whether this el is a lifeline?
   String elementType = el.GetType(); //this will be "Object" if you drop a class as a lifeline, and "Sequence" if you choose a lifeline from the toolbox
   if (el.GetClassifierID > 0) {
       Element classifier = rep.GetElementByID(el.GetClassifierID);
   }
 }
Geert Bellekens
  • 12,788
  • 2
  • 23
  • 50
  • Thanks for the good hint. I am very new to this EA and really sorry if my question is silly one. But still I have a Fragment also in my sequence diagram. I would like to mark somehow this Fragment is not a life lines like Actor and other classes in my sequence diagram. If i iterate all the diagram objects, I will be getting this fragment object also there. Now i need to to mark Actor and Other classes in my sequence diagram are Lifelines but this Fragment is not. – Raj kumar Jun 23 '21 at 07:16
  • You have to check the string elementType. It will read "InteractionFragment" for a fragment, and the el.classifierID will be 0. – Geert Bellekens Jun 23 '21 at 07:42