|
|
|
|
Re: Running template just once for an Ecore model [message #1780467 is a reply to message #1780356] |
Mon, 22 January 2018 22:04 |
Gonzalo Sintas Messages: 3 Registered: January 2018 |
Junior Member |
|
|
I will show you everything I have, maybe I'm misunderstanding something.
This is my Ecore Metamodel:
package model : model = 'http://www.example.org/model'
{
class Entity
{
attribute id : ecore::EInt[1];
property animals: Animal[*|1] { ordered composes };
}
class Animal
{
attribute id : ecore::EInt[1];
attribute legs : ecore::EInt[1];
}
class Mammal extends Animal
{
attribute name : String[?];
}
class Dog extends Mammal
{
attribute breed : String[?];
attribute age : ecore::EInt[1];
}
}
Based on this metamodel, I've built a simple model
<model:Entity
id="100">
<animals
xsi:type="model:Dog"
legs="4"
id="1"
name="Keoni"
breed="Labrador"
age="12"/>
<animales
xsi:type="model:Dog"
legs="4"
id="2"
name="Hasso"
breed="Golden Retriever"
age="2">
</animales>
</model:Entidades>
I'm working on a project that transforms these types of Models and Metamodels into a Haskell representation. The whole representation is in a single file.
When processing the Model, I need to come out with an output similar to this one:
example = Model [
(ModelElement 0 (AnimalCh (Animal 4 1 (MammalCh (Mammal "Keoni" (DogCh (Dog "Labrador" 12)))))))
, (ModelElement 1 (AnimalCh (Animal 4 2 (MammalCh (Mammal "Hasso" (DogCh (Dog "Golden Retriever" 2)))))))
, (ModelElement 2 (EntityCh (Entity 100 [0, 1])))
]
That represents the way the model is defined in the Haskell representation I have.
So, I have the code that generates the representation for the three elements in the Model. I can get that just by iterating in the different EObjects in the Model, what I need is to write the "example = Model [" at the beginign and the "]" at the end (there is a little more text before and after, but I think the example is good enough to describe the problem).
[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/emf/2002/Ecore', 'http://www.example.org/model')]
[template public generateHeader(model : EPackage)]
[comment @main /]
[file ('TEST1.txt', true)]
example = Model ['['/]
[/file]
[/template]
[template public generate(aObject : EObject) post (trim())]
[comment @main /]
[file ('TEST1.txt', true)]
(ModelElement ([for (parent : EClass | aObject.eClass().getParents())] .... [/for]
[/file]
[/template]
[template public generateFooter(model : EPackage)]
[comment @main /]
[file ('TEST1.txt', true)]
[']'/]
[/file]
[/template]
Above is the Acceleo transformation I have. As I said before, the part where the elements (EObjects) are processed works fine, what I can't manage to achieve is running the Headers and Footers, so that I can get the output shown before. I belive there should be a way to do this using an acceleo transformation, but I'm clearly missing something. I'm open to other suggestions as to how to do this. I know I can "trick" the tranformation using a Java Wrapper, but I would like to avoid that if possible.
I hope the situation is clear now, and thanks a lot for your help Ed.
Regards,-
|
|
|
|
Powered by
FUDForum. Page generated in 0.02755 seconds