Author Topic: Is an EA.Package is an EA.Element  (Read 6168 times)

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Is an EA.Package is an EA.Element
« on: March 20, 2016, 10:25:25 pm »
Hello,

I would like to convert an EA.Package to an EA.Element.
The following cast fails: 
Code: [Select]
EA.Package parentPackage = Repository.GetPackageByID(idOfParentPackage); // existing package. success
EA.Element parentPackageAsElement = parentPackage as EA.Element; // fails

Any ideas?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13282
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Is an EA.Package is an EA.Element
« Reply #1 on: March 21, 2016, 02:17:04 am »
Use Package.Element

Geert

PS. You should really try to read the manual, it's all there you know.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Is an EA.Package is an EA.Element
« Reply #2 on: March 31, 2016, 01:06:11 am »
Hello,


To go into a bit more detail, in EA's API a Package is not a subtype of Element. Casting between them won't do you any good. EA's API is not designed from the UML metamodel, and thank Christ for that.

In EA, each UML package is represented by both an EA.Package (and has a row in the t_package table), and an EA.Element (with a row in t_object).

EXCEPT project root nodes. A root node is represented only by an EA.Package, there is no corresponding EA.Element.

You can verify this by creating a new empty project and issuing the following SQL queries:
Code: [Select]
select * from t_package
select * from t_object

The first will return a single package named 'Model' with Package_ID 1 and Parent_ID 0.
The second won't return any results at all.

Then, create a package ("view") inside the project root and issue the queries again. There'll now be two t_package rows, and one t_object row with Object_Type 'Package'.

THAT stuff isn't in the manual. :)


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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Is an EA.Package is an EA.Element
« Reply #3 on: March 31, 2016, 05:14:47 am »
,
THAT stuff isn't in the manual. :)
What's also not in the manual: the GUID of the package and the corresponding element are identical.

q.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8063
  • Karma: +118/-20
    • View Profile
Re: Is an EA.Package is an EA.Element
« Reply #4 on: March 31, 2016, 09:12:00 am »
What's also not in the manual: the GUID of the package and the corresponding element are identical.
There's a good reason why that isn't in the manual... While it is usually true, it is not always true. If that's not good enough, compare PDATA1 (MiscData(0) in the API) of a Package object with the Package id of a package.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Is an EA.Package is an EA.Element
« Reply #5 on: March 31, 2016, 09:37:14 am »
Hmm. I had that wisdom from a Sparxian who did post it here some years ago. I did not find that myself.  Very sure. If my memory does not fail me badly.

q.

P.S.: Yessss! http://sparxsystems.com/forums/smf/index.php/topic,24646.msg198399.html#msg198399
« Last Edit: March 31, 2016, 09:40:40 am by qwerty »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8596
  • Karma: +256/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Is an EA.Package is an EA.Element
« Reply #6 on: March 31, 2016, 11:07:24 am »
What's also not in the manual: the GUID of the package and the corresponding element are identical.
There's a good reason why that isn't in the manual... While it is usually true, it is not always true. If that's not good enough, compare PDATA1 (MiscData(0) in the API) of a Package object with the Package id of a package.
What????   That's like telling me 1+1!=2

I think I'd rather run a consistency check to find those instances where it's not and fix it...

Since you're already telling us something that isn't in the manual, are there any known circumstances where the GUIDs aren't identical?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!