Book a Demo

Author Topic: Code Generation and Associations  (Read 7256 times)

ch

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Code Generation and Associations
« on: April 17, 2008, 09:38:31 pm »
Hi,
I've got a problem with Code Generation Templates. There are many classes and associations in my UML-diagram. I'm not interested in the classes, but the associations. I want to have a code to each association and its stereotype. Is there a template or are there any field substitution makros to get information about the association? I can't find anything about it :-(
Can anybody help?
Thanks,
leene

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Code Generation and Associations
« Reply #1 on: April 18, 2008, 05:54:25 pm »
Hi Leene,


I believe you're after the Connectors. An association is, as far as the CTF is concerned, a connector of type Association.

You can add code templates of type Connector, and within a template you can use the connector* macros (eg. connectorName, connectorType, connectorStereotype).

Hope this helps,


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

ch

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Code Generation and Associations
« Reply #2 on: April 18, 2008, 06:09:06 pm »
Yes!! That's great, thank you :-)

But now I've got another little problem. I search for all connectors, that reference a special class-attribute. So I need the name of this attribute in the connector-template. But in the connector-template of course I can't read class-attributes. I thought I could set a variable in class-template and read this in connector-template, but all variables are only locally. Is there a chance to get informations, which were read from another template?

Thanks,
Leene
« Last Edit: April 18, 2008, 06:38:05 pm by leene »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Code Generation and Associations
« Reply #3 on: April 21, 2008, 08:22:49 pm »
Hi again Leene,


You're in luck - there is.

<== WARNING - POSSIBLE SPOILER ALERT! ==>

... by which I mean to say this feature is not, strictly speaking, documented.

You can pass parameters between templates using the special variables $parameter1, $parameter2, etc in the called template. In the calling template you use a standard comma-separated ()-enclosed list of arguments. These can be values or macro references as in %myTemplate("someString", className)% (assuming you're calling from a Class template where %className% is meaningful).

This works well for single-call situations, but I haven't been able to pass a parameter into the %list% macro.
However, I'm not sure what it is you're trying to do. When you say your connectors reference a special class-attribute, what do you mean? Since connectors are between classes, I don't quite see what's going on.
Unless you mean the source or destination roles, which are available as macros.


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

ch

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Code Generation and Associations
« Reply #4 on: April 21, 2008, 09:31:35 pm »
Hey,
the solution for single-call situation is great :-)
But it doesn't help me, I must use the %list% macro :-(
That's what I'm trying to do (related to references in a database-model):
I have a class "classA" with attributes "attr1" and "attr2". Besides a class "classB" with attributes "attr1" and "attr2". Now I have a connector from "classA" to "classB". The roles are "attr1" (classA) and "attr2"(classB). Another connector (from "classB" to "classA") has the roles "attr1"(classB) and "attr2"(classA).
Now I'm in the "attribute"-template (classA-attr1) and call my own "connector"-template. This template should read all connectors, which sourceRole is this attribute (in this case classA-attr1).
But this template read all connectors of this class (from and to). I could build a big string with all necessary informations about all connectors (incl. seperators...) and save this to a variable in the "attribute"-template. And there I will search after this entry, which sourceRole is "attr1". But there are two entries (classA-attr1 -> classB-attr2 and classB-attr1 -> classA-attr2). So additionally I must check the sourceClass ("classA"). But there is still a problem. There are no macros "destinationClass" or "sourceClass".
Oh, that's many, I hope it's understandably.
Thanks again!

Leene
« Last Edit: April 21, 2008, 09:32:01 pm by leene »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Code Generation and Associations
« Reply #5 on: April 22, 2008, 09:24:53 pm »
Yo!


Yes, it's all understandable, except the big one - why? ;)

The macros to find the source and destination classes of a connector are there. All %class*% macros are available in the %connectorSource(Dest)Elem*% macros.

So if you're after the source class name you use %connectorSourceElemName%, if you want the destination class full name it's %connectorDestElemQualName%.

Inside your Connector template you're still (also) in a Class context, so %className% is valid. Which means you can check f'rinstance
%if className == connectorSourceElemName%
which will make sure the rest of the template is only executed at the source end of a connector.

However, I'm pretty sure (though I haven't tested this) that you're never in an Attribute context when in a Connector template. But UML-wise I'm not sure that having connectors with the same role names as attributes is a Great Idea[size=8]TM[/size] anyway.
There is no conceptual difference between an attribute and an association, so having both in the same class is the same as having two identically-named attributes - probably not what you want.
The association is a more explicit notation and also has more power in the CTF so I'd go with that.


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

ch

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Code Generation and Associations
« Reply #6 on: April 22, 2008, 10:25:49 pm »
It solves my problem :-)
Thank you very much for all your answers!