Book a Demo

Author Topic: Extend metaclass Association + TemplateBindings  (Read 6673 times)

Dominik K

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Extend metaclass Association + TemplateBindings
« on: August 05, 2015, 10:19:05 pm »
Hello,

in our EA project we are using a custom UML profile. This profile contains a stereotype 'X' that extends the metaclass 'Association'.

In our EA plugin we access our EA project to automatically create connectors of stereotype 'X'. E.g.:
Code: [Select]
Connector conn = (Connector) source.Connectors.AddNew("name", "X");
conn.SupplierID = target.ElementID;
conn.Update();

Now, once we attempt to query the template bindings (conn.TemplateBindings; e.g. when iterating through the template bindings in a loop) of the connector of stereotype 'X', we run into a System.Runtime.InteropServices.SEHException ("External component has thrown an exception", ErrorCode: 0x80004005).

Interestingly, if we do the same connector creation but make the connector an "Association" instead of "X", no problem occurs. Furthermore, if we use a file based repository instead of a Database repository, no problem occurs.

Our environment is:
  • EA 12.0.214
  • Plugin written in C# (.NET Framework 4.5) using the Interop.EA.dll provided by the above mentioned version of EA
  • Microsoft SQL Server 2008 SP3

Could there be something wrong with our profile (any special settings required to be able to use template bindings)? Or could it be something with our database? Or should we just file a bug report?

Thanks
Dominik
« Last Edit: August 05, 2015, 10:20:33 pm by dominikk »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #1 on: August 06, 2015, 12:05:52 am »
I doubt that  AddNew("name", "X") works. To my knowledge you need to AddNew("name", "Association") (or what ever the base connector is) and then assign the stereotype to be "X".

q.
« Last Edit: August 06, 2015, 12:06:11 am by qwerty »

Dominik K

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #2 on: August 06, 2015, 12:44:30 am »
Thanks for your reply.
I changed the code to:
Code: [Select]
Connector conn = (Connector) source.Connectors.AddNew("name", "Association");
conn.SupplierID = target.ElementID;
conn.Stereotype = "X";
conn.Update();

Unfortunately, that doesn't solve the issue.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #3 on: August 06, 2015, 04:15:23 am »
With this Perl snippet
Code: [Select]
my $e1 = $rep->GetElementByGUID("{250B4CD6-C5CF-4dca-8A9E-7738264637F8}");
my $e2 = $rep->GetElementByGUID("{4260FC5A-29D8-43e3-A60F-1C5DEB4E352B}");
my $con = $e1->Connectors->AddNew("test", "Association");
$con->{Stereotype} = "ConversationLink";
$con->{SupplierID} = $e2->ElementID;
$con->Update();
I was able to create a BPMN ConversationLink. It was just necessary to reload the diagram to see the changes.

q.

Dominik K

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #4 on: August 06, 2015, 07:42:10 pm »
Hello qwerty,

thanks for the snippet. Could you also try to go one step further and iterate through the (probably empty) TemplateBindings collection of your ConversationLink? Is your repository using a (non-JET) database?

Thanks a lot
Dominik
« Last Edit: August 06, 2015, 08:47:19 pm by dominikk »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #5 on: August 06, 2015, 09:29:42 pm »
I guess it will not make sense to iterate template bindings right after creating a new connector, would it? I'm using Jet3 (IIRC) as default EAP. The code here should however be repository independent.

q.

Dominik K

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #6 on: August 06, 2015, 10:10:46 pm »
I agree, it doesn't make much sense. However, it reproduces our problem (SEHException) and I would expect that iterating an empy collection should not cause an Exception. Even when we try to iterate through the TemplateBindings collection way after the connector's creation (just to check whether TemplateBindings have been created by some other operation in the meantime) we get the Exception.

I've also reproduced the issue on a MySql 5 DBMS. So, I guess I'll try filing a bug report.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #7 on: August 06, 2015, 11:10:36 pm »
I ran it without issue (because count is zero). Can you post the snippet where you iterate?

q.

Dominik K

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #8 on: August 07, 2015, 12:26:29 am »
Sure, here's the snippet with the pseudo-iteration.
Note however that the problem only occurs if we use a DBMS (Microsoft SQL Server, MySQL) repository. Using a standard file/JET repository works just fine.

Code: [Select]
Connector connector = (Connector)source.Connectors.AddNew("name", "Association");
connector.SupplierID = target.ElementID;
connector.Stereotype = "X";
connector.Update();

// Throws SEHException.
foreach (var binding in connector.TemplateBindings)
{
     // nothing to do really...
}

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #9 on: August 07, 2015, 05:09:17 am »
I had a similar issue with Perl when not using the right type for the iterator. Have you tried using a for loop with connector.TemplateBindings.count instead?

q.

Dominik K

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #10 on: August 08, 2015, 01:07:56 am »
qwerty, thanks for your help so far.
I filed a bug report. Using TemplateBindings.Count does not solve the issue - see the following, small examle application:
Code: [Select]
class Program
{
    // Exemplary connection string.
    private static string ConnectionString =
        "ea_odbc --- DBType=0;Connect=Provider=MSDASQL.1;Persist Security Info=False;User ID=root;Data Source=ea_odbc;Initial Catalog=ea;LazyLoad=1;";

    static void Main(string[] args)
    {
        // Connect to repository.
        Repository repository = new RepositoryClass();
        repository.OpenFile(ConnectionString);

        // Create some test package.
        Package root = (Package)repository.Models.GetAt(0);
        Package testPackage = (Package)root.Packages.AddNew("TestPackage", string.Empty);
        testPackage.Update();
        root.Packages.Refresh();

        // Create two Elements.
        Element source = (Element)testPackage.Elements.AddNew("Source", "Class");
        source.Update();
        Element target = (Element)testPackage.Elements.AddNew("Target", "Class");
        target.Update();
        testPackage.Elements.Refresh();

        // Create and test a regular Association-Connector.
        {
            Connector connector = (Connector)source.Connectors.AddNew("Regular", "Association");
            connector.SupplierID = target.ElementID;
            connector.Update();
            source.Connectors.Refresh();

            Console.WriteLine(connector.TemplateBindings.Count); // Output is: 0
        }

        // Create and test a Connector with custom stereotype 'X'.
        {
            Connector connector = (Connector)source.Connectors.AddNew("Custom", "Association");
            connector.SupplierID = target.ElementID;
            connector.Stereotype = "X";
            connector.Update();
            source.Connectors.Refresh();

            Console.WriteLine(connector.TemplateBindings.Count); // Output is: 1
            if (connector.TemplateBindings.Count > 0)
            {
                // This throws an Exception! Why is there a TemplateBinding at this point and why is
                // an Exception thrown when accessing it?
                TemplateBinding templateBinding = (TemplateBinding)connector.TemplateBindings.GetAt(0);
            }
        }
    }
}

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Extend metaclass Association + TemplateBinding
« Reply #11 on: August 08, 2015, 03:01:12 am »
Really looks like a bug. No idea why you see an element in the collection right after creation.

q.