Book a Demo

Author Topic: Create RequiredInterface  (Read 5631 times)

thomaskilian

  • Guest
Create RequiredInterface
« on: June 19, 2007, 07:24:06 am »
Hi,
can someone help me in creating a Required Interface for a component? I tried $c->EmeddedElements->AddNew ("ReqIfaceName", "RequiredInterface") but I did not get a new value (nor an exception). What is wrong?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create RequiredInterface
« Reply #1 on: June 19, 2007, 08:56:49 am »
Hi Thomas,

The docs are a bit vague on this - I'm reading 811, which is much better than before, but not helpful here.

Apparently the collection involved (EmbeddedElements) comtains elements.
Quote
The Embedded Elements collection contains Element objects.

I wonder if you need to create an element, then somehow add it to the collection. How you would accomplish this is a bit of a mystery. But I do notice that there is a 'return' relationship in the model shown in the help file.

David
No, you can't have it!

thomaskilian

  • Guest
Re: Create RequiredInterface
« Reply #2 on: June 19, 2007, 01:45:20 pm »
Hi David,
I "thought" it should be like $package->Elements->AddNew ("Name", "Class"). The new documentation explicitly lists all the possible strings for the element type. I checked an existing component and found the RequiredInterface elements are inside $component->EmbeddedElements so I tried the AddNew for this collection. But it does not return a value.

Looks like Sparx needs to tell how this can be accomplished.

Edit: more carefully reading the documentation reveals that EmbeddedElements and Elements are R/O! No wonder I can't use AddNew. But still: How to add a RequiredInterface to a component ???

Edit (2): an AWKWARD workaround: create an element on package level. It seems as this needs to be something "legal" like "Interface" (but maybe it's the time?). Change the element type to "RequiredInterface". Set the ParentID to the components ElementID. And voila - there it is. But still: why not the straight way, Sparxians ??? ???
« Last Edit: June 19, 2007, 02:09:01 pm by thomaskilian »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create RequiredInterface
« Reply #3 on: June 19, 2007, 02:06:07 pm »
Thomas,

I have a sinking feeling that it will turn out to be something like "add them from the UI and then read them via automation at your leisure."

This is probably a list of pointers or something, with the elements being (hopefully) created elsewhere. There could be some kind of 'owner' link from the element side as well.

Perhaps you can get there through the back door. See if you can open a channel to the database - Jet or DBMS as appropriate - and then add the pointers and such via SQL. This approach has helped through some of the more painful read only issues with the API in the past.

[Re: EDIT 2. Ouch!]

David
« Last Edit: June 19, 2007, 02:20:04 pm by Midnight »
No, you can't have it!

thomaskilian

  • Guest
Re: Create RequiredInterface
« Reply #4 on: June 19, 2007, 02:10:04 pm »
(see Edit2 above)
Edit (3):When using my AWKWARD work around EA creates always ProvidedInterface elements - somehow! When I look at the properties I see Provided AND Required as I have told it to do. But when dbl-clicking it always tells both variants are ProvidedInterface. Also dragging it to a diagram they appear as provided.  ??? ??? ???

Btw: I'm using the latest Beta.

Edit(4): Now I found out that I need to set the Subtype for RequiredInterface to 1. This in fact shows the dbl-click correctly and also the drag-to-diagram. But why say "RequiredInterface" PLUS later Subtype = 1 ??? ??? ??? ??? Bit of overspecification? AND: in the browser I still see lollipops for both. (Maybe it vanishes after reload, but I leave that to you :-X)

Edit (5):guess...
I also forgot to mention: Although I told to remove the <<interface>> stereotype, EA did not do so and left it in the element. Now it's definitely too late to get also rid of that. Will do that likely with an SQL :(
« Last Edit: June 19, 2007, 03:45:31 pm by thomaskilian »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Create RequiredInterface
« Reply #5 on: June 19, 2007, 03:53:30 pm »
Sorry, I can't reply to all of this right now.  Send something in to sparx support about it.

Regarding the Read Only status of those collections.  According to the documentation all collection attributes are read-only.  This is technically correct, you can't assign another collection to that attribute, but misleading because you can edit the collection itself.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Create RequiredInterface
« Reply #6 on: June 19, 2007, 04:27:15 pm »
So perhaps there's hope.

Stay tuned...
No, you can't have it!

thomaskilian

  • Guest
Re: Create RequiredInterface
« Reply #7 on: June 19, 2007, 09:23:19 pm »
Bug report sent. Waiting for response...

markymark

  • Guest
Re: Create RequiredInterface
« Reply #8 on: June 20, 2007, 07:05:15 am »
Quote
Thomas,

Perhaps you can get there through the back door. See if you can open a channel to the database - Jet or DBMS as appropriate - and then add the pointers and such via SQL. This approach has helped through some of the more painful read only issues with the API in the past.


Hey Thomas -

Hope this helps (I typically mix and match automation interface tasks with a healthy dose of raw-SQL manipulation/reverse engineering).  I've got a few others of these, too... they've been fun :)

@InterfaceName is the name of the RequiredInterface that you want to create.

@FunctionName is the name of the Component that you want to add the RequiredInterface to.  It does an exact text match on the name, so make sure this matches.

The Classifier and Classifier_guid create the reference to the original interface that lives somewhere in my model, but you could tailor this based on your needs.


CREATE PROCEDURE InterfaceRequiredAdd
(

@InterfaceName nvarchar(255),

@FunctionName nvarchar(255)
)
AS

BEGIN TRANSACTION TREQUIRED

INSERT INTO

t_object
SELECT

'RequiredInterface' AS Object_Type,

0 AS Diagram_ID,

@InterfaceName AS [Name],

null AS Alias,

null AS Author,

'1.0' AS Version,

null AS Note,

0 AS Package_ID,

null AS Stereotype,

1 AS NType,

1 AS Complexity,

0 AS Effort,

null as Style,

-1 AS Backcolor,

0 AS BorderStyle,

-1 AS BorderWidth,

1 As FontColor,

0 AS Bordercolor,

GETDATE() AS CreatedDate,

GETDATE() AS ModifiedDate,

'Proposed' AS Status,

0 AS Abstract,

0 AS Tagged,

null AS PDATA1,

null AS PDATA2,

null AS PDATA3,

null AS PDATA4,

null AS PDATA5,

null AS Concurrency,

null AS Visibility,

null AS Persistance,

null as Cardinality,

'<none>' AS GenType,

null AS GenFile,

null AS Header1,

null AS Header2,

'1.0' AS Phase,

'Public' AS Scope,

null AS GenOption,

null AS GenLinks,

(SELECT [Object_ID] FROM t_object WHERE name = @InterfaceName AND Object_Type = 'Interface') AS Classifier,

'{' + CONVERT(nvarchar(40), NEWID()) + '}' AS ea_guid,

(SELECT [Object_ID] FROM t_object WHERE Object_Type = 'Component' AND Name = @FunctionName) AS ParentID,

null AS RunState,

(SELECT ea_guid FROM t_object WHERE name = @InterfaceName AND Object_Type = 'Interface') AS Classifier_guid,

0 AS TPos,

0 AS IsRoot,

0 AS IsLeaf,

0 AS IsSpec,

0 AS IsActive,

null AS StateFlags,

null AS PackageFlags,

null AS Multiplicity,

null AS StyleEx,

null AS EventFlags,

null AS ActionFlags

COMMIT TRANSACTION TREQUIRED

thomaskilian

  • Guest
Re: Create RequiredInterface
« Reply #9 on: June 20, 2007, 08:57:50 pm »
Thanks :) I doesn't help me (I use EAP files) but others might be grateful once in a while.