Book a Demo

Author Topic: In own MDG, constrain use of connector to certain elements  (Read 9054 times)

Jacob Vos

  • EA User
  • **
  • Posts: 108
  • Karma: +0/-0
    • View Profile
In own MDG, constrain use of connector to certain elements
« on: March 31, 2020, 01:15:38 am »
In a custom MDG, I defined own connectors. Is there a way to indicate that the connector may only have elements of type X as source (in my situation a customized element of metaclass Constraint) and elements of type Y (in my situation Class) as destination? I couldn't find this in the Special Attributes that can be set at a stereotyped model element.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: In own MDG, constrain use of connector to certain elements
« Reply #1 on: March 31, 2020, 01:42:26 am »
Yes, you can do that with metaconstraints
See https://sparxsystems.com/enterprise_architect_user_guide/15.1/modeling/metaconstraint.html

see the part about umlrole=source and umlrole=target

Geert

Jacob Vos

  • EA User
  • **
  • Posts: 108
  • Karma: +0/-0
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #2 on: March 31, 2020, 02:11:51 am »
In this way, the constraint is checked at the moment of model validation. I would like to implement checking at the moment the connector is drawn. Is that possible, too?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: In own MDG, constrain use of connector to certain elements
« Reply #3 on: March 31, 2020, 04:31:47 am »
In this way, the constraint is checked at the moment of model validation. I would like to implement checking at the moment the connector is drawn. Is that possible, too?
Yes, if you enable Strict Connector Syntax in your preferences.
It also controls what you see in the quick link.

Geert

Jacob Vos

  • EA User
  • **
  • Posts: 108
  • Karma: +0/-0
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #4 on: April 01, 2020, 06:39:24 pm »
Ah, my problem was in fact not that setting (it was already there), but wrong definition of the metaconstraint with umlrole = target.

Still I have something to solve:
- I defined a custom (stereotyped) connector and a custom element.
- I set the custom element as the only allowed source for the connector.
- Now I want to set the metaclass 'Class' as the only allowed target for the connector.

I wonder whether this is possible. The help text seems to tell that only custom elements can be used to set metaconstraints to.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: In own MDG, constrain use of connector to certain elements
« Reply #5 on: April 01, 2020, 06:44:50 pm »
I think you can do that too.
I would try to add Class as when you would extend from it, and then use it as the target of your metaconstraint relation.

I'm guessing a stereotype object with the name UML::Class should be correct, but I've never tried it myself.

Geert

Jacob Vos

  • EA User
  • **
  • Posts: 108
  • Karma: +0/-0
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #6 on: April 01, 2020, 07:36:46 pm »
Hi Geert,

Adding the metaclass 'Class' and setting the metaconstraint to it doesn't lead to any restriction (I had tried that already).

Extending that metaclass 'Class' with a stereotype with the name "UML::Class" and setting the metaconstraint to that stereotype, makes it impossible to draw the connector having as target an element of type Class (that is not stereotyped: it's the 'general' Sparx EA class element).

I even tried setting no name for the stereotype (so remove "UML::Class") with no result - but it would be strange and rather a bug if this had worked.

Lastly, applying a 'stereotyped relationship' is also not the solution.

Jacob

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: In own MDG, constrain use of connector to certain elements
« Reply #7 on: April 01, 2020, 09:37:20 pm »
Then I'm all out of ideas.

Have you asked Sparx support? I'm sure Eve knows how to do this.

Geert

Jacob Vos

  • EA User
  • **
  • Posts: 108
  • Karma: +0/-0
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #8 on: April 01, 2020, 10:54:02 pm »
I did now and will publish the result here.

Jacob

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #9 on: April 02, 2020, 08:12:27 am »
I could have sworn there was an example in the help to do that. Apparently not.

If you want to target Class (or any other UML type) connect the metaconstraint to the matching metaclass. Not stereotype, and do not use a qualified name.

The result should look like this.
Code: [Select]
<Stereotype name="MyConnector" notes="">
<metaconstraints>
<metaconstraint constraint="MyProfile::MyStartObject" umlRole="source"/>
<metaconstraint constraint="Class" umlRole="target"/>
</metaconstraints>
<AppliesTo>
<Apply type="Dependency"/>
</AppliesTo>
</Stereotype>

The equivalent if you have a single source and target is to use a stereotypedrelationship connector. In that case you put the desired connector stereotype into the stereotype property. The result looks like this:
Code: [Select]
<Stereotype name="MyStartObject" notes="">
<stereotypedrelationships>
<stereotypedrelationship constraint="Class" stereotype="MyProfile::MyConnector"/>
</stereotypedrelationships>
<AppliesTo>
<Apply type="Class"/>
</AppliesTo>
</Stereotype>

However, there is a slight wrinkle. This won't have Class as the only target. It will allow Class and all its specializations as valid targets. That probably won't matter to you unless you turn off filter to toolbox and drag the quicklinker to empty space, but I thought I should let you know anyway.

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #10 on: April 02, 2020, 02:41:02 pm »
I found this quite tricky and the help was quite unhelpful.

This article did help though :

https://community.sparxsystems.com/tutorials/1232-using-stereotyped-relationships-to-define-quicklink-rules

Good luck,
Rupert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #11 on: April 02, 2020, 04:02:58 pm »
Any thoughts on why you thought that was more useful?

Most of it is about technologies in general. I only see a few examples of the stereotyped relationship connector.

rupertkiwi

  • EA User
  • **
  • Posts: 133
  • Karma: +5/-0
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #12 on: April 03, 2020, 10:44:45 am »
I found the Metamodel Views extremely confusing.

In the article I attached there was a good working example so I used that and adapted it and it worked fine.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: In own MDG, constrain use of connector to certain elements
« Reply #13 on: April 03, 2020, 03:41:44 pm »
Yes, a good example UML profile model would be lot more helpful then all the complex explanations in the manual.

An example model says more than a thousand words ;)

Geert

Jacob Vos

  • EA User
  • **
  • Posts: 108
  • Karma: +0/-0
    • View Profile
Re: In own MDG, constrain use of connector to certain elements
« Reply #14 on: April 03, 2020, 08:19:54 pm »
And the solution was... upgrading from build 1514 to build 1528...

@Eve: I implemented already the metaconstraint you proposed. So it didn't work in build 1514 but in 1528.

@Rupertkiwi: thank you for sharing the link. That is indeed a very good addition to the Sparx helptext about defining profiles. (But not for the question I had now.)