[ATL] Support for reflection in ATL [message #89840] |
Wed, 03 September 2008 13:12  |
Eclipse User |
|
|
|
Originally posted by: jmcq.cs.nuim.ie
My question is concerned with reflection in ATL.
What I am trying to do is write a transformation where the source model
is at level M1 of the metamodelling hierarchy (e.g. a class diagram) and
the target metamodel is at the M2 layer of the hierarchy (e.g. the UML2
metamodel).
This is probably best illustrated with an example. Below is a sample
source model representing a class diagram as instance of the UML2
metamodel.
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1"
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
xmi:id="_qb8akM37EdqwVrslYOdUDA">
<uml:packagedElement xmi:type="uml:Package"
xmi:id="_w8IxIM37EdqwVrslYOdUDA"
name="MyClassDiagram">
<uml:packagedElement xmi:type="uml:Class"
xmi:id="_0D1RwDxREd2ulOnZDatzVA"
name="Class1">
<ownedAttribute xmi:id="_67-1UDxREd2ulOnZDatzVA"
name="Property1"/>
</uml:packagedElement>
<uml:packagedElement xmi:type="uml:Enumeration"
xmi:id="_2bXJ0DxREd2ulOnZDatzVA"
name="Enumeration1"/>
</uml:packagedElement>
</uml:Model>
I would like to write a transformation that results in the following
target model which is a simplified partial representation of the UML2
metamodel as an instance of the Ecore metamodel and would look something
like this
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
name="uml"
nsURI="uml"
nsPrefix="uml">
<eClassifiers xsi:type="ecore:EClass" name="Package">
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Class">
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Property">
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Enumeration">
</eClassifiers>
</ecore:EPackage>
The idea is that any classes that exist in the source model are mapped
to the Class element of the UML2 metamodel and similarly any attributes
in the class diagram map to the Property element of the UML2 metamodel
and so on.
Having thought about how to this I could write the transformation so
that I enumerate out all elements in the source metamodel(Package,
Class, Property etc) and explicitly define what they map to in the
target metamodel (all to the element ecore:EClass but with a different
value for the attribute 'name' depending on the type of the source
element - so the name would be 'Package', 'Class', 'Property'
respectively). To achieve this I would need to use some kind of
reflection to query the type of the elements in the source model and get
this type as a string and create an EClass in the target model and set
its name accordingly. This is similar to the reflection capabilities
available in Java such as Object.getClass() and Class.getName(). There
may be a more simpler or generic way to achieve this but I haven't
thought of one yet.
Does anyone know if there is support for this kind of reflection in ATL?
Thanks in advance,
Jacqui
|
|
|
Re: [ATL] Support for reflection in ATL [message #89927 is a reply to message #89840] |
Thu, 04 September 2008 11:31  |
Eclipse User |
|
|
|
Hi Jacqui,
You are trying to "promote" a UML model to Ecore.
Look a thread earlier about: [ATL]How to get the element type by the
element's attribute?
Regrads,
Alfons
"Jacqui" <jmcq@cs.nuim.ie> schreef in bericht
news:g9mgho$qbs$1@build.eclipse.org...
> My question is concerned with reflection in ATL.
>
> What I am trying to do is write a transformation where the source model is
> at level M1 of the metamodelling hierarchy (e.g. a class diagram) and the
> target metamodel is at the M2 layer of the hierarchy (e.g. the UML2
> metamodel).
>
> This is probably best illustrated with an example. Below is a sample
> source model representing a class diagram as instance of the UML2
> metamodel.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:uml="http://www.eclipse.org/uml2/2.0.0/UML"
> xmi:id="_qb8akM37EdqwVrslYOdUDA">
> <uml:packagedElement xmi:type="uml:Package"
> xmi:id="_w8IxIM37EdqwVrslYOdUDA"
> name="MyClassDiagram">
> <uml:packagedElement xmi:type="uml:Class"
> xmi:id="_0D1RwDxREd2ulOnZDatzVA"
> name="Class1">
> <ownedAttribute xmi:id="_67-1UDxREd2ulOnZDatzVA" name="Property1"/>
> </uml:packagedElement>
> <uml:packagedElement xmi:type="uml:Enumeration"
> xmi:id="_2bXJ0DxREd2ulOnZDatzVA" name="Enumeration1"/>
> </uml:packagedElement>
> </uml:Model>
>
> I would like to write a transformation that results in the following
> target model which is a simplified partial representation of the UML2
> metamodel as an instance of the Ecore metamodel and would look something
> like this
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> name="uml"
> nsURI="uml"
> nsPrefix="uml">
> <eClassifiers xsi:type="ecore:EClass" name="Package">
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Class">
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Property">
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Enumeration">
> </eClassifiers>
> </ecore:EPackage>
>
> The idea is that any classes that exist in the source model are mapped to
> the Class element of the UML2 metamodel and similarly any attributes in
> the class diagram map to the Property element of the UML2 metamodel and so
> on.
>
> Having thought about how to this I could write the transformation so that
> I enumerate out all elements in the source metamodel(Package, Class,
> Property etc) and explicitly define what they map to in the target
> metamodel (all to the element ecore:EClass but with a different value for
> the attribute 'name' depending on the type of the source element - so the
> name would be 'Package', 'Class', 'Property' respectively). To achieve
> this I would need to use some kind of reflection to query the type of the
> elements in the source model and get this type as a string and create an
> EClass in the target model and set its name accordingly. This is similar
> to the reflection capabilities available in Java such as Object.getClass()
> and Class.getName(). There may be a more simpler or generic way to achieve
> this but I haven't thought of one yet.
>
> Does anyone know if there is support for this kind of reflection in ATL?
>
> Thanks in advance,
>
> Jacqui
|
|
|
Powered by
FUDForum. Page generated in 0.03256 seconds