Book a Demo

Author Topic: Get a link‘s classifier (=association) from UML Object Diagrams using JScript  (Read 4284 times)

mhoppen

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Hi
I‘m processing objects from UML Object Diagrams with JScript. Objects as well as links between them both have instance classifiers from my UML Class Model containing classes and associations. I know how to access an object’s class via EA.Element’s ClassifierID. How can I do the same for links between the objects, i.e., get the corresponding UML association(s), via EA.Connector?!
Regards
Martin

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Hi Martin,


And welcome to the forum. :)

The connectors are located in the Element.Connectors collection. There is only one such collection, not two separate ones for incoming and outgoing as you might expect.
Each connector is present in both the source element's and target element's .Connectors.

The Connector class holds the source and target element IDs in .ClientID and .SupplierID, respectively.

So to find the direction of a connector relative to an element, you need to check whether Element.ElementID matches Connector.ClientID (outgoing) or Connector.SupplierID (incoming).

As with all Collections, Element.Connectors contains objects, not IDs. If you instead have a connector ID or GUID, you can retrieve the Connector object using Repository.GetConnectorByID() or Repository.GetConnectorByGuid().

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

mhoppen

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Hey Uffe,

thanks for the warm welcome and your support. However, I think you got me wrong. I know how to get the Connector from an Element. What I don't know is, how to get the classifier of a connector. In my case (UML Object Diagram), the Connector is a link, i.e., an instance of a UML Association from my UML class model. When accessing the connector (that represents some link), I want to access its classifier, i.e., its Association.

I made a little example of a House and a Room class, connected by a rooms Association. There is an instance of House called myHouse (yielding myHouse : House) and an instance of Room called myRoom (yielding myRoom : Room). They are connected by an anonymous instance of rooms yielding :rooms.
My JScript-Code iterates all EA.Elements of type Object and finds myHouse, gets all its EA.Connectors and finds its Connectors.
Question: How can I get the name (i.e., :rooms) of this Connector and its classifier (i.e., rooms). Regarding the name: it is not set as the Name of the Connector. I use Context Menu > Advanced > Instance Classifier... (Ctrl+L) on the connector and choose rooms from the list of available classifiers. Subsequently, :rooms appears in the diagram (BTW this didn't work with my old EA 12ish version where :rooms would not show up in the diagram).




Regards
Martin

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Hi Martin,

I'm not sure where exactly EA stores this info, but I can make an informed guess.

The first thing to look at is the table t_connector. That is where each relationship is stored.
There is a good chance that the connectorID of the association is stored in one of the fields of t_connector of the record representing the link.

If you can't find it there, you might want to look at the table t_xref. EA sometimes stores some of that type of info there as well. It there is a record for t_connector it will be linked the fields t_xref.Client = t_connector.ea_guid

Once you know the table and column, it is usually pretty straightforward to figure out the API field to use (most of them are named the same, or very similar)
If you can't find it in the API you might need to use Repository.SQLQuery() to get the ID of the association.

Geert

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Hi again,


Sorry, I misunderstood. With you now.

Luckily, this one isn't in the t_xref (aka black magic) table. It's in t_connector.PDATA2  ==  Connector.MiscData(1).
(And yes, the PDATA columns really are off by one compared to the MiscData property.)

This column/attribute of the instantiating connector (the one between your object elements) contains the GUID of the instantiated connector (the one between the classes), which you can then retrieve with Repository.GetConnectorByGuid().

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

mhoppen

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Uffe

That's it! Thank you so much.

Regards
Martin