Book a Demo

Author Topic: Tagged values and Code Generation  (Read 5318 times)

TerryB

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Tagged values and Code Generation
« on: April 25, 2006, 01:56:58 am »
Hi Guys,

I'm pretty new to the Code Generation templates and I'm having problems getting the code generator to add tagged values to my code.

I'm using the tagged values in stereotypes almost as constants so it would be a great help if I could get these into my code through the generator. I can see how the attributes get in there but I just cant seem to find out how to apply the tagged values.

Any help gratefully accepted  ;D

Terry.
« Last Edit: April 25, 2006, 01:57:18 am by TerryB »
Research & Development Area
[email protected]

European Software Institute (ESI)
Tecnalia Corporación Tecnológica
Parque Tecnológico de Zamudio, # 204
E-48170 Zamudio
Bizkaia – Spain

thomaskilian

  • Guest
Re: Tagged values and Code Generation
« Reply #1 on: April 25, 2006, 04:11:20 am »
Search the help for "classtag". If you have further questions, reply here.

TerryB

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Tagged values and Code Generation
« Reply #2 on: April 25, 2006, 05:26:19 am »
Hi Thomas,

Yes I tried that, maybe I'm not using the "classtag" correctly or in the right place.

Here is what I've ammended in the Attribute Declaration template:

<-- tag value start -->
%classtag:"Attribute"%
<-- tag value end -->

the output I get is:

private int testParam = -1;<-- tag value start --><-- tag value end -->

and the tagged values are:

<Stereotype name="Element" notes="" cx="110" cy="70" bgcolor="-1" fontcolor="-1" bordercolor="-1" borderwidth="-1" hideicon="">
<AppliesTo>
<Apply type="Class"/>
</AppliesTo>
<Redefinitions/>
<TaggedValues>
<Tag name="width" type="int" description="" unit="" values="" default="99"/>
<Tag name="height" type="int" description="" unit="" values="" default="100"/>
</TaggedValues>
<Constraints/>
</Stereotype>
Research & Development Area
[email protected]

European Software Institute (ESI)
Tecnalia Corporación Tecnológica
Parque Tecnológico de Zamudio, # 204
E-48170 Zamudio
Bizkaia – Spain

thomaskilian

  • Guest
Re: Tagged values and Code Generation
« Reply #3 on: April 25, 2006, 12:58:56 pm »
I guess it's the case: try classTag (with capitalized T)

TerryB

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Tagged values and Code Generation
« Reply #4 on: April 26, 2006, 02:12:07 am »
Hi Thomas,

Still no luck. I tried with the capital T as you said:

<-- tag value start -->
%classTag:"Attribute"%
<-- tag value end -->

Terry
Research & Development Area
[email protected]

European Software Institute (ESI)
Tecnalia Corporación Tecnológica
Parque Tecnológico de Zamudio, # 204
E-48170 Zamudio
Bizkaia – Spain

thomaskilian

  • Guest
Re: Tagged values and Code Generation
« Reply #5 on: April 26, 2006, 03:09:12 am »
Terry,
as this seems to be a bit more difficult, I need some more info.  I try to summarize:
You have classes in your model which you assigned tagged values named "Attribute" containing arbitrary data. These are NOT the class attributes, right?
If you want to export the tags, your codegen macro for Class should contain the above statement. Could you provide us with a copy of the macro, or at least a code snippet?

TerryB

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Tagged values and Code Generation
« Reply #6 on: April 26, 2006, 03:52:51 am »
Hi Thomas,

I have a class (called "Class 1") in my model which is stereotyped from a class (called "Element"). The stereotyped class Element comes from a profile which I have created and imported into my new modelling project.

Im my modelling project I dragged this stereotyped class (which has 2 tagged values 'height' and 'width') from the tool box onto my diagram. To this stereotyped class (called "Class 1" on my diagram) I have added one attribute called "testParam" - this shows up fine in the code).

What I want to generate, apart from any normal attributes and operations assigned to this class is the tagged values which come from the stereotyped class.

I want to export these tagged values to Java as if they were "normal" attributes of the class

In the Attribute Declaration macro I added this:
<-- tag value start -->
%classTag:"height"%
<-- tag value end -->

which gives me the following output:
<-- tag value start -->100<-- tag value end -->

Upto now perfect  ;D

but what I want to achieve is akin to this:

private int height = 100;
private int width = 50;

So the questions is:
How can I reference all of my tagged values without using their specific names "width" & "height" and get them treated as if they were just normal attributes

I hope thats a bit clearer. If not please dont hesitate to ask for more details.

Thanks
Terry


Research & Development Area
[email protected]

European Software Institute (ESI)
Tecnalia Corporación Tecnológica
Parque Tecnológico de Zamudio, # 204
E-48170 Zamudio
Bizkaia – Spain

thomaskilian

  • Guest
Re: Tagged values and Code Generation
« Reply #7 on: April 26, 2006, 05:15:12 am »
Terry,
I'm sorry, but it is not possible to access Tags without knowing their name. I asked for something similar, but was told that it's not  possible.

Due to the limitations of the current code gen/transformation I started a bit of work (see here).  

TerryB

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Tagged values and Code Generation
« Reply #8 on: April 26, 2006, 05:25:46 am »
Thomas,

Thanks for your time and effort in answering - I'll see what I can come up with.

Cheers,
Terry.
Research & Development Area
[email protected]

European Software Institute (ESI)
Tecnalia Corporación Tecnológica
Parque Tecnológico de Zamudio, # 204
E-48170 Zamudio
Bizkaia – Spain

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Tagged values and Code Generation
« Reply #9 on: April 26, 2006, 03:05:45 pm »
Terry,

If (and only if) you have a small number of possible tags you need to evaluate and you know what they are in advance, you might be able to work around this with the HasTag(<tag>) function.

As I understand it this returns true if the element has the given tag applied. You could use this in an 'If' contstruct and then do whatever processing you want.

The obvious constraint is that you have to know the specific tags you would check when you write the code. Thus my caveats above, and the suggestion that this is at best a work around.

David
No, you can't have it!