Book a Demo

Author Topic: Creating new connector in Transformation Template  (Read 3863 times)

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Creating new connector in Transformation Template
« on: June 06, 2007, 07:10:44 pm »
Hi,

I have difficulty in creating a new connector in XSD Transformation template. This is the scenario :
I want to create a new class based on an existing class and add a new connector which its type is Dependency and its stereotype is "derivedFrom". I have tried sample code from EA help :
Code: [Select]

Dependency
{
%TRANSFORM_REFERENCE("SourceDependency",classGUID)%
stereotype="derivedFrom"
Source
{
  %TRANSFORM_REFERENCE("Class",classGUID)%
}
Target
{
  GUID=%qt%%classGUID%%qt%
}
}


and put above code in the class template :
Code: [Select]

Class
{
 name=%qt%%className%%qt%

 %TRANSFORM_CURRENT("name")%
 %TRANSFORM_REFERENCE("XSDClass")%
%if elemType=="Class"%
%list="Attribute" @separator="\n" @indent="  "%
%endIf%
}

%list="Connector" @separator="\n" @indent="  "%
Dependency
{
%TRANSFORM_REFERENCE("SourceDependency",classGUID)%
stereotype="derivedFrom"
Source
{
  %TRANSFORM_REFERENCE("Class",classGUID)%
}
Target
{
  GUID=%qt%%classGUID%%qt%
}
}

But it did not work. The "derivedFrom" connector didn't appear on the Links tab of the class property.
What's wrong with my code?
Thanks.
« Last Edit: June 06, 2007, 08:25:34 pm by Kezia »

thomaskilian

  • Guest
Re: Creating new connector in Transformation Templ
« Reply #1 on: June 06, 2007, 09:42:13 pm »
I'm probably no good advisor here (I do transformation using the automation). But the Dependency part needs to be put into another macro (say sourceDep). This is then called via %list="sourceDep" @separator="\n" @indent="  "%

You need some kind of guard in sourceDep like
%if connectorType != "Dependency"%
%endTemplate%

There is a way to specify this with %list, but I'm not sure how.

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating new connector in Transformation Templ
« Reply #2 on: June 06, 2007, 11:03:33 pm »
Hi Thomas,

I have tried your suggested way by creating a new template and then called it in the class using %list. It didn't work.

Here is the Class template
Code: [Select]

Class
{
 name=%qt%%className%%qt%

 %TRANSFORM_CURRENT("name")%
 %TRANSFORM_REFERENCE("XSDClass")%
%if elemType=="Class"%
%list="Attribute" @separator="\n" @indent="  "%
%endIf%
}
%list="Connector_derivedFrom" @separator="\n" @indent="  "%
%list="Connector" @separator="\n" @indent="  "%


Here is the Connector_derivedFrom template
Code: [Select]

Dependency
{
%TRANSFORM_REFERENCE("SourceDependency",classGUID)%
stereotype="derivedFrom"
Source
{
  %TRANSFORM_REFERENCE("Class",classGUID)%
}
Target
{
  GUID=%qt%%classGUID%%qt%
}
}


It seems that %list macro would be only executed if there is any template in class with TemplateName as mentioned %list=<TemplateName>.
For example : %list="Attribute" @separator="\n" @indent="  "% --> if there is none Atribute, this will generate nothing instead of generate a new Attribute as I expected.
Am I right in above understanding? (I'm not sure about that)

What I want is, create a new connector with type "Dependency" and stereotype "derivedFrom", so there is no such as connector in the class before. I want this connector exists once on each class, so I think I should put it in the class template, to be executed each time class template executed.

Could you help me please?

thomaskilian

  • Guest
Re: Creating new connector in Transformation Templ
« Reply #3 on: June 07, 2007, 05:52:59 am »
Dependency  
{  
%TRANSFORM_REFERENCE("SourceDependency",classGUID)%  
stereotype="derivedFrom"  
Source  
{  
  %TRANSFORM_REFERENCE("Class",classGUID)%  
}  
Target  
{  
  GUID=%qt%%classGUID%%qt%  
}  
}  

can't work. The classGUID is only know in the class' context. There must be something for the connectors. Try to browse through the existing templates...

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating new connector in Transformation Templ
« Reply #4 on: June 07, 2007, 10:27:58 pm »
I have tried remove classGUID, the TRANSFORM_REFERENCE only provide name.
%TRANSFORM_REFERENCE("SourceDependency")%
By default transform reference will gets the GUID of current class. Not works.

Three days searching for the answer and too few documentation and sample make me desperate  :'(

Are there any code template expert who can help me?

Kezia

  • EA User
  • **
  • Posts: 33
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Creating new connector - I did it !
« Reply #5 on: June 07, 2007, 11:34:05 pm »
Inspire by NUnit Class Template. Finally I did it.
Here are the XSD Class Template code:

Class
{
 name=%qt%%className%%qt%

 %TRANSFORM_CURRENT("name")%
 %TRANSFORM_REFERENCE("MyClass")%
 %if elemType=="Class"%
 %list="Attribute" @separator="\n" @indent="  "%
 %endIf%
}

%list="Connector" @separator="\n" @indent="  "%

Dependency
{
 %TRANSFORM_REFERENCE("SourceDependency",classGUID)%
 stereotype="derivedFrom"
 Source
 {
   %TRANSFORM_REFERENCE("MyClass",classGUID)%
 }
 Target
 {
   GUID=%qt%%classGUID%%qt%
 }
}


I found my fault. It was at the "Source" of "Dependency" code. The TRANSFORM_REFERENCE name must be the same with TRANSFORM_REFERENCE name of the class.
Hope my answer helps the other who have the same problem.
Thanks to God :)

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Creating new connector in Transformation Templ
« Reply #6 on: June 08, 2007, 01:39:00 am »
Well done!

And thanks for the hint.
No, you can't have it!