Book a Demo

Author Topic: JS Exception "Generalization is not legal for .."  (Read 6578 times)

sveng

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
JS Exception "Generalization is not legal for .."
« on: December 03, 2014, 12:02:27 am »
I try to add a "Generalization" connector to an element via JScript:

var p  as EA.Package;
p = Repository.GetPackageByGuid(TYPE_DEF_PACKAGE);
var elements as EA.Collection;
elements = p.Elements;
var typedefElement as EA.Element;
typedefElement = elements.AddNew( name, "Class" );
typedefElement.Stereotype = "typedef";
typedefElement.Update();
var newConnector as EA.Connector;
newConnector = typedefElement.Connectors.AddNew("","Generalization");
newConnector.SupplierID = 27;
newConnector.Update();

When calling "newConnector.Update()" I get the execption "Generalization is not legal for Class --> Class". What is the problem? A similar "typedef" element with a "Generalization" connector was created in my model by reverses engineering C++ code:

typedef enum {FILTER_NONE, FILTER_2AL} FILTER_TYPE;
typedef FILTER_TYPE EXPO_FILTER_TYPE;

Why can't I create a similar structure via JScript?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: JS Exception "Generalization is not legal for
« Reply #1 on: December 03, 2014, 05:18:59 am »
I had no issue running the above script.

q.

sveng

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: JS Exception "Generalization is not legal for
« Reply #2 on: December 03, 2014, 07:34:32 pm »
I'm using EA 11.1.1110. Do I need to change some settings in EA before I run the script? Which check in EA can cause an exception "Generalization is not legal for Class --> Class"?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: JS Exception "Generalization is not legal for
« Reply #3 on: December 03, 2014, 08:52:13 pm »
I seem to remember having seen such a compliance message but can't recall the circumstances. How does that message appear?

q.

sveng

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: JS Exception "Generalization is not legal for
« Reply #4 on: December 03, 2014, 08:57:11 pm »
I have an try-catch statement around the code:

try
{
      ...
}
catch(e)
{
      Session.Output("Exception occurred: "+e.description);
}

The output is then:
Exception occured: Generalization is not legal for Class --> Class

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: JS Exception "Generalization is not legal
« Reply #5 on: December 04, 2014, 12:48:17 am »
Have you configured some custom model validation? Does it happen if you run it in a plain EAP? What MDGs are you using?

q.
« Last Edit: December 04, 2014, 12:48:56 am by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: JS Exception "Generalization is not legal for
« Reply #6 on: December 04, 2014, 01:19:11 am »
It might also be the "strict UML syntax" option (although a Generalization between a Class and another Class seems perfectly valid UML syntax)

Geert

sveng

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: JS Exception "Generalization is not legal for
« Reply #7 on: December 04, 2014, 02:57:37 am »
Thanks a lot Geert! :)
This is the workaround:
I switched off "Tools->Options->Links->Strict Connector Syntax". Now I do not get the exception any more. You are right, that the current behavior is strange, because the created link is valid UML. The other strange thing is, that I do not get any error, when I create the link manually.
Sven

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: JS Exception "Generalization is not legal for
« Reply #8 on: December 04, 2014, 09:17:00 am »
Do the classes have stereotypes?
The Sparx Team
[email protected]

sveng

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: JS Exception "Generalization is not legal for
« Reply #9 on: December 04, 2014, 07:49:32 pm »
The client element is a Class type with "typedef" stereotype and the supplier element is an Enumeration type with "enumeration" stereotype

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: JS Exception "Generalization is not legal for
« Reply #10 on: December 04, 2014, 09:35:01 pm »
Strange. Now I also get the error. Even stranger: manually you can create it. The quick linker does not offer a Generalization from <<enumeartion>> to <<typedef>> but vice versa. The script throws an error in both directions.

q.