Author Topic: Ultimate code for changing estereotype?  (Read 5568 times)

Mauricio Moya (Arquesoft)

  • EA User
  • **
  • Posts: 341
  • Karma: +8/-4
  • EA Consulting and development in Spanish
    • View Profile
    • Arquehub Azure Module
Ultimate code for changing estereotype?
« on: June 28, 2018, 06:43:39 am »
Hi. After several tests and reading several posts in the forum about different versions of EA, I'm a bit confused about the ultimate right way to change a stereotype programatically. In a simple scenary as follows:
-There are two stereotypes, from the same profile, extending the same metaclass
-Both stereotypes add the same tag values to the elements.

Sometimes you create the element with the wrong stereotype (A), and later you want to change it to the stereotype B (with a script). What is the right procedure?

I'm particulary confused with: element.Stereotype, element.StereotypeEx, element.FQStereotype, element.MetaType, element.SynchTaggedValues.

Thanks in advance.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Ultimate code for changing estereotype?
« Reply #1 on: June 28, 2018, 02:03:10 pm »
I've found that setting element.StereotypeEx always seems to do the job.

I hardly ever use any of the other methods/properties, if at all.

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Ultimate code for changing estereotype?
« Reply #2 on: June 28, 2018, 02:47:24 pm »
I'm particulary confused with: element.Stereotype, element.StereotypeEx, element.FQStereotype, element.MetaType, element.SynchTaggedValues.
  • Use StereotypeEx for every time you want to write a stereotype.
  • Use HasStereotype() for every time you want to check a stereotype.
  • Edge cases for appending a stereotype to the existing list or checking for any stereotype both use StereotypeEx.
  • FQStereotype is read only. It allows you to see the profile the first stereotype applied comes from.
  • MetaType allows you to get the Metatype defined for an applied stereotype. (It's not read only, but it ignores any assignment)
  • SynchTaggedValues() should be automatic when assigning a stereotype. It's useful if the stereotype definition has been updated or tags accidentally deleted

Mauricio Moya (Arquesoft)

  • EA User
  • **
  • Posts: 341
  • Karma: +8/-4
  • EA Consulting and development in Spanish
    • View Profile
    • Arquehub Azure Module
Re: Ultimate code for changing estereotype?
« Reply #3 on: June 29, 2018, 04:41:07 am »
So, the right way to do it is as follows?
Code: [Select]
element.StereotypeEx = "MyStereotype";
element.Update();

or like this?
Code: [Select]
element.StereotypeEx = "MyProfile::MyStereotype";
element.Update();

So, I think: how does EA know which one of two stereotypes (with the same name but in different profiles) you want to set?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Ultimate code for changing estereotype?
« Reply #4 on: June 29, 2018, 07:04:40 am »
The first one will (silently) add EAUML (the default profile). So I would guess. Any stereotype is only part of a profile. This has been introduced in some recent UML version (don't get me nailed on that). But EA still uses its glue-profile so you can stumble from one pitfall to the next.

It's strange (ehrm, no; not at all) that Stereotype (without Ex) has never been deprecated (like some other attributes/operations). EA is conziztent as its "Generalisation".

q.

Nizam

  • Prolab Moderator
  • EA User
  • *
  • Posts: 320
  • Karma: +15/-2
  • Model Sharing - Simplified
    • View Profile
    • Professional Model Collaboration
Re: Ultimate code for changing estereotype?
« Reply #5 on: June 29, 2018, 09:36:57 am »
Better to go with the FQ Name, and also take a note of the 'synchronize Stereotypes.' call

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Ultimate code for changing estereotype?
« Reply #6 on: July 02, 2018, 09:49:48 am »
The first one will (silently) add EAUML (the default profile). So I would guess. Any stereotype is only part of a profile.
Not quite true.

If you don't specify a fully qualified name, EA will apply a matching stereotype from any profile. Only if no matching stereotype exists will it create a new stereotype entry.

As a result, you get an insidious bug in your code. It works fine until some other profile including a stereotype with that name loads before yours.

Please... Always fully qualify your stereotypes.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Ultimate code for changing estereotype?
« Reply #7 on: July 02, 2018, 03:55:53 pm »
As a result, you get an insidious bug in your code. It works fine until some other profile including a stereotype with that name loads before yours.

Please... Always fully qualify your stereotypes.
Phew. Even worse :-( How about EA insisting on a FQN when checking the parameters?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Ultimate code for changing estereotype?
« Reply #8 on: July 02, 2018, 04:20:40 pm »
As a result, you get an insidious bug in your code. It works fine until some other profile including a stereotype with that name loads before yours.

Please... Always fully qualify your stereotypes.
Phew. Even worse :-( How about EA insisting on a FQN when checking the parameters?

q.
And breaking a bunch of existing working code?
I hope not.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Ultimate code for changing estereotype?
« Reply #9 on: July 02, 2018, 07:46:13 pm »
Well, that's the attitude still having "Generalisation" and other rotten stuff. Software is not dead. You have to work on it to keep it alive.

Of course it would have been better to require FQN in the first place when this operation had been introduced.

q.
« Last Edit: July 02, 2018, 07:49:43 pm by qwerty »