Transforming into target structure [message #1860839] |
Tue, 05 September 2023 17:33 |
Thomas Chiang Messages: 101 Registered: March 2020 |
Senior Member |
|
|
Hello,
I am new to ETL and am currently trying to build a transformation between two languages that I have built. I want to be able to complete a transformation into an already created file with only the model root object existing. And I want all of the transformed object to be under the model root in the target file. How do I build that? I think I'm essentially looking for a way to state as part of the transformation:
target.setContainer = target.ModelRoot
By extension I may also want to preserve some of the object structure from the source in the target file as well. Haven't tackled that yet but figured they might be similar enough to have similar solutions.
Thanks,
Thomas
[Updated on: Tue, 05 September 2023 17:44] Report message to a moderator
|
|
|
|
Re: Transforming into target structure [message #1860841 is a reply to message #1860840] |
Tue, 05 September 2023 21:06 |
|
How did you build your languages and/or how are your models persisted? I will assume your models are instances of an Ecore metamodel, i.e. Ecore models. In that case, all the properties of the model elements are accessible via dot notation. For example, if you have two classes in your language:
class A {
attr String name;
val B[*] children;
}
class B {
attr String name;
attr int age;
}
Then in ETL (or any other Epsilon language) you can use dot notation to access the model element properties:
a.name = "Martin"; // a is an instance of A
b.name = "Juan"; // b is an instance of B
b.age = 13;
a.children.add(b);
Now for the root containment part, in ETL all elements created as part of the "to" statement of the rule are added to the root of output model. So for example:
rule AllBs
transform b:In!B // Input model is 'In'
to x:Out!X { // Output model is 'Out'
x.name = a.name;
}
For each instance of B in the input model, a new X will be created in the output model. All the x's will be in the root. If you want a root element to containment, your output models metamodel (language) must have a class that contains x's.
class Root {
val X[*] under;
}
Then you can do:
rule Root
transform a:In!A
to r:Out!Root {
r.name = a.name;
r.under.addAll(a.children.equivalents());
}
Several notes here:
- It assumes the input model has a single 'a' element
- We use the 'equivalents' operation so that all x's created from b's are added to the root,
Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
|
|
|
Powered by
FUDForum. Page generated in 0.04274 seconds