Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Only one file for many classes, here my code.
Only one file for many classes, here my code. [message #780668] Wed, 18 January 2012 23:06 Go to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Hi all...

I am trying to generate only one file for model. (One model contains a class diagram with many classes).
For example, I want to create a txt file with all the names of the classes.

I have done this:

[comment encoding = UTF-8 /]
[module generate('.../uml2/3.0.0/UML')]


[template public Main(aClass : Class)]

[comment @main/]
[file (aClass.name.concat('.txt'), false)]		
    [printNameClass(aClass)/]
[/file]


If I have a model with 4 classes, this code generates four different file with the name of their class.

I want to create only one file with all the four names. How can I do it?
Thanks.

[Updated on: Thu, 19 January 2012 00:51]

Report message to a moderator

Re: Only one file for many classes, here my code. [message #780711 is a reply to message #780668] Thu, 19 January 2012 07:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

why do you define your template for a uml::Class if you want to define it for a uml::Model?
and then navigate through/search the model for classes and output them.
an imported thing when you do MDD is: know the metamodel

~Christian
Re: Only one file for many classes, here my code. [message #780737 is a reply to message #780711] Thu, 19 January 2012 09:14 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/uml2/3.0.0/UML')]


[template public Main(aClass : Model)]

[comment @main/]
[file (aClass.name.concat('.txt'),  false, 'UTF-8')]
    [print(aClass)/]
[/file]

[/template]
[template public print(aClass : Model)]
Classname  [aClass.name/],
visibility [aClass.visibility/]
[/template]


If I change the "Class" with "Model" I'm not able to access the class name.
It wrote "Data" instead of the class name.

How can I iterate for all the class name?
Its really hard to find in that guide.
Re: Only one file for many classes, here my code. [message #780740 is a reply to message #780737] Thu, 19 January 2012 09:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

i said: you have to navigate from the model to the classes

~Christian
Re: Only one file for many classes, here my code. [message #780741 is a reply to message #780737] Thu, 19 January 2012 09:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
Hi

This is OO.

"a".toUpperCase() works in Java but 4.toUpperCase() doesn't; I wonder why?

Regards

Ed Willink

On 19/01/2012 09:14, Davide P wrote:
>
> [comment encoding = UTF-8 /]
> [module generate('http://www.eclipse.org/uml2/3.0.0/UML')]
>
>
> [template public Main(aClass : Model)]
>
> [comment @main/]
> [file (aClass.name.concat('.txt'), false, 'UTF-8')]
> [print(aClass)/]
> [/file]
>
> [/template]
> [template public print(aClass : Model)]
> Classname [aClass.name/],
> visibility [aClass.visibility/]
> [/template]
>
>
> If I change the "Class" with "Model" I'm not able to access the class
> name.
> It wrote "Data" instead of the class name.
>
> How can I iterate for all the class name?
> Its really hard to find in that guide.
Re: Only one file for many classes, here my code. [message #780775 is a reply to message #780668] Thu, 19 January 2012 10:54 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
The syntax is not clear and even the way on how to print the class names in one file.

Can you give a real example please?
Re: Only one file for many classes, here my code. [message #780792 is a reply to message #780775] Thu, 19 January 2012 11:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

http://wiki.eclipse.org/Acceleo/Getting_Started
should give you all information you need to do the task.
if you have a file that does correctly traverse the AST
and then still have problems to output the names
you can ask again Wink

~Christian
Re: Only one file for many classes, here my code. [message #780802 is a reply to message #780792] Thu, 19 January 2012 12:47 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Christian Dietrich wrote on Thu, 19 January 2012 06:45
Hi,

http://wiki.eclipse.org/Acceleo/Getting_Started
should give you all information you need to do the task.
if you have a file that does correctly traverse the AST
and then still have problems to output the names
you can ask again Wink

~Christian


I have read and re-read that quick start guide but there is no syntax,
no explanations on how to traverse the AST since the only example is the one that generate one file per class.
Re: Only one file for many classes, here my code. [message #780807 is a reply to message #780802] Thu, 19 January 2012 12:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

still the same.

(1) how to traverse. you need to know the metamodel. in Xpand such a traversation would look like

«IMPORT uml»

«DEFINE main FOR Model»
«FILE "test.txt"»
«EXPAND handlePackageElement FOREACH this.packagedElement»
«ENDFILE»
«ENDDEFINE»

«REM»Just a Fallback«ENDREM»
«DEFINE handlePackageElement FOR PackageableElement»
«ENDDEFINE»

«DEFINE handlePackageElement FOR Package»
«EXPAND handlePackageElement FOREACH this.packagedElement»
«ENDDEFINE»

«DEFINE handlePackageElement FOR Class»
Class: «this.name»
«ENDDEFINE»


(2) how to technically traverse with acceleo you can find here

 [template public umlToBeans(aPackage : Package)]
 [comment @main /]
 [for (aClass : Class | aPackage.packagedElement->filter(Class))]
 	[aClass.generate()/]
 [/for]
 [/template]


and how to get everything into one file:

do the same in acceleo than you do in xpand.

the tutorial contains an example for even this too

 [template public generate(aClass : Class)]
 [file (aClass.name.concat('.java'), false)]
   public class [aClass.name.toUpperFirst()/] {
   [for (p: Property | aClass.attribute) separator('\n')]
     private [p.type.name/] [p.name/];
   [/for]
 
   [for (p: Property | aClass.attribute) separator('\n')]
     public [p.type.name/] get[p.name.toUpperFirst()/]() {
       return this.[p.name/];
     }
   [/for]
 
   [for (o: Operation | aClass.ownedOperation) separator('\n')]
     public [o.type.name/] [o.name/]() {
       // TODO should be implemented
     }
   [/for]
   }
 [/file]
 [/template]


the properties go into the same file as the class does. what a miracle.

~Christian
Re: Only one file for many classes, here my code. [message #780862 is a reply to message #780807] Thu, 19 January 2012 17:39 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Christian Dietrich wrote on Thu, 19 January 2012 07:58

the properties go into the same file as the class does. what a miracle.

~Christian


For first thanks for the answer, I really appreciate your help but
that code does not solve the problem since it generates n file for n classes.

the code you have posted:
 [template public umlToBeans(aPackage : Package)]
 [comment @main /]
 [for (aClass : Class | aPackage.packagedElement->filter(Class))]
 	[aClass.generate()/]
 [/for]
 [/template]

 [template public generate(aClass : Class)]
 [file (aClass.name.concat('.java'), false)]
   public class [aClass.name.toUpperFirst()/] {
   [for (p: Property | aClass.attribute) separator('\n')]
     private [p.type.name/] [p.name/];
   [/for]
 
   [for (p: Property | aClass.attribute) separator('\n')]
     public [p.type.name/] get[p.name.toUpperFirst()/]() {
       return this.[p.name/];
     }
   [/for]
 
   [for (o: Operation | aClass.ownedOperation) separator('\n')]
     public [o.type.name/] [o.name/]() {
       // TODO should be implemented
     }
   [/for]
   }
 [/file]
 [/template]


generates exactly the same things that my original code generates with "different" requests.

This is my original code:
[template public Main(aClass : Class)]
[comment @main/]
[file (aClass.name.concat('.txt'),  false, 'UTF-8')]
    [print(aClass)/]
[/file]
[/template]

[template public print(aClass : Class)]
Class name = [aClass.name/]
[/template]


As I asked, I need to generate only one output file with the names of the classes contained in the model.
If my model have 4 classes for example, I need to create only one output file containing the name of the four classes.

With mine and yours code, acceleo generates four output file for four classes.

Any help is much appreciated.
Thanks.

[Updated on: Thu, 19 January 2012 17:40]

Report message to a moderator

Re: Only one file for many classes, here my code. [message #780864 is a reply to message #780862] Thu, 19 January 2012 17:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
HI,

i wont do your homework. i wanted to tell you that you should create a file like

THIS IS A TEMPLATE FOR A UML::MODEL
FILE "FILENAME.TXT"
TRAVERSE THE MODEL AND SREACH THE CLASSES AND OOUTPUT THEIR NAME
ENDFILE
ENDOFTHETEMPLATE


Re: Only one file for many classes, here my code. [message #780870 is a reply to message #780864] Thu, 19 January 2012 18:36 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Christian Dietrich wrote on Thu, 19 January 2012 12:48
HI,

i wont do your homework. i wanted to tell you that you should create a file like

THIS IS A TEMPLATE FOR A UML::MODEL
FILE "FILENAME.TXT"
TRAVERSE THE MODEL AND SREACH THE CLASSES AND OOUTPUT THEIR NAME
ENDFILE
ENDOFTHETEMPLATE




I have a degree in computer science, don't call it homework Smile
The homework time is finished, now I need to choose if use acceleo in my company or not so I am studying it Smile

In any case, your suggestion is really much appreciated and I thank you for your help/patience.
I tought you gived me the solution but, I understood the code now and "adjusted" the shot.

Now I can print all the class names in one file. Thanks.
I will continue my excercise. I will post some more question here, if I'll have questions, hope you will be here Smile

Again, many thanks.


Re: Only one file for many classes, here my code. [message #780933 is a reply to message #780870] Fri, 20 January 2012 00:38 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Ok, I'm continuing with my excercises. Really hard for me to open mind to this new concept but slowly, something is moving.

This is my latest code to print all the class name on a file and to print
the the generalizations.

I have two classes with a generalization.
A dog class and an animal class.
A dog is an animal.

I want to print that a dog is an animal
[template public umlToBeans(aPackage : Package)]
[comment @main /]
[for (aClass : Class | aPackage.packagedElement->filter(Class))]
	[aClass.generate()/]
[/for]
[/template]

[template public generate(aClass : Class)]
[file ('Output.txt', true)]

[aClass.name.toUpperFirst()/] is an  
[for (p: Generalization | aClass.generalization) separator('')]
	[p.target/] // I think that the problem is here
[/for]

[/file]
[/template]


the output is:
Dog is an  
	org.eclipse.uml2.uml.internal.impl.ClassImpl@1a4f105 (name: animal, visibility: <unset>) (isLeaf: false, isAbstract: true) (isActive: false)


I think that the problem is in the [p.target/] should I use something like [p.target.name/] to extract only the class name ???

What is the correct [p.target.???/] to extract only the class name?
Many thanks for the help, if any.

Re: Only one file for many classes, here my code. [message #781047 is a reply to message #780933] Fri, 20 January 2012 07:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

one more my advice: have a look at/know the metamodel - you would see that the Target ist of type Element that has a subclass NamedElement that has a subsub..class Class. Only NamedElements have a name

~Christian

[Updated on: Fri, 20 January 2012 10:51]

Report message to a moderator

Re: Only one file for many classes, here my code. [message #781085 is a reply to message #781047] Fri, 20 January 2012 13:38 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Christian Dietrich wrote on Fri, 20 January 2012 02:57
Hi,

one more my advice: have a look at/know the metamodel - you would see that the Target ist of type Element that has a subclass NamedElement that has a subsub..class Class. Only NamedElements have a name

~Christian


I'm looking at metamodel, I have also opened the .uml file to try to understand something more but I can't understand the way to access the information I need.
I have got my degree in CS without problem, I should not be too much stupid, why it is so difficult?
Re: Only one file for many classes, here my code. [message #781107 is a reply to message #781085] Fri, 20 January 2012 14:50 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Solved with this:
[for (it : Generalization | aClass.generalization)]
[aClass.name.toUpperFirst()/] is a [it.general.name/]
[/for]


Christian don't leave me alone, I will back with other questions Smile

Re: Only one file for many classes, here my code. [message #781108 is a reply to message #781107] Fri, 20 January 2012 14:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

i am still not sure if you understood the problem.

consider you have following Java Interfaces

public interface Relationship {
	Element getTarget();
}


public interface Element {
}


public interface NamedElement extends Element {
	String getName();
}


public interface Class extends NamedElement{
}


so now you should know/understand the problem
how to solve it

(1) use some if else and typechecks (ocliskindof)
(2) Acceleo (as Xpand) supports Polymorphic Dispatch
this fact should help you to solve the problem

thus the solution for your last problem could have looked like
[template public generateElement(model : Model)]
[comment @main/]
[file ('test.txt', false, 'UTF-8')]
[for (e : Element | model.ownedElement)]
[gen(e)/]	
[/for]
[/file]
[/template]

[template public gen(c : Class)]
	Class: [c.name/]
[/template]

[template public gen(p : Package)]
	[for (e : Element | p.ownedElement)]
	[gen(e)/]	
	[/for]
[/template]

[template public gen(c : Element)]
[/template]


this should help you to handle only elements that are of type Class and throw the other ones to /dev/null
Re: Only one file for many classes, here my code. [message #781118 is a reply to message #781108] Fri, 20 January 2012 15:36 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
we are solving many problems, thanks.

Now I would like to understand how to output aggregations.
Suppose that I have two classes. professor and class.
The Prof. class is aggregate with the class.
A prof has a class, and a class has 1 or more professor.

How can I output something like????:
A prof has a class, and a class has 1 or more professor.
Re: Only one file for many classes, here my code. [message #781121 is a reply to message #781118] Fri, 20 January 2012 15:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

can you ask a bit more specific? what do you have so far? what is the problem?
where do you stuck. if you can post your uml model (as xmi) this would help to

~Christian
Re: Only one file for many classes, here my code. [message #781123 is a reply to message #781121] Fri, 20 January 2012 16:00 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
The problem is that I would like to be able to output pure text from my model.
My model has two classes with an aggregation. The aggregation has multiplicity.

Here the graph:
http://dl.dropbox.com/u/17948666/Cattura.PNG

and the XMI
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:MagicDrawProfile="http:///schemas/MagicDrawProfile/_A4FSYEN_EeGoiIIHlWCcOg/0" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xsi:schemaLocation="http:///schemas/MagicDrawProfile/_A4FSYEN_EeGoiIIHlWCcOg/0 UML_Standard_Profile.MagicDraw_Profile.profile.uml#_BCa8fEN_EeGoiIIHlWCcOg">
  <uml:Model xmi:id="eee_1045467100313_135436_1" name="Data" viewpoint="">
    <ownedComment xmi:id="_17_0_1_1ba9049a_1326912648883_309493_1662" body="Author:sblantipodi.&#xA;Created:18/01/12 19.50.&#xA;Title:.&#xA;Comment:.&#xA;" annotatedElement="eee_1045467100313_135436_1"/>
    <packageImport xmi:id="_0primitiveTypesData">
      <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
    </packageImport>
    <packageImport xmi:id="_0javaPrimitiveTypesData">
      <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/JavaPrimitiveTypes.library.uml#_0"/>
    </packageImport>
    <packagedElement xmi:type="uml:Package" xmi:id="magicdraw_uml_standard_profile_v_0001" name="UML Standard Profile">
      <ownedComment xmi:id="_be00301_1078843546940_242228_131" body="UML Standard Profile contains UML metamodel (metaclasses without properties and associations), StandardProfileL2 and StandardProfileL3 from UML specification, Standard UML stereotypes defined in annex C of UML specification.&#xA;Profile also includes validation suites for UML model correctness and completeness checking, and stereotypes used by MagicDraw internally." annotatedElement="magicdraw_uml_standard_profile_v_0001"/>
    </packagedElement>
    <packagedElement xmi:type="uml:Class" xmi:id="_17_0_1_1ba9049a_1327074778132_919593_1703" name="Professor">
      <ownedAttribute xmi:id="_17_0_1_1ba9049a_1327074809505_294617_1746" name="" visibility="private" type="_17_0_1_1ba9049a_1327074788204_444995_1723" aggregation="shared" association="_17_0_1_1ba9049a_1327074809505_547161_1745">
        <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_17_0_1_1ba9049a_1327074817990_295136_1764" name="" value="*"/>
        <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_17_0_1_1ba9049a_1327074817990_964208_1763" name="" value="1"/>
      </ownedAttribute>
    </packagedElement>
    <packagedElement xmi:type="uml:Class" xmi:id="_17_0_1_1ba9049a_1327074788204_444995_1723" name="Class"/>
    <packagedElement xmi:type="uml:Association" xmi:id="_17_0_1_1ba9049a_1327074809505_547161_1745" name="" memberEnd="_17_0_1_1ba9049a_1327074809505_60393_1747 _17_0_1_1ba9049a_1327074809505_294617_1746">
      <ownedEnd xmi:id="_17_0_1_1ba9049a_1327074809505_60393_1747" name="" visibility="private" type="_17_0_1_1ba9049a_1327074778132_919593_1703" association="_17_0_1_1ba9049a_1327074809505_547161_1745">
        <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_17_0_1_1ba9049a_1327074824675_954139_1770" name="" value="1"/>
        <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_17_0_1_1ba9049a_1327074824675_721954_1769" name="" value="1"/>
      </ownedEnd>
    </packagedElement>
    <profileApplication xmi:id="_16_8beta_62a020a_1256807755193_508228_378profileApplicationData">
      <eAnnotations xmi:id="_BCdWYEN_EeGoiIIHlWCcOg" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="UML_Standard_Profile.StandardProfileL3.profile.uml#_BCaUgEN_EeGoiIIHlWCcOg"/>
      </eAnnotations>
      <appliedProfile href="UML_Standard_Profile.StandardProfileL3.profile.uml#_16_8beta_62a020a_1256807755193_508228_378"/>
    </profileApplication>
    <profileApplication xmi:id="_11_5_f720368_1159529670215_231387_1profileApplicationData">
      <eAnnotations xmi:id="_BCd9cUN_EeGoiIIHlWCcOg" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="UML_Standard_Profile.Validation_Profile.profile.uml#_BCaVQEN_EeGoiIIHlWCcOg"/>
      </eAnnotations>
      <appliedProfile href="UML_Standard_Profile.Validation_Profile.profile.uml#_11_5_f720368_1159529670215_231387_1"/>
    </profileApplication>
    <profileApplication xmi:id="_11_5_be00301_1153310565718_226811_161profileApplicationData">
      <eAnnotations xmi:id="_BCfyoEN_EeGoiIIHlWCcOg" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="UML_Standard_Profile.MagicDraw_Profile.DSL_Customization.profile.uml#_BCZsAkN_EeGoiIIHlWCcOg"/>
      </eAnnotations>
      <appliedProfile href="UML_Standard_Profile.MagicDraw_Profile.DSL_Customization.profile.uml#_11_5_be00301_1153310565718_226811_161"/>
    </profileApplication>
    <profileApplication xmi:id="_be00301_1073394351331_445580_2profileApplicationData">
      <eAnnotations xmi:id="_BCfyokN_EeGoiIIHlWCcOg" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="UML_Standard_Profile.MagicDraw_Profile.profile.uml#_BCa8fEN_EeGoiIIHlWCcOg"/>
      </eAnnotations>
      <appliedProfile href="UML_Standard_Profile.MagicDraw_Profile.profile.uml#_be00301_1073394351331_445580_2"/>
    </profileApplication>
    <profileApplication xmi:id="_16_6_8f90291_1254846042821_86742_517profileApplicationData">
      <eAnnotations xmi:id="_BCfypEN_EeGoiIIHlWCcOg" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="UML_Standard_Profile.MagicDraw_Profile.Traceability_customization.profile.uml#_BCaUhkN_EeGoiIIHlWCcOg"/>
      </eAnnotations>
      <appliedProfile href="UML_Standard_Profile.MagicDraw_Profile.Traceability_customization.profile.uml#_16_6_8f90291_1254846042821_86742_517"/>
    </profileApplication>
    <profileApplication xmi:id="_9_0_be00301_1108050582343_527400_10847profileApplicationData">
      <eAnnotations xmi:id="_BCfypkN_EeGoiIIHlWCcOg" source="http://www.eclipse.org/uml2/2.0.0/UML">
        <references xmi:type="ecore:EPackage" href="UML_Standard_Profile.StandardProfileL2.profile.uml#_BCaVOkN_EeGoiIIHlWCcOg"/>
      </eAnnotations>
      <appliedProfile href="UML_Standard_Profile.StandardProfileL2.profile.uml#_9_0_be00301_1108050582343_527400_10847"/>
    </profileApplication>
  </uml:Model>
  <MagicDrawProfile:auxiliaryResource xmi:id="_BC_h4EN_EeGoiIIHlWCcOg" base_Element="magicdraw_uml_standard_profile_v_0001" base_Package="magicdraw_uml_standard_profile_v_0001"/>
</xmi:XMI>


From this simple model, I would like to output a simple text like the one I saied.
Another phrases that I would like to output for example.
A professor can aggregate a class. A class can aggregate 1 or more professor.

Is it possible to output a phrase like this?


Re: Only one file for many classes, here my code. [message #781137 is a reply to message #781123] Fri, 20 January 2012 16:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

this is once more a question on the uml metamodel and not one on acceleo. so asking the uml forum or having a look at the uml metamodel would
once more help. ( i know that uml is ugly but you have to blame the OMG for that

[template public generateElement(aModel : Model)]
[comment @main /]
[file ('test.txt', false, 'Cp1252')]
	[for (a : Association | aModel.eAllContents(Association))]
A [a.memberEnd->at(1).type.name/] has [a.memberEnd->at(2).lower/] [a.memberEnd->at(2).upper/] [a.memberEnd->at(2).type.name/].
A [a.memberEnd->at(2).type.name/] has [a.memberEnd->at(1).lower/] [a.memberEnd->at(1).upper/] [a.memberEnd->at(1).type.name/].   
	[/for]
[/file]
[/template]


~Christian
Re: Only one file for many classes, here my code. [message #781154 is a reply to message #781137] Fri, 20 January 2012 18:13 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
You are a good Professor Christian, I really appreciate your help.
You have teached me a lot and I'm really greatful for this.

I don't want to hurt your patience but I have the last question if possible.

In the way you teached me I can see if I have a "link" between two classes but I can't know if this link is a composition, an aggregation or an association.
Is it possible to print something like??:
A Professor has 1 * Class and it is a aggregation.

obviously the "and it is a aggregation" phrase should be added only if its true that it is an aggregation and not a normal association.
Re: Only one file for many classes, here my code. [message #781157 is a reply to message #781154] Fri, 20 January 2012 18:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

you can inspect the aggregation kind: [a.memberEnd->at(1).aggregation/]

~Christian
Re: Only one file for many classes, here my code. [message #781189 is a reply to message #781157] Fri, 20 January 2012 19:49 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
great. but why there isn't something like:
[a.memberEnd->at(1).composition/]
???
Re: Only one file for many classes, here my code. [message #781207 is a reply to message #781189] Fri, 20 January 2012 20:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Hi,

you make a destinction that does not exist. a composition is a special aggregtion
http://geertbellekens.wordpress.com/2010/12/20/uml-composition-vs-aggregation-vs-association/

~Christian
Re: Only one file for many classes, here my code. [message #781211 is a reply to message #781207] Fri, 20 January 2012 20:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
P.S: in doubt have a look at the specs http://www.omg.org/spec/UML/2.4.1/Superstructure/PDF/

~Christian
Re: Only one file for many classes, here my code. [message #781252 is a reply to message #781211] Fri, 20 January 2012 21:36 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
I know the difference between Composition and Aggregation.
As you see in the guide you posted UML has two different arrow to illustrate a composition or an aggregation.

That guide says that an aggregationKind can be
none
Indicates that the property has no aggregation.

shared
Indicates that the property has a shared aggregation.

composite
Indicates that the property is aggregated compositely, i.e., the composite

In this case this:
[a.memberEnd->at(1).aggregation/]
should return none, shared, composite.

In my code it returns only none or shared, it never return composite also if
I specified a composition in my diagram using magic draw.
Re: Only one file for many classes, here my code. [message #781265 is a reply to message #781252] Fri, 20 January 2012 21:57 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
I'm really sorry
[a.memberEnd->at(1).aggregation/]
[a.memberEnd->at(2).aggregation/]

Now correctly output shared, composite or none.

Thanks a million professor, I finished with my questions.
You really helped me a lot, thanks a billion Smile

See you here around Smile
Re: Only one file for many classes, here my code. [message #781448 is a reply to message #781189] Sat, 21 January 2012 08:51 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
On 20/01/2012 19:49, Dave Donald wrote:
> great. but why there isn't something like:
> [a.memberEnd->at(1).composition/]
> ???
It's

aggregation : AggregationKind

Regards

Ed Willink
Re: Only one file for many classes, here my code. [message #781930 is a reply to message #781448] Sun, 22 January 2012 19:22 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Hi all...
I have written this code to print the enumations's name of my model along with its properties.

My model contains only one enumaration like this:
http://dl.dropbox.com/u/17948666/enumartion.PNG

The MTL code is this:
[template public stampaEnumerazioni(aEnumeration : Enumeration)]
[comment @main /]
[file ('test.txt', true, 'UTF-8')]
[aEnumeration.name/] is an enumeration.
Property:
[aEnumeration.eAllContents().eAllContents()/]
[/file]
[/template]


The output correctly print the enumeration name with the properties.
TemperatureScale is an enumeration.
Property:
org.eclipse.uml2.uml.internal.impl.EnumerationLiteralImpl@2e7ceb (name: Celsius, visibility: <unset>)org.eclipse.uml2.uml.internal.impl.EnumerationLiteralImpl@b3be2 (name: Fahreneit, visibility: <unset>)org.eclipse.uml2.uml.internal.impl.EnumerationLiteralImpl@1888e26 (name: Kelvin, visibility: <unset>)org.eclipse.uml2.uml.internal.impl.EnumerationLiteralImpl@2c6ee9 (name: Rankine, visibility: <unset>)


I would like to filter the output to get something like this:
TemperatureScale is an enumeration.
Property:
Celsius
Fahreneit
Kelvin
Rankine

Is it possible? Should I add some filter to:
[aEnumeration.eAllContents().eAllContents()/]
if yes how? If no, how can I do it?

Thanks for any help you could give. Smile

Re: Only one file for many classes, here my code. [message #781940 is a reply to message #781930] Sun, 22 January 2012 19:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6499
Registered: July 2009
Senior Member
Strange Things you do: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.uml2.doc%2Freferences%2Fjavadoc%2Forg%2Feclipse%2Fuml2%2Fuml%2FEnumeration.html
Re: Only one file for many classes, here my code. [message #781999 is a reply to message #781940] Sun, 22 January 2012 23:42 Go to previous messageGo to next message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
really thanks for the answer dear christian but is there a "command" in acceleo to filter some output like the one I saied in the previous post?

Re: Only one file for many classes, here my code. [message #782152 is a reply to message #781999] Mon, 23 January 2012 09:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4154
Registered: July 2009
Senior Member
Hi

Christian has consistently been saying 'know your meta-model'

[aEnumeration.eAllContents().eAllContents()/]

Is incredibly stupid, but fortunately enumerations only have limited
content so the N-squared usage is not catastrophic.

Christiain pointed you at the Java version of your meta-model where you
will find an accessor for the literals. If you look at the true
meta-model in the UML spec or the UML2 project you won't get confused by
EMF's Java encoding of the model features.

Regards

Ed Willink

On 22/01/2012 23:42, Dave Donald wrote:
> really thanks for the answer dear christian but is there a "command"
> in acceleo to filter some output like the one I saied in the previous
> post?
>
>
Re: Only one file for many classes, here my code. [message #782460 is a reply to message #782152] Mon, 23 January 2012 18:46 Go to previous message
Dave Donald is currently offline Dave DonaldFriend
Messages: 26
Registered: January 2012
Junior Member
Edward Willink wrote on Mon, 23 January 2012 04:15

[aEnumeration.eAllContents().eAllContents()/]

Is incredibly stupid, but fortunately enumerations only have limited
content so the N-squared usage is not catastrophic.>


Not catastrophic but it output anything.
There is not output at all from
[aEnumeration.eAllContents().eAllContents()/]
Previous Topic:Using either globalvardef or property in both workflow and Xpand
Next Topic:[xtend] Casting to Subclass in Template
Goto Forum:
  


Current Time: Wed Nov 26 17:45:41 GMT 2014

Powered by FUDForum. Page generated in 0.03493 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software