Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Tehila1 on March 20, 2016, 10:25:25 pm

Title: Is an EA.Package is an EA.Element
Post by: Tehila1 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?
Title: Re: Is an EA.Package is an EA.Element
Post by: Geert Bellekens 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.
Title: Re: Is an EA.Package is an EA.Element
Post by: Uffe 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
Title: Re: Is an EA.Package is an EA.Element
Post by: qwerty 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.
Title: Re: Is an EA.Package is an EA.Element
Post by: Eve 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.
Title: Re: Is an EA.Package is an EA.Element
Post by: qwerty 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 (http://sparxsystems.com/forums/smf/index.php/topic,24646.msg198399.html#msg198399)
Title: Re: Is an EA.Package is an EA.Element
Post by: Paolo F Cantoni 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