Book a Demo

Author Topic: Accessing attribute constraints within CTF/CTE  (Read 4093 times)

domi55

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Accessing attribute constraints within CTF/CTE
« on: February 28, 2012, 11:57:03 pm »
Hi

Is there a way to access the defined constraints for an attribute within the code template editor?



http://www.sparxsystems.com/uml_tool_guide/modeling/attributeconstraints.htm

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Accessing attribute constraints within CTF/CTE
« Reply #1 on: February 29, 2012, 08:47:49 am »
No. You can access them by calling an add-in. Do a search for EXEC_ADD_IN and you'll find some examples.

domi55

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Accessing attribute constraints within CTF/CTE
« Reply #2 on: March 01, 2012, 12:36:54 am »
Thanks Simon. I managed to create a little add-in. But unfortunately I have difficulties to retrieve the attribute constraints.

I can however get the attributes name for example:

Code Template Editor:
Code: [Select]
%EXEC_ADD_IN("IAGen", "getAttributeName", $attID)%
C# Code:
Code: [Select]
public object getAttributeName(EA.Repository Repository, object args)
{
    string[] arguments = (string[]) args;
    return Repository.GetAttributeByGuid(arguments[0]).Name;
}
This is code is just to show that my add-in actually works. ;)

C# Code for getting the attribute constraints:
Code: [Select]
public object getAttributeConstraints(EA.Repository Repository, object args)
{
    string[] arguments = (string[]) args;

     // create collection with constraint entries
     EA.Collection constraints = Repository.GetAttributeByGuid(arguments[0]).Constraints;

     // what do I have to return here? To which type do I have to cast constraints.GetAt(0) for example?

     return "";
}

So my questions is: How do I actually do the casting? I tried the following:

Code: [Select]
EA.Constraint b = (EA.Constraint) constraints.GetAt(0);
But this produces the following error:


domi55

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Accessing attribute constraints within CTF/CTE
« Reply #3 on: March 01, 2012, 01:31:32 am »
NVM. I solved the "problem" by using:

Code: [Select]
EA.IDualAttributeConstraint b = (EA.IDualAttributeConstraint) constraints.GetAt(0);